Skip to content

Enhance MFA setup handling in CognitoIdpBackend#9815

Open
luchesar wants to merge 3 commits intogetmoto:masterfrom
Teal-Connect:master
Open

Enhance MFA setup handling in CognitoIdpBackend#9815
luchesar wants to merge 3 commits intogetmoto:masterfrom
Teal-Connect:master

Conversation

@luchesar
Copy link

@luchesar luchesar commented Mar 5, 2026

  • 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.

luchesar added 3 commits March 5, 2026 17:44
- 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.
Copy link
Collaborator

@bpandola bpandola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchesar There are a lot of unrelated formatting changes in here that need to be reverted. Additionally, see my comments about not modifying any "core" functionality.

headers["x-moto-temporary-password"] = temp_password

return ActionResult({"User": user.to_json(extended=True)}, headers=headers)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't modify ActionResult. If you need to manually add a header, use self.response_headers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to modify "core" functionality unless absolutely necessary. See my other comment for how to return a custom header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants