Prompt
How do I let users sign in with a passkey on web and mobile?
Latest observation
To let users sign in with a passkey on web and mobile, you typically use WebAuthn / Passkeys APIs on the web and the platform credential managers on mobile, all backed by the same server-side auth flow.
1) High-level architecture
You need:
- Server
- Issues challenges
- Verifies passkey responses
- Stores credential public keys and metadata
- Web app
- Uses WebAuthn
- Mobile app
- Uses platform passkey APIs
- iOS: AuthenticationServices
- Android: Credential Manager / FIDO2
- Uses platform passkey APIs
Passkeys are based on public-key cryptography, so your server never stores a password. It stores:
- user ID
- credential ID
- public key
- sign count / metadata
2) Two main flows
Registration
User creates a passkey for your account.
- Server creates a registration challenge
- Client calls passkey creation API
- Authenticator/user verifies with biometrics/device lock
- Client sends result back to server
- Server verifies and stores the public key
Authentication
User signs in with an existing passkey.
- Server creates an authentication challenge
- Client calls passkey assertion/sign-in API
- Authenticator verifies user
- Client sends signed assertion to server
- Server verifies signature and logs user in
3) Web implementation
Use WebAuthn in browsers.
Registration on web
const options = await fetch('/auth/register/options', { method: 'POST' }).then(r => r.json());
options.challenge = base64urlToBuffer(options.challenge);
options.user.id = base64urlToBuffer(options.user.id);
options.excludeCredentials = options.excludeCredentials?.map(c => ({
...c,
id: base64urlToBuffer(c.id),
}));
const credential = await navigator.credentials.create({
publicKey: options
});
await fetch('/auth/register/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(credential)
});
Authentication on web
const options = await fetch('/auth/login/options', { method: 'POST' }).then(r => r.json());
options.challenge = base64urlToBuffer(options.challenge);
options.allowCredentials = options.allowCredentials?.map(c => ({
...c,
id: base64urlToBuffer(c.id),
}));
const assertion = await navigator.credentials.get({
publicKey: options
});
await fetch('/auth/login/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(assertion)
});
Important:
- Passkeys require HTTPS
- Your domain must be correctly configured
- Use origin/RP ID validation on the server
4) iOS implementation
Use AuthenticationServices.
Sign up / create passkey
ASAuthorizationPlatformPublicKeyCredentialProviderASAuthorizationController
Sign in
ASAuthorizationPlatformPublicKeyCredentialProviderASAuthorizationController
Typical flow:
- Fetch challenge/options from your backend
- Build a request using Apple APIs
- Present authorization controller
- Send attestation/assertion data back to backend for verification
Apple supports passkeys synced via iCloud Keychain.
5) Android implementation
Use Credential Manager for passkeys.
Sign up
- Create a
CreatePublicKeyCredentialRequest - Request passkey creation
Sign in
- Create a
GetPublicKeyCredentialOption - Request a passkey assertion
Flow:
- Get challenge/options from backend
- Call Credential Manager
- Send returned credential data to backend
- Backend verifies response
Credential Manager is the recommended modern API.
6) Backend requirements
Your backend should implement:
Challenge endpoints
POST /auth/register/optionsPOST /auth/register/verifyPOST /auth/login/optionsPOST /auth/login/verify
Verification steps
For both registration and login:
- Check challenge matches what you issued
- Check origin / RP ID
- Check signature is valid
- Check user and credential binding
- Check sign counter if applicable
Store
userIdcredentialIdpublicKeytransportssignCountcreatedAt
7) Cross-platform strategy
If you want the same account to work on web and mobile:
- Use the same backend passkey system
- Use the same user IDs
- Let users create one or more passkeys per account
- Support discovery login:
- User enters email or username, or
- User uses “Sign in with a passkey” and the authenticator discovers the account
Recommended UX:
- “Continue with passkey”
- Fallbacks:
- email magic link
- password
- recovery codes
- support-based recovery
8) Libraries you can use
Web / Node
@simplewebauthn/server@simplewebauthn/browser
Server-side
fido2-lib- WebAuthn libraries in your backend language
Mobile
- iOS: native AuthenticationServices
- Android: native Credential Manager APIs
9) Security best practices
- Use HTTPS everywhere
- Verify origin and RP ID strictly
- Use a short-lived, single-use challenge
- Store challenges server-side or signed
- Allow credential registration only after authenticated session or email verification
- Provide account recovery options
- Support multiple passkeys per account
- Keep passkey login as the primary path, but don’t trap users with no recovery
10) Recommended implementation plan
- Add server challenge/verify endpoints
- Add WebAuthn to your web app
- Add iOS passkey support
- Add Android Credential Manager support
- Normalize credential storage on the backend
- Add UX for:
- create passkey
- sign in with passkey
- manage/delete passkeys
- recover account
If you want, I can give you:
- a complete backend example in Node/Express,
- a web implementation using SimpleWebAuthn, or
- iOS + Android sample code for passkey sign-in.