Skip to content

Use one passkey on related sites

For: an app developer with one service on several domains, such as example.com and example.net.

What it does: with passkey.relatedOrigins: true, auth.wellKnown serves GET /.well-known/webauthn on the rpID host. A browser reads it, and lets a passkey of example.com sign in on example.net.

  1. Set passkey.relatedOrigins to true.
  2. Add each related origin to passkey.origins and to trustedOrigins.
  3. Mount auth.wellKnown at the origin root of the rpID host, for each path that starts with /.well-known/.
  4. On the related site, run the ceremonies with the same rpID.
Two related sites in the config
import { createAuth, type MailPort, type StorageAdapter } from "@authtempo/core";
/** One passkey for example.com, its app host, and two related sites. */
export function createRelatedOriginsAuth(deps: {
storage: StorageAdapter;
mail: MailPort;
secret: string;
}) {
const origins = [
"https://app.example.com",
// Outside the domain tree of rpID: the document lists these two.
"https://example.net",
"https://example.org",
];
return createAuth({
baseURL: "https://api.example.com",
appURL: "https://app.example.com",
// Each passkey origin must be a trusted origin, or the router refuses its posts.
trustedOrigins: origins,
secret: deps.secret,
storage: deps.storage,
mail: deps.mail,
passkey: {
rpID: "example.com",
rpName: "Example",
origins,
// At most five origins outside example.com. auth.wellKnown serves the document.
relatedOrigins: true,
},
});
}
The document as a test
import { describe, expect, it } from "vitest";
import { harness } from "../support/harness.ts";
import { createRelatedOriginsAuth } from "./related-origins.ts";
describe("passkey related origins", () => {
it("lists the origins outside the RP ID on the RP ID host", async () => {
const auth = createRelatedOriginsAuth(harness());
// Mount auth.wellKnown at the origin root of example.com.
const res = await auth.wellKnown(new Request("https://example.com/.well-known/webauthn"));
expect(res.status).toBe(200);
expect(res.headers.get("content-type")).toContain("application/json");
expect(await res.json()).toEqual({ origins: ["https://example.net", "https://example.org"] });
});
it("answers 404 on any other host", async () => {
const auth = createRelatedOriginsAuth(harness());
const res = await auth.wellKnown(new Request("https://api.example.com/.well-known/webauthn"));
expect(res.status).toBe(404);
});
});
  • The document is { "origins": [...] }, with content-type: application/json and cache-control: public, max-age=300.
  • It lists only the origins outside the domain tree of rpID, in config order. An origin on the tree needs no document.
  • Only a request to the rpID host gets it. Any other host answers 404.
  • WebAuthn Level 3 says a browser must accept at least five labels, such as example of example.net. So createAuth refuses more than five origins outside the tree.
  • Core has no public suffix list, so it counts each origin outside the tree as one label. Two origins of one label count twice. So core can refuse a config that a browser accepts.
  • Each ceremony still checks the origin of the browser against passkey.origins. An origin outside the list never passes.
  • passkey.hints.register and passkey.hints.signIn give the browser a preference: security-key, client-device, or hybrid. A hints field of an options body replaces the list for that ceremony.
  • A sign-in by a credential that the site does not store answers passkey_unknown. Call PublicKeyCredential.signalUnknownCredential with it, so the device removes the passkey. The client’s passkey.signIn makes that call for you where the browser has it.
  • GET /passkeys answers rpId and userHandle. Pass them with the credential ids to PublicKeyCredential.signalAllAcceptedCredentials. The client’s passkeys.sync() does this.
  • GET /passkeys also answers userName and userDisplayName, the names of a new registration. Pass them to PublicKeyCredential.signalCurrentUserDetails after a change of name. The client’s passkeys.signalDetails() does this.
  • passkey_unknown tells the holder of a credential that the site stores no row for it. Only that holder can see the answer: the credential id is random, and the person’s own device gives it.
  • A browser that does not read the document refuses the passkey on the related site. The person then signs in by another method there.
  • passkey_failed: the origin of the browser is not in passkey.origins, or the signature is bad.
  • passkey_unknown: the site stores no passkey with this credential id.
  • not_found: the document was asked on a host that is not the rpID host.
  • invalid_body: an options body named a hint that is not known, or a hint twice.