Passkey basics · Implementation
Discoverable credentials and residentKey: passkey sign-in without a username
5 min read
Key points
- A discoverable credential is one the authenticator can find without being given a credential ID, which is what makes username-less sign-in and autofill work.
- residentKey required guarantees a discoverable credential; preferred may still produce a non-discoverable one.
- For username-less sign-in, look up the user by the returned user handle and confirm the credential ID belongs to that user.
A discoverable credential is a passkey the authenticator can locate on its own for a given site, without the service passing a credential ID. That is what lets users sign in with a single "Sign in with a passkey" button or through autofill, without typing a username. Setting residentKey to required at registration guarantees a discoverable credential; preferred usually gets one but does not guarantee it. If you rely on username-less sign-in, use required, and make the user handle a random value that does not identify the person.
Two kinds of credentials
W3C WebAuthn Level 3 splits credentials by how they are stored:
- Discoverable credential (client-side discoverable credential): usable in an authentication ceremony where the relying party provides no credential IDs. The authenticator remembers credentials per RP ID (the site's domain) and finds them itself. These were formerly called resident credentials or resident keys.
- Server-side credential (non-discoverable credential): the authenticator needs both the RP ID and the credential ID to use it. The spec allows the credential ID itself to be the credential source encrypted so only that authenticator can decrypt it, which lets the authenticator be nearly stateless.
With server-side credentials, your service needs to know whose credential to ask for before the ceremony. So the user types a username first, and you pass that user's credential IDs in allowCredentials. With discoverable credentials, you call with an empty allowCredentials and the browser or OS shows the passkeys saved for your site. As Google's web.dev deep dive explains, each entry is labeled with the user.name set at registration.
WebAuthn Level 3 describes passkey authenticators as supporting discoverable credentials, "also called passkeys," which enable flows where username input is not necessary.
The three residentKey values
At registration, authenticatorSelection.residentKey says which kind you want:
| Value | Spec definition (summarized) |
|---|---|
required |
A discoverable credential is required. If one cannot be created, the browser returns an error |
preferred |
The RP strongly prefers a discoverable credential but will accept a server-side one |
discouraged |
The RP prefers a server-side credential but will accept a discoverable one |
The older boolean requireResidentKey is kept for compatibility with WebAuthn Level 1. The spec says to set it to true if, and only if, residentKey is required.
With preferred and discouraged, you cannot tell from the outside which kind was created. The spec points to the Credential Properties extension (credProps): an rk value of true means the credential is discoverable. The spec also notes that this value may not be returned.
Which value to choose
- Sign-in is only username-less or autofill →
required. A user who ends up with a non-discoverable credential will not see it in the account list and cannot sign in. - You keep a "username first" flow →
preferredworks. Users with non-discoverable credentials type their username and sign in withallowCredentials. discouragedis for when you prefer server-side credentials. If you want username-less sign-in or autofill, there is little reason to choose it.
For autofill (conditional mediation), the browser clears allowCredentials before processing the request. The spec says this "prevents non-discoverable credentials from being used during conditional requests," so non-discoverable credentials never appear as suggestions. If autofill is your main entry point, use required.
Choosing the user handle (user.id)
A discoverable credential is stored together with the user.id (user handle) you passed at registration. In a username-less sign-in, that value comes back in the response's userHandle, and you use it to find the account. The spec requires the user handle to always be returned for discoverable credentials.
Rules for the user handle:
- No personal information. The spec says the user handle must not contain personally identifying information such as email addresses or usernames, because authenticators may reveal user handles without user verification. Hashes of such values are also out, since guessable inputs can be probed, unless you salt them with a secret only you hold.
- Make it random. The spec recommends 64 random bytes stored with the account.
- Keep it stable per account. Authenticators store credentials keyed by the pair of RP ID and user handle. A different user handle for the same person looks like a different account; the same one means re-registering on the same authenticator replaces the earlier credential.
user.name and user.displayName, on the other hand, are what users see in the account picker. Use something they recognize, such as their email address or nickname.
What the server checks for username-less sign-in
The spec's assertion verification steps branch on whether you knew the user before the ceremony:
- User identified beforehand (username, cookie, etc.): confirm that account has a credential whose ID matches the response. If
userHandleis present, confirm it matches that account's user handle. - User not identified (username-less): confirm
userHandleis present, then confirm the account it points to has a credential whose ID matches the response.
If you skip step 2 and pick the account from only the credential ID or only the user handle, you leave room for mixing up one user's credential with another's. Check both before issuing a session.
Implementing this with SealGate
In SealGate, residentKey is the per-app (per-environment) setting resident_key: required, preferred or discouraged, with preferred as the default. If you run username-less sign-in or autofill only, set it to required in the environment settings in the dashboard or with PATCH /v1/apps/{app_id}.
For sign-in, calling POST /v1/login/options without external_id lets the user pick from passkeys saved on the device. POST /v1/login/verify checks the credential against the user, and your server issues a session for the returned external_id. In the browser SDK, that is sg.login() with no arguments, or sg.login({}, { mediation: 'conditional' }) for autofill.
For external_id in POST /v1/register/options, use an internal number or random ID rather than an email address. display_name is the name shown in the authenticator dialog, so pick something users recognize. See Registration and Login in the docs.
FAQ
Are all passkeys discoverable credentials?
WebAuthn Level 3 says discoverable credentials are "also called passkeys." But if you register with preferred or discouraged, some authenticators may create a non-discoverable credential.
Can I remove the username field?
Yes, if residentKey is required and you no longer need other entry points such as passwords. While users with non-discoverable credentials remain, keep a way to sign in by entering a username.
Sources
Related posts
Implementation
Passkey autofill with conditional UI: show passkeys in the username field
How conditional UI (conditional mediation) puts passkeys in the username field's autofill suggestions, and how to implement it, covering the autocomplete token, feature detection, challenges, aborting, and common pitfalls.
Passkey basics · Implementation
The WebAuthn registration flow: what to check in challenge, options, and verify
A walkthrough of passkey registration (the WebAuthn registration ceremony), covering the options your server builds, navigator.credentials.create(), server-side verification, and what to store, following W3C WebAuthn Level 3.
Implementation
Choosing userVerification: required vs. preferred and the UV flag
WebAuthn userVerification asks the authenticator to verify the user with a biometric or PIN. How required and preferred differ, how to read the UV flag, and which to choose.