WebAuthn Passkeys: Registration, Authentication, and Server-Side Verification
Build phishing-resistant sign-in flows around challenges and public-key credentials without treating browser data as proof.
WebAuthn lets a relying party create and use public-key credentials through a browser and authenticator. The private key stays with the authenticator; the server stores a public key and verifies signed authentication data for a fresh challenge.
THE PRODUCTION PROBLEM STATEMENT
Adding a browser credential call is only one part of authentication. If a server accepts client-supplied fields without validating the challenge, origin, relying-party ID, and signature, the flow does not establish the intended identity.
Have the server create a one-time challenge
The server prepares public-key creation options with a fresh unpredictable challenge, the relying-party ID, and the account context. The browser passes those options to navigator.credentials.create, then returns a credential response for server verification.
Associate the challenge with the session and expire it after use. Do not accept an authentication response for another account or another relying party just because the browser returned a credential-shaped object.
const options = await fetch('/webauthn/register/options', {
method: 'POST',
credentials: 'same-origin'
}).then((response) => response.json());
const credential = await navigator.credentials.create({ publicKey: options });
await fetch('/webauthn/register/verify', {
method: 'POST',
credentials: 'same-origin',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(serializeCredential(credential))
});Verify the complete assertion on the server
During authentication, the server checks that the challenge is fresh and matches, the origin is expected, the relying-party ID hash matches, the user-presence and verification requirements are satisfied, and the signature verifies with the registered public key.
Return a generic authentication failure to the client while recording useful security events server-side. Client JavaScript is not a trusted verifier and must not decide that a signature is valid.
Design account recovery and credential lifecycle
Users can lose devices or remove credentials. Let them register more than one authenticator where possible, provide a secure recovery path, and allow credential revocation from account settings.
Passkeys reduce dependence on shared secrets, but account recovery and session security remain part of the system. Use secure transport, protect session cookies, and review the relying-party origin configuration before launch.
Frequently Asked Questions & Technical Inquiries
Direct, practical answers to common architectural and debugging questions.
The authenticator performs user verification locally. The server receives a credential assertion and cryptographic evidence, not a biometric template.
Faisal Askari
Verified AuthorSoftware Engineer & Full-Stack Developer
Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.
Resilient Full-Stack Architecture: Idempotent APIs, Optimistic UI, and Cache Invalidation
Engineering robust distributed state between client and server: idempotency keys, safe optimistic rollbacks, exponential backoff with jitter, and cache coherence.
Server-Sent Events (SSE) vs WebSockets over HTTP/2: Choosing the Right Real-Time Streaming Architecture
Why HTTP/2 multiplexing made Server-Sent Events the modern standard for LLM token streams and live telemetry over complex WebSockets.