Skip to content

Sign up with a passkey

For: an app developer who wants a person to make an account with a passkey only.

What it does: passkey.signUp adds POST /passkey/sign-up/options and POST /passkey/sign-up/verify. The verify makes the user, the passkey, and the session. The user has no address.

  • Passkey sign-in, as in Sign in with a passkey.
  • A limiter that counts for the whole deployment: the D1, Postgres, or MySQL limiter. Limits names each one.
  • signUp: "open", the default of Top level.
  1. Set passkey.signUp to true, or to an object with dailyCap.
  2. Pass the limiter of your adapter as limiter.
  3. Ask the person for a name. Post { name } to POST /passkey/sign-up/options.
  4. Give the answer to navigator.credentials.create.
  5. Post { response } to POST /passkey/sign-up/verify. A browser gets the session cookie.
  6. In a browser app, call client.passkey.signUp of the client package in place of steps 3 to 5.
  7. On a public site, add the captcha flow passkey-sign-up to captcha.flows.
Passkey sign-up in the config
import { createAuth, type LimiterPort, type MailPort, type StorageAdapter } from "@authtempo/core";
/**
* Sign-up with a passkey and a name. The new user has no address. Pass the
* limiter of your D1, Postgres, or MySQL adapter: the daily cap counts per
* deployment. Only a test passes "isolate-for-tests", and its cap then
* counts per isolate.
*/
export function createPasskeySignUpAuth(deps: {
storage: StorageAdapter;
mail: MailPort;
secret: string;
limiter: LimiterPort | "isolate-for-tests";
}) {
const forTests = deps.limiter === "isolate-for-tests";
return createAuth({
baseURL: "https://api.example.com",
appURL: "https://app.example.com",
trustedOrigins: ["https://app.example.com"],
secret: deps.secret,
storage: deps.storage,
mail: deps.mail,
...(deps.limiter === "isolate-for-tests" ? {} : { limiter: deps.limiter }),
passkey: {
rpID: "example.com",
rpName: "Example",
origins: ["https://app.example.com"],
signUp: {
// The sign-ups of the whole deployment per 24 hours.
dailyCap: 1000,
// Tests only. With a limiter that counts per isolate, createAuth refuses this.
...(forTests ? { isolateLimiter: "allow" as const } : {}),
},
},
});
}
The sign-up as a test
import { createMemoryLimiter, systemClock } from "@authtempo/core";
import { SoftAuthenticator } from "@authtempo/core/testing";
import { describe, expect, it } from "vitest";
import { call, harness, sessionCookieOf } from "../support/harness.ts";
import { createPasskeySignUpAuth } from "./passkey-sign-up.ts";
/** The bytes of a base64url string. */
const bytesOf = (s: string) => Uint8Array.from(Buffer.from(s, "base64url"));
describe("sign up with a passkey", () => {
it("makes a user with a passkey, a name, and no address", async () => {
// A test passes the test value. An app passes the limiter of its adapter.
const auth = createPasskeySignUpAuth({ ...harness(), limiter: "isolate-for-tests" });
const res = await call(auth, "POST", "/auth/passkey/sign-up/options", { name: "Ada" });
expect(res.status).toBe(200);
const options = (await res.json()) as { challenge: string; user: { id: string; name: string } };
expect(options.user.name).toBe("Ada");
// In the browser: navigator.credentials.create. A test uses a software authenticator.
const device = await SoftAuthenticator.create({
rpID: "example.com",
origin: "https://app.example.com",
});
const response = await device.register(options.challenge, bytesOf(options.user.id));
const done = await call(auth, "POST", "/auth/passkey/sign-up/verify", { response });
expect(done.status).toBe(200);
const { user } = (await done.json()) as { user: { name: string; email: string | null } };
expect(user.email).toBeNull();
expect(user.name).toBe("Ada");
expect(sessionCookieOf(done)).not.toBe("");
});
it("refuses a memory limiter outside tests: the cap is per deployment", () => {
const limiter = createMemoryLimiter(systemClock);
expect(() => createPasskeySignUpAuth({ ...harness(), limiter })).toThrow(/shared limiter/);
});
it("refuses a call with no limiter, as from plain JavaScript", () => {
// The type needs a limiter. A call that skips the type check gets the refusal.
const deps = harness() as never;
expect(() => createPasskeySignUpAuth(deps)).toThrow(/shared limiter/);
});
});
  • The options make no user. Core mints the user id at the options and keeps it with the challenge. The verify makes the user.
  • The name has 1 to 80 characters, with no control, format, or bidi character. It is the name of the user, and the device shows it with the passkey. The stored passkey has no name until a rename.
  • A challenge makes one user. A second verify of the same challenge answers invalid_token.
  • The verify runs user.beforeCreate with via: "passkey", and the session hooks see via: "passkey".
  • No second factor gates the sign-up. A new user has no factor, and a passkey with user verification is two factors.
  • Only signUp: "open" lets the user in. "invited" and false answer sign_up_closed, because an invitation names an address.
  • A credential id that another user holds answers passkey_failed and makes nothing.
  • A live anonymous session of the browser is replaced, as at each sign-in. See Anonymous sessions.
  • The limit passkey-sign-up:ip allows 10 options per IP per hour. The cap passkey-sign-up:all-day allows dailyCap options per deployment per 24 hours, 1000 by default.
  • With the captcha flow on, the captcha runs after the per-IP limit and before the cap. A failed captcha does not count against the cap.
  • createAuth refuses passkey.signUp with a limiter that counts per isolate. For tests only, set passkey.signUp.isolateLimiter: "allow". The cap is then per isolate.
  • The user has a proved handle: its passkey. So it can register a second passkey, set a username, and add an address. See The account with no address.
  • A script with a software authenticator can make a user at each verify. The attestation is none, so core cannot tell a script from a device. The per-IP limit and the daily cap bound it.
  • A script that spends the cap stops real sign-ups until the window ends. Turn on the captcha flow on a public site.
  • The user has no address, so no mail can recover the account. Ask the person to register a second passkey or to add an address.