Passwords have been the standard method of authenticating users in web applications for many years. However, password-based authentication creates several challenges. Users must remember passwords, applications need to store password hashes securely, and weak or reused passwords can expose accounts to security risks.
Passkeys provide a passwordless authentication approach based on public-key cryptography. They allow users to authenticate using a device's built-in security features, such as fingerprint recognition, facial recognition, a device PIN, or a security key.
The Web Authentication API, commonly called WebAuthn, provides the browser interface for implementing passkey authentication.
One particularly useful WebAuthn feature is Conditional UI. It allows websites to offer passkeys through the browser's existing autofill experience instead of immediately displaying a separate authentication dialog.
This makes passkey authentication easier to introduce into applications that already support username and password login.
This article explains how WebAuthn Conditional UI works, how to implement it in a web application, how to communicate with the authentication server, and what developers should consider before deploying passkeys in production.
What Are Passkeys?
A passkey is a credential based on public-key cryptography. It consists of a public key and a corresponding private key.
During registration, the authenticator creates a credential and provides the public key to the application. The private key remains protected by the authenticator and is not shared with the website.
When the user signs in, the application sends a cryptographic challenge to the browser. The authenticator uses the private key to sign the challenge and returns the authentication response.
The server verifies the response using the stored public key.
This approach provides several security benefits:
The application does not need to store user passwords.
The private key is not transmitted to the server.
Authentication responses are tied to a specific challenge.
WebAuthn credentials are associated with a relying party, helping protect against phishing on unrelated domains.
Users can authenticate using familiar device-level verification methods.
Passkeys can also be synchronized across supported devices through credential manager ecosystems, depending on the platform and user settings.
Understanding WebAuthn Conditional UI
Traditional WebAuthn authentication usually displays a browser or operating system dialog when the application requests a credential.
Although this approach works, it can interrupt the normal login experience. Users who do not have a passkey may see an authentication prompt that does not help them.
Conditional UI solves this problem by integrating passkey selection into the browser's autofill experience.
For example, consider a login page containing a username and password field. When Conditional UI is enabled, the browser can display available passkeys when the user interacts with the username field.
The user can select a passkey from the autofill suggestions and authenticate without manually entering a password.
If the user does not have a suitable passkey, the traditional username and password login flow can continue.
The important difference is that Conditional UI does not immediately display a modal authentication dialog. Instead, the WebAuthn request remains pending until the user selects an available credential.
This makes it suitable for applications that want to support both password-based and passkey-based authentication.
Understanding the WebAuthn Authentication Flow
A typical Conditional UI authentication flow involves the browser, the application server, and the user's authenticator.
The process works as follows:
The user opens the application's login page.
The browser checks whether Conditional UI is supported.
The application requests authentication options from the server.
The server generates a cryptographically secure challenge and returns the WebAuthn request options.
The browser starts a conditional WebAuthn request.
The user focuses on the username field and selects an available passkey from autofill suggestions.
The authenticator verifies the user and signs the challenge.
The browser returns the authentication credential to the application.
The application sends the credential response to the server.
The server verifies the signature, challenge, origin, relying party ID, and stored credential information.
The server creates an authenticated session.
The server must perform the final verification. A successful browser operation alone does not mean that the user has been authenticated.
Preparing the Login Form
The first step is to prepare the login form so that the browser can display passkeys through autofill.
The username field must include the webauthn autocomplete token.
For example:
<form id="loginForm">
<label for="username">Username</label>
<input
type="text"
id="username"
name="username"
autocomplete="username webauthn"
autofocus
/>
<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
autocomplete="current-password"
/>
<button type="submit">
Sign in
</button>
</form>
The important part is:
autocomplete="username webauthn"
The username token allows the browser to offer saved usernames, while the webauthn token enables compatible passkey suggestions for the pending conditional request.
The password field remains available for users who prefer traditional authentication.
This is useful during passkey adoption because an application does not need to remove its existing login form.
Checking Conditional UI Support
Not every browser or platform supports every WebAuthn feature.
Before starting a conditional request, check whether the browser supports the required capability.
Modern browsers provide the getClientCapabilities() method on PublicKeyCredential.
async function supportsConditionalUI() {
if (!window.PublicKeyCredential) {
return false;
}
try {
const capabilities =
await PublicKeyCredential.getClientCapabilities();
return capabilities.conditionalGet === true;
} catch (error) {
console.error(
"Unable to check WebAuthn capabilities",
error
);
return false;
}
}
The conditionalGet capability indicates whether the browser supports conditional WebAuthn credential retrieval.
For environments that use an older browser API, applications may encounter examples using isConditionalMediationAvailable(). That older feature-detection method is still found in existing implementations, but new implementations should follow the current browser documentation and capability detection approach.
If Conditional UI is unavailable, the application should continue offering its normal authentication methods.
Starting a Conditional WebAuthn Request
After checking browser support, the application needs to request authentication options from its backend.
The server should generate a fresh random challenge for every authentication ceremony. It should also provide the relying party ID and other required WebAuthn options.
The following example demonstrates the browser-side flow:
let conditionalAbortController;
async function startConditionalAuthentication() {
if (!(await supportsConditionalUI())) {
return;
}
conditionalAbortController =
new AbortController();
try {
const response = await fetch(
"/api/passkeys/login-options",
{
method: "POST",
credentials: "same-origin"
}
);
if (!response.ok) {
throw new Error(
"Unable to retrieve login options"
);
}
const optionsJSON = await response.json();
const publicKey =
PublicKeyCredential
.parseRequestOptionsFromJSON(optionsJSON);
const credential =
await navigator.credentials.get({
publicKey,
mediation: "conditional",
signal: conditionalAbortController.signal
});
if (!credential) {
return;
}
await verifyPasskey(credential);
} catch (error) {
if (error.name !== "AbortError") {
console.error(
"Passkey authentication failed",
error
);
}
}
}
There are several important details in this implementation.
First, the application requests authentication options from the backend rather than generating the challenge in the browser.
Second, parseRequestOptionsFromJSON() converts the server's JSON representation into the format expected by the WebAuthn API. This is important because binary values such as the challenge and credential IDs need to be represented correctly in JSON.
Third, the request uses mediation: "conditional". This tells the browser to integrate the authentication request with its autofill experience.
The request can remain pending until the user selects a passkey. Therefore, the application should not treat a pending promise as an authentication failure.
Sending the Authentication Response to the Server
When the user selects a passkey, the browser returns a PublicKeyCredential.
The application must serialize the response and send it to the backend for verification.
Modern browsers provide the toJSON() method for converting a public-key credential into a JSON-compatible representation.
async function verifyPasskey(credential) {
const response = await fetch(
"/api/passkeys/verify",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
credentials: "same-origin",
body: JSON.stringify(
credential.toJSON()
)
}
);
if (!response.ok) {
throw new Error(
"Passkey verification failed"
);
}
const result = await response.json();
if (result.authenticated) {
window.location.href = "/dashboard";
}
}
The server must validate the credential response using a trusted WebAuthn implementation.
It should not accept a client-provided authenticated flag as proof of successful authentication. The browser is not responsible for deciding whether the user's session should be trusted.
Implementing Server-Side Verification
The backend is responsible for generating challenges, storing registered credentials, and validating authentication responses.
During passkey registration, the server should store the following information:
Credential ID.
Public key.
User account identifier.
Relying party information.
Signature counter, when applicable.
Supported authenticator metadata and backup-related information when available.
During authentication, the server must verify the response against the registered credential.
Important checks include:
Challenge Validation
The returned challenge must match the challenge generated for the current authentication ceremony.
Challenges should be unpredictable, associated with the relevant session or authentication transaction, and accepted only once.
Origin Validation
The server must verify that the response originated from an allowed application origin.
For example, an application hosted at https://example.com should not accept an authentication response from an unrelated website.
Relying Party ID Validation
The relying party ID must match the application's configured WebAuthn relying party.
This helps prevent credentials created for another website from being accepted.
Signature Verification
The server must verify the cryptographic signature using the public key stored during registration.
User Verification
If the application requires user verification, the server must check that the authenticator response satisfies that requirement.
User verification can involve a fingerprint, facial recognition, device PIN, or another supported authenticator mechanism.
Credential Ownership
The credential must belong to the account being authenticated. The server should also verify that the credential is active and has not been revoked.
Use a maintained WebAuthn server library rather than implementing signature verification and authenticator data parsing manually.
Handling Traditional Password Login Alongside Passkeys
One of the main advantages of Conditional UI is that it supports gradual passkey adoption.
An application can continue to provide username and password authentication while offering passkeys through the same login experience.
For example, the login process can follow this approach:
Start the conditional WebAuthn request when the login page loads.
Allow the user to select a passkey through browser autofill.
Keep the password login form available.
If the user submits the password form, authenticate through the existing backend flow.
If the user selects a passkey, verify the WebAuthn response.
Create the same type of secure application session after either authentication method succeeds.
This approach avoids forcing every user to migrate to passkeys immediately.
It also allows organizations to introduce passwordless authentication gradually while maintaining compatibility with existing accounts and workflows.
Managing Cancellation and Multiple Authentication Requests
Conditional WebAuthn requests can remain pending for an extended period because the browser waits for user interaction.
Applications should manage these requests carefully.
For example, a user may navigate to another authentication method or leave the login page. In these situations, the application should abort the pending WebAuthn request.
function cancelConditionalAuthentication() {
if (conditionalAbortController) {
conditionalAbortController.abort();
conditionalAbortController = null;
}
}
An AbortController allows the application to cancel a pending credential request.
This is especially important when implementing an explicit Sign in with passkey button. Before starting a separate modal WebAuthn request, abort the existing conditional request to avoid competing authentication operations.
Applications should also handle AbortError separately from genuine authentication failures. Cancellation is a normal part of the user experience and should not automatically display an error message.
Security Considerations for Production
Passkeys improve authentication security, but production implementations still require careful security controls.
Use HTTPS
WebAuthn requires a secure context. Production applications should use HTTPS and configure their relying party ID and allowed origins correctly.
Local development environments have special secure-context treatment, but production systems should never rely on insecure HTTP.
Generate Challenges on the Server
Never generate authentication challenges using predictable values or fixed strings.
Use a cryptographically secure random number generator and associate each challenge with its authentication transaction.
Make Challenges Single-Use
A challenge should be accepted only once and should expire after a reasonable period.
This helps prevent replay attacks.
Protect Authentication Sessions
After successful verification, create a secure application session using appropriate cookie settings.
For example, session cookies should generally use Secure, HttpOnly, and an appropriate SameSite policy.
Regenerate the session identifier after authentication to reduce session fixation risks.
Support Credential Revocation
Users should be able to view and remove registered passkeys from their accounts.
The backend must reject credentials that have been revoked or are no longer associated with the account.
Provide Account Recovery
Passkeys do not remove the need for account recovery.
Users may lose access to a device or credential manager. Applications should provide a secure recovery process that does not become an easy way for attackers to bypass passkey protection.
Common Mistakes to Avoid
Starting Conditional UI Without Feature Detection
Calling Conditional UI without checking browser support can produce inconsistent behavior.
Check the conditionalGet capability and retain a normal login option.
Forgetting the WebAuthn Autocomplete Token
The conditional request alone is not enough to provide the expected autofill experience.
The username field should include autocomplete="username webauthn".
Generating the Challenge in the Browser
The challenge must be generated by the trusted server using a cryptographically secure random source.
The browser should receive the challenge through the authentication options endpoint.
Trusting Client-Side Verification
A successful browser credential response does not prove that authentication is complete.
Always verify the response on the server before creating an authenticated session.
Ignoring Pending Requests
Conditional requests can remain pending until a user selects a credential.
Manage their lifecycle with AbortController and cancel them when switching authentication flows.
Supporting Only Passkey Authentication
Users may not have a registered passkey or may be using a browser that does not support Conditional UI.
Provide an alternative authentication method and a secure account recovery process.
Testing WebAuthn Conditional UI
Testing should cover more than successful passkey authentication.
Important scenarios include:
A user with a registered passkey selects it from autofill.
A user without a passkey signs in with a password.
The browser does not support conditionalGet.
The user cancels the authentication request.
The server receives an expired or reused challenge.
The authentication response contains an invalid signature.
The credential belongs to a different relying party.
The user revokes a registered passkey.
The application switches from conditional authentication to an explicit passkey button.
Test across supported browsers, operating systems, and authenticator types. Passkey availability and autofill behavior can vary depending on the browser and platform.
Also test the complete registration, authentication, session creation, and account recovery processes before enabling passkeys for production users.
Conclusion
WebAuthn Conditional UI provides a practical way to introduce passkey authentication into existing web applications. Instead of displaying a separate authentication dialog immediately, it integrates available passkeys into the browser's autofill experience.
This makes authentication more convenient for users while allowing applications to retain traditional username and password login options.
A production implementation requires proper browser capability detection, server-generated challenges, secure credential storage, strict response verification, and reliable session management.
When these components are implemented correctly, Conditional UI can help organizations adopt passkeys gradually and provide a simpler, phishing-resistant authentication experience.
Join the conversation! Your thoughts help the community grow.