To configure the user's MFA configuration to TOTP MFA, run either the set-user-mfa-preference or admin-set-user-mfa-preference AWS CLI command:
Example set-user-mfa-preference command
aws cognito-idp set-user-mfa-preference --software-token-mfa-settings Enabled=true,PreferredMfa=true --access-token eyJraWQiO........ua5Pq3NaA
Note: This command allows users to set their own MFA configuration.
Example admin-set-user-mfa-preference command
aws cognito-idp admin-set-user-mfa-preference --software-token-mfa-settings Enabled=true,PreferredMfa=true --username ExampleName --user-pool-id us-east-1_123456789
Note: This command allows an admin to set a user's MFA configuration.
To test your setup, authenticate the user with one of the following methods:
The Amazon Cognito hosted UI.
The InitiateAuth, AdminInitiateAuth, or RespondToAuthChallenge API calls in the AWS CLI.
Note: To authenticate a user with either method, you must have the user's password, username, and software MFA code.
Example admin-initiate-auth command
aws cognito-idp admin-initiate-auth --user-pool-id us-east-1_123456789 --client-id 3n4b5urk1ft4fl3mg5e62d9ado --auth-flow ADMIN_USER_PASSWORD_AUTH --auth-parameters USERNAME=ExampleName,PASSWORD=P@ssw0rd
Note: Replace the following variables with your information: user-pool-id, client-id, username, and password.
Example output from admin-initiate-auth command
{
"ChallengeName": "SOFTWARE_TOKEN_MFA",
"ChallengeParameters": {
"FRIENDLY_DEVICE_NAME": "ExampleDevice",
"USER_ID_FOR_SRP": "ExampleName"
},
"Session": "Xxz6iadwuWJGN4Z7f4ul5p50IHUqITquoaNxxyDvep.......3A6GokZWKeQ6gkFW4Pgv"
}
Example admin-respond-to-auth-challenge command
aws cognito-idp admin-respond-to-auth-challenge --user-pool-id us-east-1_123456789 --client-id 3n4b5urk1ft4fl3mg5e62d9ado --challenge-name SOFTWARE_TOKEN_MFA --challenge-responses USERNAME=ExampleName,SOFTWARE_TOKEN_MFA_CODE=123456 --session Xxz6iadwuWJGN4Z7f4ul5p50IHUqITquoaNxxyDvep.......3A6GokZWKeQ6gkFW4Pgv
Note: Replace the following variables with your information: client-id, username, and software_token_MFA_Code.
Example output from admin-respond-to-auth-challenge command
{
"AuthenticationResult": {
"ExpiresIn": 3600,
"RefreshToken": "eyJjdHkiOiJKV1QiLCJlbmMi.......dlbjrtyizlLzZZ5fjjCgL__AVHEzYycjJs_h3i-ly_KixDNtz9VEC",
"TokenType": "Bearer",
"NewDeviceMetadata": {
"DeviceKey": "us-east-1_28abrd7-10f7-9fc6-a931-3ede1c8ckd75",
"DeviceGroupKey": "-Gqkj3brS"
},
"IdToken": "eyJraWQiOiIzcFFSV29Pb........mNMbE_vvPkQYBuA9ackoER1aSABFGaKK4BpgPjMn7la_A",
"AccessToken": "eyJraWQiOi...........qwvQq4awt63TyWw"
},
"ChallengeParameters": {}
}