Skip to content

feat(cognito): support email based MFA#31816

Merged
mergify[bot] merged 8 commits intoaws:mainfrom
mazyu36:cognito-mfa-email
Oct 22, 2024
Merged

feat(cognito): support email based MFA#31816
mergify[bot] merged 8 commits intoaws:mainfrom
mazyu36:cognito-mfa-email

Conversation

@mazyu36
Copy link
Copy Markdown
Contributor

@mazyu36 mazyu36 commented Oct 19, 2024

Issue # (if applicable)

Closes #31815.

Reason for this change

To use email based MFA.

Description of changes

Add email option to MfaSecondFactor.

Description of how you validated changes

Add unit tests and integ test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team October 19, 2024 15:02
@github-actions github-actions bot added feature-request A feature should be added or improved. p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Oct 19, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 20, 2024
}
if (props.mfaSecondFactor!.otp) {
enabledMfas.push('SOFTWARE_TOKEN_MFA');
} if (props.mfaSecondFactor!.email) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An idea to make this code more readable - we could add a helper function to validate email MFA, something like:

function validateEmailMfa(props: UserPoolProps) {
  if (!props.email || this.emailConfiguration?.emailSendingAccount !== 'DEVELOPER') {
    throw new Error('To enable email-based MFA, set `email` property to the Amazon SES email-sending configuration.');
  }
  
  if (props.advancedSecurityMode === AdvancedSecurityMode.OFF) {
    throw new Error('To enable email-based MFA, set `advancedSecurityMode` to `AdvancedSecurity.ENFORCED` or `AdvancedSecurity.AUDIT`.');
  }
}

and then replace the if statements with:

if (props.mfaSecondFactor!.otp) {
  enabledMfas.push('SOFTWARE_TOKEN_MFA');
}

if (props.mfaSecondFactor!.email) {
  validateEmailMfa(props);
  enabledMfas.push('EMAIL_OTP');
}

Makes it easier to follow this code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I've updated.
I thought private methods would be better so I went with that approach.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, thanks @mazyu36 !

@mazyu36 mazyu36 requested a review from sumupitchayan October 22, 2024 01:54
sumupitchayan
sumupitchayan previously approved these changes Oct 22, 2024
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 22, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 22, 2024
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 22, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@sumupitchayan
Copy link
Copy Markdown
Contributor

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 22, 2024

update

❌ Mergify doesn't have permission to update

Details

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/request-cli-integ-test.yml without workflows permission

@mergify mergify bot dismissed sumupitchayan’s stale review October 22, 2024 22:06

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 22, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 5bd23e2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit f9d6eef into aws:main Oct 22, 2024
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 22, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2024
@mazyu36 mazyu36 deleted the cognito-mfa-email branch October 22, 2024 23:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK feature-request A feature should be added or improved. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cognito: support email for multi-factor authentication (MFA)

4 participants