Skip to content

Commit

Permalink
fix: MFA types to not require sms settings if turned off (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer authored Apr 16, 2024
1 parent e7817b2 commit 65b516d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-news-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/auth-construct-alpha': patch
---

fix: MFA types to not require sms settings if turned off
23 changes: 17 additions & 6 deletions packages/auth-construct/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,28 @@ export type IdentityProviderProps = {

// @public
export type MFA = {
mode: 'OFF' | 'OPTIONAL' | 'REQUIRED';
} & MFASettings;
mode: 'OFF';
} | ({
mode: 'OPTIONAL' | 'REQUIRED';
} & MFASettings);

// @public
export type MFASettings = {
totp?: boolean;
sms: boolean | {
smsMessage: (code: string) => string;
};
totp?: MFATotpSettings;
sms: MFASmsSettings;
} | {
totp: MFATotpSettings;
sms?: MFASmsSettings;
};

// @public
export type MFASmsSettings = boolean | {
smsMessage: (code: string) => string;
};

// @public
export type MFATotpSettings = boolean;

// @public
export type OidcProviderProps = Omit<aws_cognito.UserPoolIdentityProviderOidcProps, 'userPool' | 'attributeRequestMethod' | 'attributeMapping'> & {
readonly attributeRequestMethod?: 'GET' | 'POST';
Expand Down
2 changes: 2 additions & 0 deletions packages/auth-construct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export {
VerificationEmailWithCode,
VerificationEmailWithLink,
MFA,
MFASmsSettings,
MFATotpSettings,
MFASettings,
PhoneNumberLogin,
TriggerEvent,
Expand Down
72 changes: 40 additions & 32 deletions packages/auth-construct/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,49 @@ export type PhoneNumberLogin =
};

/**
* Configure the MFA types that users can use. Ignored if MFA mode is set to OFF.
* If true, or if a settings object is provided, the MFA token is sent to the user via SMS to their verified phone numbers.
* @see - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-mfa-sms-text-message.html
*/
export type MFASettings = {
/**
* If true, the MFA token is a time-based one time password that is generated by a hardware or software token
* @see - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-mfa-totp.html
* @default false
*/
totp?: boolean;
/**
* If true, or if a settings object is provided, the MFA token is sent to the user via SMS to their verified phone numbers.
* @see - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-mfa-sms-text-message.html
*/
sms:
| boolean
| {
/**
* The SMS message template sent during MFA verification.
* Use the code parameter in the template where Cognito should insert the verification code.
* @default
* smsMessage: (code: string) => `Your authentication code is ${code}.`
*/
smsMessage: (code: string) => string;
};
};
export type MFASmsSettings =
| boolean
| {
/**
* The SMS message template sent during MFA verification.
* Use the code parameter in the template where Cognito should insert the verification code.
* @default
* smsMessage: (code: string) => `Your authentication code is ${code}.`
*/
smsMessage: (code: string) => string;
};
/**
* MFA Settings
* If true, the MFA token is a time-based one time password that is generated by a hardware or software token
* @see - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-mfa-totp.html
*/
export type MFA = {
/**
* Configure whether users can or are required to use multifactor (MFA) to sign in.
* @default - 'OFF'
*/
mode: 'OFF' | 'OPTIONAL' | 'REQUIRED';
} & MFASettings;
export type MFATotpSettings = boolean;
/**
* Configure the MFA types that users can use. At least one of totp or sms is required.
*/
export type MFASettings =
| {
totp?: MFATotpSettings;
sms: MFASmsSettings;
}
| { totp: MFATotpSettings; sms?: MFASmsSettings };

/**
* MFA configuration. MFA settings are required if the mode is either "OPTIONAL" or "REQUIRED"
*/
export type MFA =
| {
/**
* Configure whether users can or are required to use multifactor (MFA) to sign in.
* @default - 'OFF'
*/
mode: 'OFF';
}
| ({
mode: 'OPTIONAL' | 'REQUIRED';
} & MFASettings);
/**
* Properties which all identity providers have
*/
Expand Down

0 comments on commit 65b516d

Please sign in to comment.