Enhance MFA setup handling in CognitoIdpBackend#9815
Open
luchesar wants to merge 3 commits intogetmoto:masterfrom
Open
Enhance MFA setup handling in CognitoIdpBackend#9815luchesar wants to merge 3 commits intogetmoto:masterfrom
luchesar wants to merge 3 commits intogetmoto:masterfrom
Conversation
- Updated MFA logic to include a new challenge for MFA setup when MFA is enabled and the user has not verified their token or enabled SMS MFA. - Added support for returning available MFA options (SOFTWARE_TOKEN_MFA and SMS_MFA) during the MFA setup challenge. - Changed the default secret code for software token association to a valid value. Additionally, added a test to verify the MFA setup challenge behavior when MFA is enabled.
- Introduced a new `CodeMismatchException` to handle invalid MFA codes during verification. - Implemented TOTP verification logic in `CognitoIdpBackend` to validate user-provided codes against stored secrets. - Updated the `associate_software_token` method to generate and return a unique MFA secret for users. - Enhanced the `verify_software_token` method to include user code validation and raise exceptions for mismatches. - Modified tests to cover new MFA verification scenarios and ensure proper handling of TOTP codes.
- Updated the `admin_create_user` method in `CognitoIdpBackend` to return a tuple containing the user and the temporary password. - Modified the `CognitoIdpResponse` class to handle the temporary password in the response headers when requested. - Enhanced the `ActionResult` class to support custom headers, ensuring proper serialization of responses with additional header information. - Introduced a new method `_get_header` in `BaseResponse` for improved header retrieval. These changes improve the user creation flow and allow clients to receive temporary passwords as needed.
bpandola
requested changes
Mar 17, 2026
| headers["x-moto-temporary-password"] = temp_password | ||
|
|
||
| return ActionResult({"User": user.to_json(extended=True)}, headers=headers) | ||
|
|
Collaborator
There was a problem hiding this comment.
Don't modify ActionResult. If you need to manually add a header, use self.response_headers.
Collaborator
There was a problem hiding this comment.
We don't want to modify "core" functionality unless absolutely necessary. See my other comment for how to return a custom header.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Additionally, added a test to verify the MFA setup challenge behavior when MFA is enabled.