- Newest
- Most votes
- Most comments
We ran into this same issue regarding the Passkeys and Password + MFA not being supported. We have AWS business support so we were able to put a ticket in as I assumed it was a bug. However after talks with their Cognito dev team, they said it was behaving as expected.
From AWS Business Support:
Thank you for your patience while I discussed this behavior with the Cognito Service Team. I now have confirmation from the team that this is indeed working as expected.
When both MFA and Choice-Based sign-in method are active, MFA takes more priority, and the user then needs to input the password then MFA verification code. So MFA will override other Choice-based sign-in methods [Password, Passkey, Email OTP, Phone OTP] and they will no longer e available.
However, upon review we found that this is "override" is not communicated very clearly in the public documentation. Therefore, our Cognito Service Team is currently updating the documentation to reflect this behavior more accurately.
I would also like to see this change, but for now it seems unlikely.
answered 2 years ago
Here are some potential solutions to address both issues:
For the username/email requirement: Solution 1: Store the last used username in localStorage
const lastUsedEmail = localStorage.getItem('lastLoginEmail');
if (lastUsedEmail) {
// Attempt passkey login with stored email
await signIn({
username: lastUsedEmail,
options: {
authFlowType: 'USER_AUTH',
preferredChallenge: 'WEB_AUTHN',
},
});
}
Solution 2: Use a discovery service Create a separate API endpoint that maps WebAuthn credentials to usernames
async function getUsernameFromCredential(credentialId) {
const response = await fetch('/api/get-username', {
method: 'POST',
body: JSON.stringify({ credentialId })
});
return response.json();
}
For the MFA issue: Solution 1: Handle MFA challenge separately
const signInWithPasskey = async (username) => {
try {
const response = await signIn({
username,
options: {
authFlowType: 'USER_AUTH',
preferredChallenge: 'WEB_AUTHN',
},
});
if (response.challengeName === 'SOFTWARE_TOKEN_MFA') {
// Prompt user for MFA code
const mfaCode = await promptForMFACode(); // Implement this function
// Complete MFA challenge
const result = await confirmSignIn({
challengeResponse: mfaCode
});
return result;
}
return response;
} catch (error) {
console.error('Sign-in error:', error);
throw error;
}
};
Solution 2: Configure Passkey as an MFA method In your Cognito User Pool settings, configure WebAuthn/Passkey as an acceptable MFA method alongside TOTP Alternative approach using custom authentication flow: Create a custom auth flow that combines passkey and MFA
const customAuthFlow = async () => {
try {
// Step 1: Initialize WebAuthn assertion
const assertion = await navigator.credentials.get({
publicKey: // ... your WebAuthn options
});
// Step 2: Send assertion to backend
const response = await API.post('auth', '/verify-passkey', {
body: {
assertion,
// Include any other necessary data
}
});
// Step 3: Handle MFA if required
if (response.requiresMFA) {
const mfaCode = await promptForMFACode();
const finalResponse = await API.post('auth', '/complete-mfa', {
body: {
sessionId: response.sessionId,
mfaCode
}
});
return finalResponse;
}
return response;
} catch (error) {
console.error('Authentication error:', error);
throw error;
}
};
Backend modifications:
// In your Lambda function or backend service
exports.handler = async (event) => {
// Create a mapping table in DynamoDB to store credential-to-username mappings
const credentialTable = {
TableName: 'WebAuthnCredentials',
KeySchema: [
{ AttributeName: 'credentialId', KeyType: 'HASH' }
]
};
// When registering a passkey, store the mapping
await dynamoDB.put({
TableName: 'WebAuthnCredentials',
Item: {
credentialId: credentialId,
username: username
}
});
};
Additional recommendations:
Implement proper error handling and user feedback Add fallback mechanisms when passkey authentication fails Consider implementing a way for users to manage their passkeys Store passkey metadata securely Implement proper security measures in your backend services Remember to:
Follow security best practices Test thoroughly with different scenarios Handle edge cases appropriately Provide clear user feedback Implement proper error recovery mechanisms These solutions should help you implement a smoother passkey authentication flow while maintaining MFA security requirements.
answered 2 years ago
Thanks for these workaround ideas.
Email Solution 1 might work partially, if we add some code to watch when Amplify login occurs and store the email in local storage. But there will be problems when the user changes their email address in some other session, and local storage becomes out of date. Also, when user logs in from another computer, the email won't be known there. So I hope this problem will be fixed by AWS so that email is not required at all before passkey login.
Email Solution 2 does not work, because we don't have the credentialId before calling signIn(). So we cannot try to find the related email address first.
MFA Solution 1 does not work, because signIn() response does not return challengeName === 'SOFTWARE_TOKEN_MFA'. The response only has availableChallenges: ["PASSWORD_SRP", "PASSWORD"] and signInStep: "CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION" when MFA is enabled for the user. So the passkey login is not working at all when MFA is enabled for the user. It starts to work when MFA is disabled for the user.
MFA Solution 2 looks like we would need to replace Cognito's built-in passkey support completely with a custom solution, and we don't want to do that. I hope AWS will make Cognito work with MFA enabled.

Thanks for passing on this information! It seems the Cognito team is confused about how Passkeys are intended to work as an alternative way to securely sign in, while still allowing users to sign in with password and 2FA when needed. I hope they change their approach in the future, because otherwise Passkeys are just not usable in Cognito. There is no way I would disable 2FA and make password logins insecure just to allow Passkey logins.
Well somebody needs to tell them that their perception that you need disable be MFA to go entirely passwordless is flawed. Warning: Avoid password-only verification. If the password is leaked, attackers could create a passkey and compromise the account. Use stronger verification methods like email or phone verification. from: https://web.dev/articles/passkey-registration MFA + Passwordless should lead to require mfa for password login including the the login for passwordless setup + passwordless afterwards.If the user doesn't get that option he will end up with a less secure configuration to achieve passwordless