Amazon Cognito has built-in passkey sign-in, but only on the Essentials and Plus feature plans. A user pool on the Lite plan doesn't get it. We wanted to know whether a Lite pool could still offer passkeys, so we tried it: the custom authentication Lambda triggers call an external passkey API, and Cognito keeps doing everything else. It works, and this post walks through the whole setup with the AWS CLI.
We use SealGate for passkey registration and verification. Cognito still issues the ID token, access token and refresh token after a successful sign-in, so the token verification in your app doesn't change.
How it fits together
Sign-in follows Cognito's custom authentication flow (CUSTOM_AUTH):
- The browser calls Cognito's
InitiateAuthwith the username. - Cognito invokes the Create Lambda. It calls SealGate's
POST /v1/login/optionsto create the sign-in options, which go back to the browser through Cognito. - The browser signs with the passkey on the device and sends the result with
RespondToAuthChallenge. - Cognito invokes the Verify Lambda. It calls SealGate's
POST /v1/login/verifyto verify the signature. - If verification succeeds, Cognito issues the tokens.
For the user ID on the SealGate side (external_id) we use the Cognito sub. It never changes, so the mapping survives a username or email change.
What you need
- The AWS CLI, with permission to manage Cognito, Lambda and IAM
- Node.js 22 (the Lambda runtime is Node.js 22 as well)
- A SealGate test API key (it starts with
sk_test_)
The commands below run in the Tokyo region (ap-northeast-1). Swap in your own.
export AWS_DEFAULT_REGION=ap-northeast-1 ACCOUNT=$(aws sts get-caller-identity --query Account --output text) 1. Set up a SealGate test environment
Create a project in the SealGate dashboard. The test environment comes preset for local development: the domain is localhost and the allowed origin is http://localhost:3000. If your sign-in page runs on a different origin, add it to the allowed origins.
Then create a test API key. It goes into the Lambda environment and never reaches the browser.
2. Create the three Lambda functions
Custom authentication uses three triggers: Define, Create and Verify. We put all three in one file, with no external packages.
// index.mjs const API = 'https://api.sealgate.jp/v1'; // Cognito expects a Lambda response within 5 seconds, so we give up on the API call after 4 async function sg(path, body) { const res = await fetch(`${API}${path}`, { method: 'POST', headers: { authorization: `Bearer ${process.env.SEALGATE_API_KEY}`, 'content-type': 'application/json', }, body: JSON.stringify(body), signal: AbortSignal.timeout(4000), }); const json = await res.json(); if (!res.ok) throw new Error(`${path} ${res.status} ${json?.error?.code ?? ''}`); return json; } // Define: decide whether to present a challenge, issue tokens, or fail export const define = async (event) => { const session = event.request.session; const last = session[session.length - 1]; if (event.request.userNotFound) { event.response.issueTokens = false; event.response.failAuthentication = true; } else if (session.length === 0) { event.response.issueTokens = false; event.response.failAuthentication = false; event.response.challengeName = 'CUSTOM_CHALLENGE'; } else if (last.challengeName === 'CUSTOM_CHALLENGE' && last.challengeResult === true) { event.response.issueTokens = true; event.response.failAuthentication = false; } else { event.response.issueTokens = false; event.response.failAuthentication = true; } return event; }; // Create: create the sign-in options. The options go to the browser; challenge_id stays inside Cognito export const create = async (event) => { const start = await sg('/login/options', { external_id: event.request.userAttributes.sub }); event.response.publicChallengeParameters = { options: JSON.stringify(start.options) }; event.response.privateChallengeParameters = { challenge_id: start.challenge_id }; event.response.challengeMetadata = 'PASSKEY'; return event; }; // Verify: verify the signature from the browser, and succeed only if the user matches the sub export const verify = async (event) => { try { const result = await sg('/login/verify', { challenge_id: event.request.privateChallengeParameters.challenge_id, response: JSON.parse(event.request.challengeAnswer), }); event.response.answerCorrect = result.external_id === event.request.userAttributes.sub; } catch (e) { console.log(JSON.stringify({ verifyError: String(e.message) })); event.response.answerCorrect = false; } return event; }; Three things to check in this code:
-
publicChallengeParametersis returned to the browser.privateChallengeParametersis kept inside Cognito.challenge_idbelongs in the private one. - Verify doesn't stop at "the signature is valid". It also checks that the returned
external_idequals thesubof the user who is signing in. - Define fails the attempt when
userNotFoundis set. A later step turns on the setting that hides whether a user exists, and with it the Lambda is invoked for unknown usernames too.
Create the execution role and the three functions:
aws iam create-role --role-name cognito-passkey-lambda \ --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}' aws iam attach-role-policy --role-name cognito-passkey-lambda \ --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole zip fn.zip index.mjs for f in define create verify; do aws lambda create-function --function-name cognito-passkey-$f \ --runtime nodejs22.x --handler index.$f \ --role arn:aws:iam::$ACCOUNT:role/cognito-passkey-lambda \ --zip-file fileb://fn.zip --timeout 5 --memory-size 256 \ --environment "Variables={SEALGATE_API_KEY=sk_test_...}" done Right after the role is created, create-function can fail. If it does, wait about 10 seconds and run it again.
In production, keep the API key in AWS Secrets Manager or similar instead of putting it straight into an environment variable.
3. Create the user pool and the app client
Create the user pool on the Lite plan and attach the three functions as triggers.
L=arn:aws:lambda:ap-northeast-1:$ACCOUNT:function:cognito-passkey POOL=$(aws cognito-idp create-user-pool --pool-name passkey-demo \ --user-pool-tier LITE \ --lambda-config "DefineAuthChallenge=$L-define,CreateAuthChallenge=$L-create,VerifyAuthChallengeResponse=$L-verify" \ --query UserPool.Id --output text) for f in define create verify; do aws lambda add-permission --function-name cognito-passkey-$f \ --statement-id cognito --action lambda:InvokeFunction \ --principal cognito-idp.amazonaws.com \ --source-arn arn:aws:cognito-idp:ap-northeast-1:$ACCOUNT:userpool/$POOL done CLIENT=$(aws cognito-idp create-user-pool-client --user-pool-id $POOL \ --client-name web --no-generate-secret \ --explicit-auth-flows ALLOW_CUSTOM_AUTH ALLOW_REFRESH_TOKEN_AUTH \ --prevent-user-existence-errors ENABLED \ --query UserPoolClient.ClientId --output text) The app client needs ALLOW_CUSTOM_AUTH in its auth flows. For an existing user pool, keep the flows you already have (ALLOW_USER_SRP_AUTH and so on), add ALLOW_CUSTOM_AUTH, and set the Lambda triggers with update-user-pool.
The custom authentication triggers were accepted on a Lite user pool. We didn't have to move the pool to Essentials.
4. Register a passkey
Registration happens outside Cognito's authentication flow. For a user who is already signed in the existing way (a password, for example), your app server calls SealGate's registration API.
The server verifies the ID token it gets from the browser and passes its sub as the external_id.
// server.js (registration endpoints) import { SealGate } from 'sealgate-server'; const sg = new SealGate(process.env.SEALGATE_API_KEY); app.post('/api/passkey/options', async (c) => { const user = await verifyIdToken(c); // verifies the Cognito ID token and returns { sub, email } if (!user) return c.json({ error: { code: 'unauthorized' } }, 401); return c.json( await sg.register.options({ external_id: user.sub, display_name: user.email, signed_in: true }), ); }); app.post('/api/passkey/verify', async (c) => { if (!(await verifyIdToken(c))) return c.json({ error: { code: 'unauthorized' } }, 401); const body = await c.req.json(); return c.json( await sg.register.verify({ challenge_id: body.challenge_id, response: body.response, name: body.name }), ); }); In the browser, point the SealGate browser SDK at those two endpoints.
<button id="passkey-register" type="button">Add a passkey on this device</button> <script type="module"> import { SealGate } from 'https://sealgate.jp/sdk/v1.js'; const sg = new SealGate({ optionsUrl: '/api/passkey/options', verifyUrl: '/api/passkey/verify' }); document.getElementById('passkey-register').addEventListener('click', async () => { await sg.register({ name: 'This device' }); }); </script> Registration is the same as in any other app. The details are in Add passkeys to an existing login.
5. Sign in with the passkey
At sign-in, the options arrive as a Cognito challenge. So instead of the browser SDK's login(), the page calls the Cognito API and the WebAuthn API directly.
// login.js const ENDPOINT = 'https://cognito-idp.ap-northeast-1.amazonaws.com/'; const CLIENT_ID = '<your app client ID>'; async function cognito(target, body) { const res = await fetch(ENDPOINT, { method: 'POST', headers: { 'content-type': 'application/x-amz-json-1.1', 'x-amz-target': `AWSCognitoIdentityProviderService.${target}`, }, body: JSON.stringify(body), }); const json = await res.json(); if (!res.ok) throw new Error(json.message ?? 'Sign-in failed'); return json; } export async function loginWithPasskey(username) { // 1. Start custom authentication and receive the sign-in options const init = await cognito('InitiateAuth', { AuthFlow: 'CUSTOM_AUTH', ClientId: CLIENT_ID, AuthParameters: { USERNAME: username }, }); // 2. Sign with the passkey on the device const publicKey = PublicKeyCredential.parseRequestOptionsFromJSON( JSON.parse(init.ChallengeParameters.options), ); const credential = await navigator.credentials.get({ publicKey }); // 3. Send the signature. If it verifies, the tokens come back const done = await cognito('RespondToAuthChallenge', { ChallengeName: 'CUSTOM_CHALLENGE', ClientId: CLIENT_ID, Session: init.Session, ChallengeResponses: { USERNAME: username, ANSWER: JSON.stringify(credential.toJSON()) }, }); return done.AuthenticationResult; // IdToken, AccessToken, RefreshToken } If you use the AWS SDK or Amplify, the API calls are the same two: InitiateAuth and RespondToAuthChallenge.
6. What we tested
We created two users in the pool (alice and bob), registered a passkey for alice, and checked the seven cases below. The test was a script that calls the Cognito API and signs with a software authenticator in place of a browser.
| # | What we did | Result |
|---|---|---|
| 1 | alice signs in with her passkey | Tokens issued. The sub in the ID token is alice's |
| 2 | Sign in again | Tokens issued |
| 3 | Send the first signature a second time | Fails (rejected as a used challenge) |
| 4 | Use alice's device with bob's username | Fails |
| 5 | Give a username that doesn't exist | Fails (Define fails it on userNotFound) |
| 6 | Revoke the passkey, then sign in | Fails |
| 7 | Register a passkey on a new device with a recovery token, then sign in | Tokens issued |
We also measured the Lambda run time. Cognito's limit is 5 seconds.
| Create | Verify | |
|---|---|---|
| First call (cold start) | about 1.4 s | about 1.6 s |
| After that | 150–260 ms | 150–260 ms |
Seen from the user, sign-in (two round trips to Cognito) took about 4 seconds the first time and 0.7–0.9 seconds after that.
When a device is lost
For a user who lost the device that holds the passkey:
- Revoke the passkey on the lost device (
DELETE /v1/credentials/:id). - Confirm who they are with what Cognito already gives you, such as an email or SMS code.
- Call
POST /v1/recovery/startfrom your server to issue a recovery token. - Pass the recovery token (
recovery_token) when you create the registration options. From there it's a normal registration.
How you confirm the user's identity is up to your app.
Things to know before you build this
- The username comes first. Custom authentication starts with a username. A screen where the user signs in with a passkey alone, without typing a username, can't be built this way.
- No managed login. The managed login pages can't handle custom authentication. You build the sign-in page yourself.
- The Lambda limit is 5 seconds. It can't be changed. Give the external API call a shorter timeout. If cold starts bother you, look at provisioned concurrency.
- Decide the RP ID before launch. Passkeys are bound to the RP ID (the domain). Change the domain later and users have to register again.
Clean up
aws cognito-idp delete-user-pool --user-pool-id $POOL for f in define create verify; do aws lambda delete-function --function-name cognito-passkey-$f; done aws iam detach-role-policy --role-name cognito-passkey-lambda \ --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole aws iam delete-role --role-name cognito-passkey-lambda Summary
- Cognito's built-in passkeys are for Essentials and Plus. On a Lite user pool you can add passkeys by calling an external passkey API from the custom authentication Lambda triggers.
- What you add: three Lambda functions, two registration endpoints, and the sign-in code on the page. Cognito still issues the tokens, so token verification in your app stays as it is.
- If you're already on Essentials or above and a username-first flow is fine for you, the built-in feature is less work.
References:
- Amazon Cognito: user pool feature plans
- Amazon Cognito: custom authentication challenge Lambda triggers
- SealGate docs
SealGate is free up to 1,000 monthly active users, and users in the test environment aren't counted: https://app.sealgate.jp/signup