Overview
WebAuthn (Web Authentication) enables passwordless authentication using biometrics (fingerprint, Face ID) or hardware security keys (YubiKey, Titan). SuperTokens Core implements the WebAuthn standard for secure, phishing-resistant authentication. Standards: W3C Web Authentication API (WebAuthn Level 2) Implementation: Uses webauthn4j library for credential verificationCore Concepts
Relying Party (RP)
Your application acts as the relying party:- RP ID: Your domain (e.g., “example.com”)
- RP Name: Display name (e.g., “My App”)
- Origin: Full URL (e.g., “https://example.com”)
Credentials
Each user can have multiple credentials:- Biometric authenticators (Touch ID, Face ID, Windows Hello)
- Security keys (YubiKey, Titan Key)
- Platform authenticators (TPM, Secure Enclave)
Challenge-Response
WebAuthn uses cryptographic challenge-response:- Server generates random challenge
- Client signs challenge with private key
- Server verifies signature with public key
Registration Flow
Generate Registration Options
Create options for credential registration. Implementation:io.supertokens.webauthn.WebAuthN.generateRegisterOptions() - View source
API Endpoint:
POST /recipe/webauthn/options/register
Request Body:
-7: ES256 (ECDSA with SHA-256)-257: RS256 (RSASSA-PKCS1-v1_5 with SHA-256)
Register Credential
Verify and store the credential. Implementation:io.supertokens.webauthn.WebAuthN.registerCredentials() - View source
Process:
- Retrieve generated options
- Validate credential format
- Verify attestation signature
- Extract public key
- Store credential
/recipe/webauthn/credentials/register
Request Body:
Sign Up with Credential
Create a new user and credential in one transaction. Implementation:io.supertokens.webauthn.WebAuthN.signUp() - View source
API Endpoint:
POST /recipe/webauthn/signup
Request Body:
Authentication Flow
Generate Sign-In Options
Create options for authentication. Implementation:io.supertokens.webauthn.WebAuthN.generateSignInOptions() - View source
API Endpoint:
POST /recipe/webauthn/options/signin
Request Body:
Sign In
Verify credential and authenticate user. Implementation:io.supertokens.webauthn.WebAuthN.signIn() - View source
Process:
- Retrieve sign-in options
- Load credential by ID
- Verify authentication data
- Update signature counter
- Return user information
/recipe/webauthn/signin
Request Body:
Credential Management
List Credentials
Get all credentials for a user. Implementation:io.supertokens.webauthn.WebAuthN.listCredentialsForUser() - View source
API Endpoint:
GET /recipe/webauthn/credentials/list?userId={userId}
Response:
Get Credential
Retrieve specific credential details. Implementation:io.supertokens.webauthn.WebAuthN.loadCredentialByIdForUser() - View source
API Endpoint:
GET /recipe/webauthn/credential?credentialId={id}&userId={userId}
Remove Credential
Delete a credential. Implementation:io.supertokens.webauthn.WebAuthN.removeCredential() - View source
API Endpoint:
POST /recipe/webauthn/credentials/remove
Request Body:
Account Recovery
WebAuthn accounts can be recovered via email.Generate Recovery Token
Implementation:io.supertokens.webauthn.WebAuthN.generateRecoverAccountToken() - View source
API Endpoint:
POST /recipe/webauthn/account/recover/token
Request Body:
Consume Recovery Token
Implementation:io.supertokens.webauthn.WebAuthN.consumeRecoverAccountToken() - View source
API Endpoint:
POST /recipe/webauthn/account/recover/token/consume
Request Body:
User Management
Update User Email
Implementation:io.supertokens.webauthn.WebAuthN.updateUserEmail() - View source
API Endpoint:
PUT /recipe/webauthn/user/email
Request Body:
Configuration
WebAuthn Settings
Relying Party Configuration
Configure in your application: RP ID:- Must match the domain
- Can be the root domain or subdomain
- Example: “example.com” or “auth.example.com”
- Must be the full URL
- Must use HTTPS in production
- Example: “https://example.com”
Security Features
Attestation Verification
Verify authenticator authenticity during registration. Implementation:io.supertokens.webauthn.WebAuthN.verifyRegistrationData() - View source
Attestation Types:
none: No attestation (most common)indirect: Anonymized attestationdirect: Full attestation chain
Signature Counter
Detect cloned authenticators:Challenge Validation
Challenges are:- 32 random bytes
- One-time use
- Time-limited (default: 60 seconds)
- Cryptographically signed by authenticator
Origin Validation
Strict origin checking:- Must match exactly
- No wildcards allowed
- HTTPS required in production
WebAuthn Options
User Verification
Controls biometric/PIN verification:required: Always verify user (biometric/PIN)preferred: Verify if possiblediscouraged: Skip verification
preferred for good UX and security balance.
Resident Keys
Also known as “discoverable credentials” or “passkeys”:required: Must be stored on authenticatorpreferred: Store if possiblediscouraged: Don’t store on authenticator
- Usernameless login
- Better UX on mobile
- Works across devices (with sync)
Attestation
Control authenticator verification:none: No attestation (fastest)indirect: Anonymized attestationdirect: Full attestation (privacy concerns)
none unless you need to restrict authenticator types.
Client-Side Integration
Registration (JavaScript)
Authentication (JavaScript)
Error Handling
Common Exceptions
WebauthNVerificationFailedException: Signature verification failedWebauthNInvalidFormatException: Malformed credential dataWebauthNOptionsNotExistsException: Options expired or not foundInvalidWebauthNOptionsException: Invalid or expired optionsDuplicateCredentialException: Credential already registeredInvalidTokenException: Recovery token invalid or expired
Best Practices
- HTTPS only: WebAuthn requires HTTPS (except localhost)
- User verification: Use
preferredfor best UX - Resident keys: Enable for passkey support
- Multiple credentials: Allow users to register multiple devices
- Recovery flow: Implement email-based recovery
- Clear naming: Help users identify their credentials
- Error handling: Provide helpful error messages
- Browser support: Check for WebAuthn support
- Timeout: Use reasonable timeouts (60 seconds)
- Testing: Test on multiple browsers and devices
Browser Support
WebAuthn is supported in:- Chrome 67+
- Firefox 60+
- Safari 14+
- Edge 18+
- Windows Hello (Windows 10+)
- Touch ID / Face ID (iOS 14+, macOS)
- Android biometrics (Android 9+)
Multi-Tenancy
WebAuthn credentials are tenant-specific:- Credentials are isolated per tenant
- Relying Party ID can vary by tenant
- Options validation respects tenant context