generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 103
feat(auth): Add email MFA support to Amplify Auth construct #3036
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
Open
osama-rizk
wants to merge
9
commits into
main
Choose a base branch
from
auth/amplify-auth-construct-email-mfa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6580698
feat(auth): Add email MFA support to Amplify Auth construct
osama-rizk 4feaba4
fix: add @aws-amplify/backend to changeset
osama-rizk 968c351
Remove redundant code
osama-rizk c590818
Merge branch 'main' into auth/amplify-auth-construct-email-mfa
osama-rizk 02a8b01
regenerate the schema files
osama-rizk 2e8c356
revert schema changes
osama-rizk 27b9c2c
update schema config 1.4
osama-rizk 10637f2
Update client config
osama-rizk 0b7171c
update api doc.
osama-rizk 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@aws-amplify/auth-construct': minor | ||
| '@aws-amplify/client-config': minor | ||
| '@aws-amplify/backend-auth': minor | ||
| '@aws-amplify/backend': minor | ||
| '@aws-amplify/seed': minor | ||
| --- | ||
|
|
||
| feat(auth): Added support for email-MFA in Amplify Auth construct |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,36 @@ new AmplifyAuth(stack, 'Auth', { | |
| }); | ||
| ``` | ||
|
|
||
| ### Email login with email MFA | ||
|
|
||
| In this example, you will create a stack with email login and email MFA enabled. Note that email MFA requires an email sender configuration. | ||
|
|
||
| ```ts | ||
| import { App, Stack } from 'aws-cdk-lib'; | ||
| import { AmplifyAuth } from '@aws-amplify/auth-construct'; | ||
|
|
||
| const app = new App(); | ||
| const stack = new Stack(app, 'AuthStack'); | ||
|
|
||
| new AmplifyAuth(stack, 'Auth', { | ||
| loginWith: { | ||
| email: true, | ||
| }, | ||
| multifactor: { | ||
| mode: 'OPTIONAL', | ||
| email: true, | ||
| sms: false, | ||
| totp: false, | ||
| }, | ||
| senders: { | ||
| email: { | ||
| fromEmail: '[email protected]', | ||
| fromName: 'My App', | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Customized email and phone login with external login providers | ||
|
|
||
| In this example, you will create a stack with email, phone, and external login providers. Additionally, you can customize the email and phone verification messages. | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -1169,6 +1169,62 @@ void describe('Auth construct', () => { | |
| assert.equal(outputs['mfaConfiguration']['Value'], 'ON'); | ||
| }); | ||
|
|
||
| void it('enables email MFA when email is set to true', () => { | ||
| new AmplifyAuth(stack, 'test', { | ||
| loginWith: { email: true }, | ||
| multifactor: { mode: 'OPTIONAL', email: true }, | ||
| senders: { | ||
| email: { | ||
| fromEmail: '[email protected]', | ||
| fromName: 'Example.com', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const template = Template.fromStack(stack); | ||
| template.hasResourceProperties('AWS::Cognito::UserPool', { | ||
| EnabledMfas: ['EMAIL_OTP'], | ||
| }); | ||
| const outputs = template.findOutputs('*'); | ||
| assert.equal(outputs['mfaTypes']['Value'], '["EMAIL"]'); | ||
| assert.equal(outputs['mfaConfiguration']['Value'], 'OPTIONAL'); | ||
| }); | ||
|
|
||
| void it('enables multiple MFA types including email', () => { | ||
| new AmplifyAuth(stack, 'test', { | ||
| loginWith: { email: true }, | ||
| multifactor: { mode: 'REQUIRED', sms: true, totp: true, email: true }, | ||
| senders: { | ||
| email: { | ||
| fromEmail: '[email protected]', | ||
| fromName: 'Example.com', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const template = Template.fromStack(stack); | ||
| template.hasResourceProperties('AWS::Cognito::UserPool', { | ||
| EnabledMfas: ['SMS_MFA', 'SOFTWARE_TOKEN_MFA', 'EMAIL_OTP'], | ||
| }); | ||
| const outputs = template.findOutputs('*'); | ||
| assert.equal(outputs['mfaTypes']['Value'], '["SMS","TOTP","EMAIL"]'); | ||
| assert.equal(outputs['mfaConfiguration']['Value'], 'ON'); | ||
| }); | ||
|
|
||
| void it('does not enable email MFA when email is set to false', () => { | ||
| new AmplifyAuth(stack, 'test', { | ||
| loginWith: { email: true }, | ||
| multifactor: { mode: 'OPTIONAL', sms: true, email: false }, | ||
| }); | ||
|
|
||
| const template = Template.fromStack(stack); | ||
| template.hasResourceProperties('AWS::Cognito::UserPool', { | ||
| EnabledMfas: ['SMS_MFA'], | ||
| }); | ||
| const outputs = template.findOutputs('*'); | ||
| assert.equal(outputs['mfaTypes']['Value'], '["SMS"]'); | ||
| }); | ||
|
|
||
| void it('updates socialProviders and oauth outputs when external providers are present', () => { | ||
| new AmplifyAuth(stack, 'test', { | ||
| loginWith: { | ||
|
|
||
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
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.
Is senders with email (custom email sending) required to enabled email MFA?
(not really a blocker, just curious about why senders with email is enabled in both of the tests where we want email MFA to be enabled)
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.
This property already exists and does not require enable email MFA as it can be used for other email purposes 1) email verification upon user registration and forget password
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.
If it's not necessary for email MFA, can you write a test that doesn't use it (you can just alter one of you existing tests) so when people look at these tests in the future they are not under the impression that enabling senders with email is necessary to set up in order to use email MFA?
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.
Actually it is required, if we did not pass it we will get the following error.
Apologies for the confusion.
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.
sounds good, make sure to put that information in the docs if it is not already there 👍