-
Notifications
You must be signed in to change notification settings - Fork 122
fix(auth): Fix confirm signin when incorrect MFA code is entered #2286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9dcc7f6
Added the challengestate to the signin error state
gpanshu 06b3fae
Fix confirm sign in
gpanshu 735bb2c
Merge branch 'main' into fix-confirm-signin
gpanshu ec8df34
Lint fix + adding integration test
gpanshu a151860
Adding tests for confirm sign in
gpanshu 2cddb87
Fixing tests
gpanshu dadd049
reverting serialization tools
gpanshu ad5a10d
reverting serialization tools
gpanshu 6353e11
Merge branch 'main' into fix-confirm-signin
gpanshu 4a0d605
lint fix
gpanshu 8c75154
Fix confirm sign in test case
gpanshu 5bd5172
Addressed PR comments
gpanshu 2fe92aa
Revert "Addressed PR comments"
gpanshu 93b79cd
Reverting last commit and removal of the SignedInException
gpanshu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
|
@@ -588,11 +588,19 @@ internal class RealAWSCognitoAuthPlugin( | |
authStateMachine.getCurrentState { authState -> | ||
val authNState = authState.authNState | ||
val signInState = (authNState as? AuthenticationState.SigningIn)?.signInState | ||
when ((signInState as? SignInState.ResolvingChallenge)?.challengeState) { | ||
is SignInChallengeState.WaitingForAnswer -> { | ||
_confirmSignIn(challengeResponse, options, onSuccess, onError) | ||
if (signInState is SignInState.ResolvingChallenge) { | ||
when (signInState.challengeState) { | ||
is SignInChallengeState.WaitingForAnswer, is SignInChallengeState.Error -> { | ||
_confirmSignIn(challengeResponse, options, onSuccess, onError) | ||
} | ||
else -> { | ||
onError.accept(InvalidStateException()) | ||
} | ||
} | ||
else -> onError.accept(InvalidStateException()) | ||
} else if (authNState is AuthenticationState.SignedIn) { | ||
onError.accept(SignedInException()) | ||
gpanshu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
onError.accept(InvalidStateException()) | ||
} | ||
} | ||
} | ||
|
@@ -610,7 +618,6 @@ internal class RealAWSCognitoAuthPlugin( | |
val authNState = authState.authNState | ||
val authZState = authState.authZState | ||
val signInState = (authNState as? AuthenticationState.SigningIn)?.signInState | ||
val challengeState = (signInState as? SignInState.ResolvingChallenge)?.challengeState | ||
when { | ||
authNState is AuthenticationState.SignedIn && | ||
authZState is AuthorizationState.SessionEstablished -> { | ||
|
@@ -625,21 +632,35 @@ internal class RealAWSCognitoAuthPlugin( | |
signInState is SignInState.Error -> { | ||
authStateMachine.cancel(token) | ||
onError.accept( | ||
CognitoAuthExceptionConverter.lookup(signInState.exception, "Confirm Sign in failed.") | ||
CognitoAuthExceptionConverter.lookup( | ||
signInState.exception, "Confirm Sign in failed." | ||
) | ||
) | ||
} | ||
signInState is SignInState.ResolvingChallenge && | ||
signInState.challengeState is SignInChallengeState.Error -> { | ||
(signInState.challengeState as SignInChallengeState.Error).exception?.let { | ||
authStateMachine.cancel(token) | ||
onError.accept( | ||
CognitoAuthExceptionConverter.lookup( | ||
error = it, | ||
fallbackMessage = "Confirm Sign in failed." | ||
) | ||
) | ||
(signInState.challengeState as? SignInChallengeState.Error)?.exception = null | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
val awsCognitoConfirmSignInOptions = options as? AWSCognitoAuthConfirmSignInOptions | ||
val event = SignInChallengeEvent( | ||
SignInChallengeEvent.EventType.VerifyChallengeAnswer( | ||
challengeResponse, | ||
awsCognitoConfirmSignInOptions?.metadata ?: mapOf() | ||
) | ||
}, { | ||
val awsCognitoConfirmSignInOptions = options as? AWSCognitoAuthConfirmSignInOptions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation looks off, I wonder how it passed lint check. |
||
val event = SignInChallengeEvent( | ||
SignInChallengeEvent.EventType.VerifyChallengeAnswer( | ||
challengeResponse, | ||
awsCognitoConfirmSignInOptions?.metadata ?: mapOf() | ||
) | ||
authStateMachine.send(event) | ||
} | ||
) | ||
authStateMachine.send(event) | ||
} | ||
) | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...confirmSignIn/Test_that_invalid_code_on_confirm_SignIn_with_SMS_challenge_errors_out.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"description": "Test that invalid code on confirm SignIn with SMS challenge errors out", | ||
"preConditions": { | ||
"amplify-configuration": "authconfiguration.json", | ||
"state": "SigningIn_SigningIn.json", | ||
"mockedResponses": [ | ||
{ | ||
"type": "cognitoIdentityProvider", | ||
"apiName": "respondToAuthChallenge", | ||
"responseType": "failure", | ||
"response": { | ||
"errorType": "CodeMismatchException", | ||
"errorMessage": "Confirmation code entered is not correct." | ||
} | ||
} | ||
] | ||
}, | ||
"api": { | ||
"name": "confirmSignIn", | ||
"params": { | ||
"challengeResponse": "000000" | ||
}, | ||
"options": { | ||
} | ||
}, | ||
"validations": [ | ||
{ | ||
"type": "amplify", | ||
"apiName": "confirmSignIn", | ||
"responseType": "failure", | ||
"response": { | ||
"errorType": "CodeMismatchException", | ||
"errorMessage": "Confirmation code entered is not correct.", | ||
"recoverySuggestion": "Enter correct confirmation code.", | ||
"cause": { | ||
"errorType": "CodeMismatchException", | ||
"errorMessage": "Confirmation code entered is not correct." | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like code paths are still the same. This change looks unnecessary.