-
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
Changes from 7 commits
6580698
4feaba4
968c351
c590818
02a8b01
2e8c356
27b9c2c
10637f2
0b7171c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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. | ||
|
|
||
| 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: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,10 @@ export type AmplifyStorageAccessActions = | |
| * Config format for Amplify Gen 2 client libraries to communicate with backend services. | ||
| */ | ||
| export interface AWSAmplifyBackendOutputs { | ||
| /** | ||
| * JSON schema | ||
| */ | ||
| $schema?: string; | ||
|
||
| /** | ||
| * Version of this schema | ||
| */ | ||
|
|
@@ -185,7 +189,7 @@ export interface AWSAmplifyBackendOutputs { | |
| user_verification_types?: ('email' | 'phone_number')[]; | ||
| unauthenticated_identities_enabled?: boolean; | ||
| mfa_configuration?: 'NONE' | 'OPTIONAL' | 'REQUIRED'; | ||
| mfa_methods?: ('SMS' | 'TOTP')[]; | ||
| mfa_methods?: ('SMS' | 'TOTP' | 'EMAIL')[]; | ||
| groups?: { | ||
| [k: string]: AmplifyUserGroupConfig; | ||
| }[]; | ||
|
|
@@ -291,10 +295,6 @@ export interface AmplifyUserGroupConfig { | |
| * via the `definition` "amazon_location_service_config". | ||
| */ | ||
| export interface AmazonLocationServiceConfig { | ||
| /** | ||
| * Map resource name | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * Map style | ||
| */ | ||
|
|
||
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 👍