You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d8ce058
Browse filesBrowse the repository at this point in the historyBrowse files
feat(auth): apps sign users in with passkeys on their own pages (#163)
Closes#77
Apps on other domains must send users to auth.piquel.fr to sign in,
which confuses people who have never heard of piquel.fr. Passkeys only
worked on auth's own pages: the verifier accepted one origin, and every
ceremony was bound to a host-only cookie another site cannot send.
## How
WebAuthn Level 3 related origins (§5.11) let a page on
`https://app.example` run a ceremony for RP ID `auth.piquel.fr` once
`https://auth.piquel.fr/.well-known/webauthn` lists that origin.
Existing passkeys keep working.
- **Approved origins.** A new `client_webauthn_origins` table, managed
from the admin dashboard's Clients page or with `auth-service client
origin add|remove|list`. Both run the same `AdminService` operations and
`ClientRegistry` rules, and record
`RelatedOriginApproved`/`RelatedOriginRemoved`. Approval needs a trusted
client (this sign-in skips consent), an origin that is one of its
redirect origins, and at most 5 registrable-domain labels across all
approved origins (`psl` crate), as browsers count them. Deleting a
client removes its origins, by a trigger, so a replica on the previous
release (including #152's account purge) does too.
- **`GET /.well-known/webauthn`** lists them: discovery, public cache
for 5 minutes.
- **`POST /webauthn/related/start {request_uri}`** checks the page's
`Origin` is approved for an enabled, trusted client, then claims that
client's pushed request and stores the ceremony in one transaction,
bound to the origin and the claim instead of a cookie. `prompt=consent`
and `prompt=none` are refused with `interaction_required` and the
request stays usable for the redirect flow. An `id_token_hint` limits
the ceremony to that account's passkeys.
- **`POST /webauthn/related/finish`** requires the same origin, still
approved for the same client, and `clientDataJSON.origin` naming it. It
creates a session with no browser secret, consumes the request, and
answers `{code, state, iss}` as JSON. No cookie is set; the code needs
the PKCE verifier.
- **Security layer.** `Endpoint::RelatedLogin` gets its own
credential-free CORS grant (`content-type, x-piquel-csrf`, `POST`) for
approved origins, still requires the CSRF header, and uses the login
rate bucket. The public-client grant is unchanged.
- **History.** `SignedIn` gains an optional `inline: {client_id,
origin}`; settings history shows "Signed in with a passkey on
app.example".
### Since the first version of this PR
Main moved every UI into server-rendered pages and deleted the TS SDK,
so this is a port rather than a rebase:
- There is no client-side helper. `passkey.js` serves only auth's own
pages, and the related flow runs on the app's page, so README documents
the protocol, including when to fall back to `/oauth/authorize`. A
public SDK (#58, #59) can wrap it later; [#58 asks for
that](#58 (comment)).
- **Dashboard pages.** The dashboard now lives in auth, so its Clients
page lists each client's approved origins, with Remove links and an
"Approve an origin" form; untrusted and deleted clients show why they
cannot have one. Approving and removing are change forms needing the
dashboard's own confirmation, and a refused origin is explained beside
the form. Listing origins is part of `ListClients`, the operation that
page runs; `approve` and `remove` are their own. No admin JSON API.
- Sessions take a `Credential`; inline sign-in passes on the one the
assertion gave, #180's probation credential included. The code is issued
only if the new session meets the request's requirements, checked as the
redirect flow does, so a recovered passkey during its probation meets no
`acr_values=phr`. That gets `interaction_required`, and auth's pages
then answer the client `unmet_authentication_requirements`. Recovery
enrolment stays on auth's own `/recover` page: related origins only sign
in.
- **Account deletion (#152).** An account scheduled for deletion gets
`interaction_required` at finish rather than a session, since only
auth's sign-in page offers to restore it.
- Migration is `0023_related_origins`, right after #152's 0022. #163
merges before #159, which then takes 0024.
- CodeRabbit's findings are fixed: the README's domain-count rule, and
approved origins left behind by deleted clients.
## Tests
- `related_pages_sign_in_for_pkce_bound_codes` and
`related_sign_in_refuses_other_origins_requests_and_unverified_users`
(passkey, across two replicas),
`a_probation_passkey_meets_no_phr_on_related_pages`,
`an_account_being_deleted_signs_in_on_auths_pages_only`,
`origin_approval_needs_trust_a_redirect_origin_and_few_domains` (now
also deleting the client) and
`related_origins_count_registrable_domain_labels` (clients), plus the
CLI/admin operation coverage tests.
- `tests/browser/related-origins.spec.ts` signs in on a client page
served through DevTools. In CI auth is on `localhost`, so the page is
`https://localhost:4443`, where browsers need no list. On a piqueld
preview it passed from `https://related-e2e.test`, a separate site, so
Chromium read `/.well-known/webauthn` first; `oidc.spec.ts` and
`sign-in.spec.ts` passed there too.
- `related_origins_are_approved_and_removed_from_the_dashboard` drives
the dashboard pages.
- `just db test`: all 293 pass; `cargo clippy --all-targets
--all-features` is clean.
Reviewed with review-loop: 4 rounds with 3× GPT 6.1 Sol and Claude Opus
5.5 (Sol was over its usage limit in round 1; later rounds covered the
rebases onto #180 and the dashboard). Verdict: approved. A GPT 6.1 Sol
review of the rebase onto #152 found that older replicas left a deleted
client's origins behind, which the trigger fixes.
> [!NOTE]
> Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol
and Claude Opus 5.5 (via T3 Code)
0 commit comments