diff --git a/moto/cognitoidp/models.py b/moto/cognitoidp/models.py index fb77e66881ef..15aa01455bf6 100644 --- a/moto/cognitoidp/models.py +++ b/moto/cognitoidp/models.py @@ -1525,7 +1525,7 @@ def initiate_auth(self, client_id, auth_flow, auth_parameters): "ChallengeParameters": { "SALT": uuid.uuid4().hex, "SRP_B": uuid.uuid4().hex, - "USERNAME": user.id, + "USERNAME": user.username, "USER_ID_FOR_SRP": user.id, "SECRET_BLOCK": session, }, diff --git a/tests/test_cognitoidp/test_cognitoidp.py b/tests/test_cognitoidp/test_cognitoidp.py index 1219be4b6c69..671c179bdbca 100644 --- a/tests/test_cognitoidp/test_cognitoidp.py +++ b/tests/test_cognitoidp/test_cognitoidp.py @@ -2561,6 +2561,7 @@ def user_authentication_flow(conn): result["AuthenticationResult"]["IdToken"].should_not.be.none result["AuthenticationResult"]["AccessToken"].should_not.be.none + result["AuthenticationResult"]["TokenType"].should.equal("Bearer") # authenticate user once again this time with mfa token result = conn.initiate_auth( @@ -3317,6 +3318,7 @@ def test_initiate_auth_USER_SRP_AUTH(): ) result["ChallengeName"].should.equal("PASSWORD_VERIFIER") + result["ChallengeParameters"]["USERNAME"].should.equal(username) @mock_cognitoidp @@ -3385,6 +3387,7 @@ def test_initiate_auth_USER_PASSWORD_AUTH(): result["AuthenticationResult"]["AccessToken"].should_not.be.none result["AuthenticationResult"]["IdToken"].should_not.be.none result["AuthenticationResult"]["RefreshToken"].should_not.be.none + result["AuthenticationResult"]["TokenType"].should.equal("Bearer") @mock_cognitoidp