@aws-amplify/auth 6.5.6-unstable.caf00e2.0 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/cjs/common/AuthErrorStrings.js +2 -2
  2. package/dist/cjs/common/AuthErrorStrings.js.map +1 -1
  3. package/dist/cjs/providers/cognito/apis/confirmSignIn.js +2 -2
  4. package/dist/cjs/providers/cognito/apis/confirmSignIn.js.map +1 -1
  5. package/dist/cjs/providers/cognito/apis/updateMFAPreference.js +2 -1
  6. package/dist/cjs/providers/cognito/apis/updateMFAPreference.js.map +1 -1
  7. package/dist/cjs/providers/cognito/utils/signInHelpers.js +189 -130
  8. package/dist/cjs/providers/cognito/utils/signInHelpers.js.map +1 -1
  9. package/dist/esm/common/AuthErrorStrings.mjs +2 -2
  10. package/dist/esm/common/AuthErrorStrings.mjs.map +1 -1
  11. package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/types/sdk.d.ts +24 -3
  12. package/dist/esm/providers/cognito/apis/confirmSignIn.mjs +2 -2
  13. package/dist/esm/providers/cognito/apis/confirmSignIn.mjs.map +1 -1
  14. package/dist/esm/providers/cognito/apis/updateMFAPreference.mjs +2 -1
  15. package/dist/esm/providers/cognito/apis/updateMFAPreference.mjs.map +1 -1
  16. package/dist/esm/providers/cognito/types/inputs.d.ts +1 -0
  17. package/dist/esm/providers/cognito/utils/signInHelpers.d.ts +4 -3
  18. package/dist/esm/providers/cognito/utils/signInHelpers.mjs +187 -127
  19. package/dist/esm/providers/cognito/utils/signInHelpers.mjs.map +1 -1
  20. package/dist/esm/types/models.d.ts +44 -2
  21. package/package.json +104 -104
  22. package/src/common/AuthErrorStrings.ts +4 -2
  23. package/src/foundation/factories/serviceClients/cognitoIdentityProvider/types/sdk.ts +23 -1
  24. package/src/providers/cognito/apis/confirmSignIn.ts +2 -2
  25. package/src/providers/cognito/apis/updateMFAPreference.ts +2 -1
  26. package/src/providers/cognito/types/inputs.ts +1 -0
  27. package/src/providers/cognito/utils/signInHelpers.ts +246 -166
  28. package/src/types/models.ts +48 -1
@@ -47,8 +47,8 @@ exports.validationErrorMap = {
47
47
  recoverySuggestion: 'Do not include a password in your signIn call.',
48
48
  },
49
49
  [validation_1.AuthValidationErrorCode.IncorrectMFAMethod]: {
50
- message: 'Incorrect MFA method was chosen. It should be either SMS or TOTP',
51
- recoverySuggestion: 'Try to pass TOTP or SMS as the challengeResponse',
50
+ message: 'Incorrect MFA method was chosen. It should be either SMS, TOTP, or EMAIL',
51
+ recoverySuggestion: 'Try to pass SMS, TOTP, or EMAIL as the challengeResponse',
52
52
  },
53
53
  [validation_1.AuthValidationErrorCode.EmptyVerifyTOTPSetupCode]: {
54
54
  message: 'code is required to verifyTotpSetup',
@@ -1 +1 @@
1
- {"version":3,"file":"AuthErrorStrings.js","sources":["../../../src/common/AuthErrorStrings.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.AuthErrorCodes = exports.AuthErrorStrings = exports.validationErrorMap = void 0;\nconst validation_1 = require(\"../errors/types/validation\");\nexports.validationErrorMap = {\n [validation_1.AuthValidationErrorCode.EmptyChallengeResponse]: {\n message: 'challengeResponse is required to confirmSignIn',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmResetPasswordUsername]: {\n message: 'username is required to confirmResetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmSignUpCode]: {\n message: 'code is required to confirmSignUp',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmSignUpUsername]: {\n message: 'username is required to confirmSignUp',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmResetPasswordConfirmationCode]: {\n message: 'confirmationCode is required to confirmResetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmResetPasswordNewPassword]: {\n message: 'newPassword is required to confirmResetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyResendSignUpCodeUsername]: {\n message: 'username is required to confirmSignUp',\n },\n [validation_1.AuthValidationErrorCode.EmptyResetPasswordUsername]: {\n message: 'username is required to resetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptySignInPassword]: {\n message: 'password is required to signIn',\n },\n [validation_1.AuthValidationErrorCode.EmptySignInUsername]: {\n message: 'username is required to signIn',\n },\n [validation_1.AuthValidationErrorCode.EmptySignUpPassword]: {\n message: 'password is required to signUp',\n },\n [validation_1.AuthValidationErrorCode.EmptySignUpUsername]: {\n message: 'username is required to signUp',\n },\n [validation_1.AuthValidationErrorCode.CustomAuthSignInPassword]: {\n message: 'A password is not needed when signing in with CUSTOM_WITHOUT_SRP',\n recoverySuggestion: 'Do not include a password in your signIn call.',\n },\n [validation_1.AuthValidationErrorCode.IncorrectMFAMethod]: {\n message: 'Incorrect MFA method was chosen. It should be either SMS or TOTP',\n recoverySuggestion: 'Try to pass TOTP or SMS as the challengeResponse',\n },\n [validation_1.AuthValidationErrorCode.EmptyVerifyTOTPSetupCode]: {\n message: 'code is required to verifyTotpSetup',\n },\n [validation_1.AuthValidationErrorCode.EmptyUpdatePassword]: {\n message: 'oldPassword and newPassword are required to changePassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmUserAttributeCode]: {\n message: 'confirmation code is required to confirmUserAttribute',\n },\n};\n// TODO: delete this code when the Auth class is removed.\nvar AuthErrorStrings;\n(function (AuthErrorStrings) {\n AuthErrorStrings[\"DEFAULT_MSG\"] = \"Authentication Error\";\n AuthErrorStrings[\"EMPTY_EMAIL\"] = \"Email cannot be empty\";\n AuthErrorStrings[\"EMPTY_PHONE\"] = \"Phone number cannot be empty\";\n AuthErrorStrings[\"EMPTY_USERNAME\"] = \"Username cannot be empty\";\n AuthErrorStrings[\"INVALID_USERNAME\"] = \"The username should either be a string or one of the sign in types\";\n AuthErrorStrings[\"EMPTY_PASSWORD\"] = \"Password cannot be empty\";\n AuthErrorStrings[\"EMPTY_CODE\"] = \"Confirmation code cannot be empty\";\n AuthErrorStrings[\"SIGN_UP_ERROR\"] = \"Error creating account\";\n AuthErrorStrings[\"NO_MFA\"] = \"No valid MFA method provided\";\n AuthErrorStrings[\"INVALID_MFA\"] = \"Invalid MFA type\";\n AuthErrorStrings[\"EMPTY_CHALLENGE\"] = \"Challenge response cannot be empty\";\n AuthErrorStrings[\"NO_USER_SESSION\"] = \"Failed to get the session because the user is empty\";\n AuthErrorStrings[\"NETWORK_ERROR\"] = \"Network Error\";\n AuthErrorStrings[\"DEVICE_CONFIG\"] = \"Device tracking has not been configured in this User Pool\";\n AuthErrorStrings[\"AUTOSIGNIN_ERROR\"] = \"Please use your credentials to sign in\";\n AuthErrorStrings[\"OAUTH_ERROR\"] = \"Couldn't finish OAuth flow, check your User Pool HostedUI settings\";\n})(AuthErrorStrings = exports.AuthErrorStrings || (exports.AuthErrorStrings = {}));\nvar AuthErrorCodes;\n(function (AuthErrorCodes) {\n AuthErrorCodes[\"SignInException\"] = \"SignInException\";\n AuthErrorCodes[\"OAuthSignInError\"] = \"OAuthSignInException\";\n})(AuthErrorCodes = exports.AuthErrorCodes || (exports.AuthErrorCodes = {}));\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACxF,MAAM,YAAY,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC3D,OAAO,CAAC,kBAAkB,GAAG;AAC7B,IAAI,CAAC,YAAY,CAAC,uBAAuB,CAAC,sBAAsB,GAAG;AACnE,QAAQ,OAAO,EAAE,gDAAgD;AACjE,KAAK;AACL,IAAI,CAAC,YAAY,CAAC,uBAAuB,CAAC,iCAAiC,GAAG;AAC9E,QA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,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AACxD,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,2DAA2D,CAAC;AACpG,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,wCAAwC,CAAC;AACpF,IAAI,gBAAgB,CAAC,aAAa,CAAC,GAAG,oEAAoE,CAAC;AAC3G,CAAC,EAAqB,OAAO,CAAC,gBAAgB,KAAK,OAAO,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAC;AAEnF,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;AAC1D,IAAI,cAAc,CAAC,kBAAkB,CAAC,GAAG,sBAAsB,CAAC;AAChE,CAAC,EAAmB,OAAO,CAAC,cAAc,KAAK,OAAO,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC;;"}
1
+ {"version":3,"file":"AuthErrorStrings.js","sources":["../../../src/common/AuthErrorStrings.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.AuthErrorCodes = exports.AuthErrorStrings = exports.validationErrorMap = void 0;\nconst validation_1 = require(\"../errors/types/validation\");\nexports.validationErrorMap = {\n [validation_1.AuthValidationErrorCode.EmptyChallengeResponse]: {\n message: 'challengeResponse is required to confirmSignIn',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmResetPasswordUsername]: {\n message: 'username is required to confirmResetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmSignUpCode]: {\n message: 'code is required to confirmSignUp',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmSignUpUsername]: {\n message: 'username is required to confirmSignUp',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmResetPasswordConfirmationCode]: {\n message: 'confirmationCode is required to confirmResetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmResetPasswordNewPassword]: {\n message: 'newPassword is required to confirmResetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyResendSignUpCodeUsername]: {\n message: 'username is required to confirmSignUp',\n },\n [validation_1.AuthValidationErrorCode.EmptyResetPasswordUsername]: {\n message: 'username is required to resetPassword',\n },\n [validation_1.AuthValidationErrorCode.EmptySignInPassword]: {\n message: 'password is required to signIn',\n },\n [validation_1.AuthValidationErrorCode.EmptySignInUsername]: {\n message: 'username is required to signIn',\n },\n [validation_1.AuthValidationErrorCode.EmptySignUpPassword]: {\n message: 'password is required to signUp',\n },\n [validation_1.AuthValidationErrorCode.EmptySignUpUsername]: {\n message: 'username is required to signUp',\n },\n [validation_1.AuthValidationErrorCode.CustomAuthSignInPassword]: {\n message: 'A password is not needed when signing in with CUSTOM_WITHOUT_SRP',\n recoverySuggestion: 'Do not include a password in your signIn call.',\n },\n [validation_1.AuthValidationErrorCode.IncorrectMFAMethod]: {\n message: 'Incorrect MFA method was chosen. It should be either SMS, TOTP, or EMAIL',\n recoverySuggestion: 'Try to pass SMS, TOTP, or EMAIL as the challengeResponse',\n },\n [validation_1.AuthValidationErrorCode.EmptyVerifyTOTPSetupCode]: {\n message: 'code is required to verifyTotpSetup',\n },\n [validation_1.AuthValidationErrorCode.EmptyUpdatePassword]: {\n message: 'oldPassword and newPassword are required to changePassword',\n },\n [validation_1.AuthValidationErrorCode.EmptyConfirmUserAttributeCode]: {\n message: 'confirmation code is required to confirmUserAttribute',\n },\n};\n// TODO: delete this code when the Auth class is removed.\nvar AuthErrorStrings;\n(function (AuthErrorStrings) {\n AuthErrorStrings[\"DEFAULT_MSG\"] = \"Authentication Error\";\n AuthErrorStrings[\"EMPTY_EMAIL\"] = \"Email cannot be empty\";\n AuthErrorStrings[\"EMPTY_PHONE\"] = \"Phone number cannot be empty\";\n AuthErrorStrings[\"EMPTY_USERNAME\"] = \"Username cannot be empty\";\n AuthErrorStrings[\"INVALID_USERNAME\"] = \"The username should either be a string or one of the sign in types\";\n AuthErrorStrings[\"EMPTY_PASSWORD\"] = \"Password cannot be empty\";\n AuthErrorStrings[\"EMPTY_CODE\"] = \"Confirmation code cannot be empty\";\n AuthErrorStrings[\"SIGN_UP_ERROR\"] = \"Error creating account\";\n AuthErrorStrings[\"NO_MFA\"] = \"No valid MFA method provided\";\n AuthErrorStrings[\"INVALID_MFA\"] = \"Invalid MFA type\";\n AuthErrorStrings[\"EMPTY_CHALLENGE\"] = \"Challenge response cannot be empty\";\n AuthErrorStrings[\"NO_USER_SESSION\"] = \"Failed to get the session because the user is empty\";\n AuthErrorStrings[\"NETWORK_ERROR\"] = \"Network Error\";\n AuthErrorStrings[\"DEVICE_CONFIG\"] = \"Device tracking has not been configured in this User Pool\";\n AuthErrorStrings[\"AUTOSIGNIN_ERROR\"] = \"Please use your credentials to sign in\";\n AuthErrorStrings[\"OAUTH_ERROR\"] = \"Couldn't finish OAuth flow, check your User Pool HostedUI settings\";\n})(AuthErrorStrings = exports.AuthErrorStrings || (exports.AuthErrorStrings = {}));\nvar AuthErrorCodes;\n(function (AuthErrorCodes) {\n AuthErrorCodes[\"SignInException\"] = \"SignInException\";\n AuthErrorCodes[\"OAuthSignInError\"] = \"OAuthSignInException\";\n})(AuthErrorCodes = exports.AuthErrorCodes || (exports.AuthErrorCodes = {}));\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACxF,MAAM,YAAY,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC3D,OAAO,CAAC,kBAAkB,GAAG;AAC7B,IAAI,CAAC,YAAY,CAAC,uBAAuB,CAAC,sBAAsB,GAAG;AACnE,QAAQ,OAAO,EAAE,gDAAgD;AACjE,KAA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,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,qDAAqD,CAAC;AAChG,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AACxD,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,2DAA2D,CAAC;AACpG,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,wCAAwC,CAAC;AACpF,IAAI,gBAAgB,CAAC,aAAa,CAAC,GAAG,oEAAoE,CAAC;AAC3G,CAAC,EAAqB,OAAO,CAAC,gBAAgB,KAAK,OAAO,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAC;AAEnF,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;AAC1D,IAAI,cAAc,CAAC,kBAAkB,CAAC,GAAG,sBAAsB,CAAC;AAChE,CAAC,EAAmB,OAAO,CAAC,cAAc,KAAK,OAAO,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC;;"}
@@ -43,8 +43,8 @@ async function confirmSignIn(input) {
43
43
  throw new AuthError_1.AuthError({
44
44
  name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
45
45
  message: `
46
- An error occurred during the sign in process.
47
-
46
+ An error occurred during the sign in process.
47
+
48
48
  This most likely occurred due to:
49
49
  1. signIn was not called before confirmSignIn.
50
50
  2. signIn threw an exception.
@@ -1 +1 @@
1
- {"version":3,"file":"confirmSignIn.js","sources":["../../../../../src/providers/cognito/apis/confirmSignIn.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.confirmSignIn = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst signInStore_1 = require(\"../utils/signInStore\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst AuthErrorStrings_1 = require(\"../../../common/AuthErrorStrings\");\nconst cacheTokens_1 = require(\"../tokenProvider/cacheTokens\");\nconst tokenProvider_1 = require(\"../tokenProvider\");\nconst dispatchSignedInHubEvent_1 = require(\"../utils/dispatchSignedInHubEvent\");\n/**\n * Continues or completes the sign in process when required by the initial call to `signIn`.\n *\n * @param input - The ConfirmSignInInput object\n * @returns ConfirmSignInOutput\n * @throws -{@link VerifySoftwareTokenException }:\n * Thrown due to an invalid MFA token.\n * @throws -{@link RespondToAuthChallengeException }:\n * Thrown due to an invalid auth challenge response.\n * @throws -{@link AssociateSoftwareTokenException}:\n * Thrown due to a service error during the MFA setup process.\n * @throws -{@link AuthValidationErrorCode }:\n * Thrown when `challengeResponse` is not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function confirmSignIn(input) {\n const { challengeResponse, options } = input;\n const { username, challengeName, signInSession, signInDetails } = signInStore_1.signInStore.getState();\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const clientMetaData = options?.clientMetadata;\n (0, assertValidationError_1.assertValidationError)(!!challengeResponse, validation_1.AuthValidationErrorCode.EmptyChallengeResponse);\n if (!username || !challengeName || !signInSession)\n // TODO: remove this error message for production apps\n throw new AuthError_1.AuthError({\n name: AuthErrorStrings_1.AuthErrorCodes.SignInException,\n message: `\n\t\t\tAn error occurred during the sign in process. \n\t\t\t\n\t\t\tThis most likely occurred due to:\n\t\t\t1. signIn was not called before confirmSignIn.\n\t\t\t2. signIn threw an exception.\n\t\t\t3. page was refreshed during the sign in flow.\n\t\t\t`,\n recoverySuggestion: 'Make sure a successful call to signIn is made before calling confirmSignIn' +\n 'and that the page is not refreshed until the sign in process is done.',\n });\n try {\n const { Session, ChallengeName: handledChallengeName, AuthenticationResult, ChallengeParameters: handledChallengeParameters, } = await (0, signInHelpers_1.handleChallengeName)(username, challengeName, signInSession, challengeResponse, authConfig, tokenProvider_1.tokenOrchestrator, clientMetaData, options);\n // sets up local state used during the sign-in process\n (0, signInStore_1.setActiveSignInState)({\n signInSession: Session,\n username,\n challengeName: handledChallengeName,\n signInDetails,\n });\n if (AuthenticationResult) {\n (0, signInStore_1.cleanActiveSignInState)();\n await (0, cacheTokens_1.cacheCognitoTokens)({\n username,\n ...AuthenticationResult,\n NewDeviceMetadata: await (0, signInHelpers_1.getNewDeviceMetadata)({\n userPoolId: authConfig.userPoolId,\n userPoolEndpoint: authConfig.userPoolEndpoint,\n newDeviceMetadata: AuthenticationResult.NewDeviceMetadata,\n accessToken: AuthenticationResult.AccessToken,\n }),\n signInDetails,\n });\n await (0, dispatchSignedInHubEvent_1.dispatchSignedInHubEvent)();\n return {\n isSignedIn: true,\n nextStep: { signInStep: 'DONE' },\n };\n }\n return (0, signInHelpers_1.getSignInResult)({\n challengeName: handledChallengeName,\n challengeParameters: handledChallengeParameters,\n });\n }\n catch (error) {\n (0, assertServiceError_1.assertServiceError)(error);\n const result = (0, signInHelpers_1.getSignInResultFromError)(error.name);\n if (result)\n return result;\n throw error;\n }\n}\nexports.confirmSignIn = confirmSignIn;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,aAAa,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACtD,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC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AC,CAAC;AACf,YAAY,MAAM,CAAC,CAAC,EAAE,0BAA0B,CAAC,wBAAwB,GAAG,CAAC;AAC7E,YAAY,OAAO;AACnB,gBAAgB,UAAU,EAAE,IAAI;AAChC,gBAAgB,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE;AAChD,aAAa,CAAC;AACd,SAAS;AACT,QAAQ,OAAO,CAAC,CAAC,EAAE,eAAe,CAAC,eAAe,EAAE;AACpD,YAAY,aAAa,EAAE,oBAAoB;AAC/C,YAAY,mBAAmB,EAAE,0BAA0B;AAC3D,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,oBAAoB,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC5D,QAAQ,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,wBAAwB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AACjF,QAAQ,IAAI,MAAM;AAClB,YAAY,OAAO,MAAM,CAAC;AAC1B,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
1
+ {"version":3,"file":"confirmSignIn.js","sources":["../../../../../src/providers/cognito/apis/confirmSignIn.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.confirmSignIn = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst signInStore_1 = require(\"../utils/signInStore\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst AuthErrorStrings_1 = require(\"../../../common/AuthErrorStrings\");\nconst cacheTokens_1 = require(\"../tokenProvider/cacheTokens\");\nconst tokenProvider_1 = require(\"../tokenProvider\");\nconst dispatchSignedInHubEvent_1 = require(\"../utils/dispatchSignedInHubEvent\");\n/**\n * Continues or completes the sign in process when required by the initial call to `signIn`.\n *\n * @param input - The ConfirmSignInInput object\n * @returns ConfirmSignInOutput\n * @throws -{@link VerifySoftwareTokenException }:\n * Thrown due to an invalid MFA token.\n * @throws -{@link RespondToAuthChallengeException }:\n * Thrown due to an invalid auth challenge response.\n * @throws -{@link AssociateSoftwareTokenException}:\n * Thrown due to a service error during the MFA setup process.\n * @throws -{@link AuthValidationErrorCode }:\n * Thrown when `challengeResponse` is not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function confirmSignIn(input) {\n const { challengeResponse, options } = input;\n const { username, challengeName, signInSession, signInDetails } = signInStore_1.signInStore.getState();\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const clientMetaData = options?.clientMetadata;\n (0, assertValidationError_1.assertValidationError)(!!challengeResponse, validation_1.AuthValidationErrorCode.EmptyChallengeResponse);\n if (!username || !challengeName || !signInSession)\n // TODO: remove this error message for production apps\n throw new AuthError_1.AuthError({\n name: AuthErrorStrings_1.AuthErrorCodes.SignInException,\n message: `\n\t\t\tAn error occurred during the sign in process.\n\n\t\t\tThis most likely occurred due to:\n\t\t\t1. signIn was not called before confirmSignIn.\n\t\t\t2. signIn threw an exception.\n\t\t\t3. page was refreshed during the sign in flow.\n\t\t\t`,\n recoverySuggestion: 'Make sure a successful call to signIn is made before calling confirmSignIn' +\n 'and that the page is not refreshed until the sign in process is done.',\n });\n try {\n const { Session, ChallengeName: handledChallengeName, AuthenticationResult, ChallengeParameters: handledChallengeParameters, } = await (0, signInHelpers_1.handleChallengeName)(username, challengeName, signInSession, challengeResponse, authConfig, tokenProvider_1.tokenOrchestrator, clientMetaData, options);\n // sets up local state used during the sign-in process\n (0, signInStore_1.setActiveSignInState)({\n signInSession: Session,\n username,\n challengeName: handledChallengeName,\n signInDetails,\n });\n if (AuthenticationResult) {\n (0, signInStore_1.cleanActiveSignInState)();\n await (0, cacheTokens_1.cacheCognitoTokens)({\n username,\n ...AuthenticationResult,\n NewDeviceMetadata: await (0, signInHelpers_1.getNewDeviceMetadata)({\n userPoolId: authConfig.userPoolId,\n userPoolEndpoint: authConfig.userPoolEndpoint,\n newDeviceMetadata: AuthenticationResult.NewDeviceMetadata,\n accessToken: AuthenticationResult.AccessToken,\n }),\n signInDetails,\n });\n await (0, dispatchSignedInHubEvent_1.dispatchSignedInHubEvent)();\n return {\n isSignedIn: true,\n nextStep: { signInStep: 'DONE' },\n };\n }\n return (0, signInHelpers_1.getSignInResult)({\n challengeName: handledChallengeName,\n challengeParameters: handledChallengeParameters,\n });\n }\n catch (error) {\n (0, assertServiceError_1.assertServiceError)(error);\n const result = (0, signInHelpers_1.getSignInResultFromError)(error.name);\n if (result)\n return result;\n throw error;\n }\n}\nexports.confirmSignIn = confirmSignIn;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,aAAa,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACtD,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC1D,MAAM,oBAAoB,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AACjF,MAAM,uBAAuB,GAAG,OAAO,CAA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AAE,EAAE,UAAU,EAAE,MAAM,EAAE;AAChD,aAAa,CAAC;AACd,SAAS;AACT,QAAQ,OAAO,CAAC,CAAC,EAAE,eAAe,CAAC,eAAe,EAAE;AACpD,YAAY,aAAa,EAAE,oBAAoB;AAC/C,YAAY,mBAAmB,EAAE,0BAA0B;AAC3D,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,oBAAoB,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC5D,QAAQ,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,wBAAwB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AACjF,QAAQ,IAAI,MAAM;AAClB,YAAY,OAAO,MAAM,CAAC;AAC1B,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
@@ -19,7 +19,7 @@ const factories_1 = require("../factories");
19
19
  * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.
20
20
  */
21
21
  async function updateMFAPreference(input) {
22
- const { sms, totp } = input;
22
+ const { sms, totp, email } = input;
23
23
  const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;
24
24
  (0, utils_1.assertTokenProviderConfig)(authConfig);
25
25
  const { userPoolEndpoint, userPoolId } = authConfig;
@@ -37,6 +37,7 @@ async function updateMFAPreference(input) {
37
37
  AccessToken: tokens.accessToken.toString(),
38
38
  SMSMfaSettings: getMFASettings(sms),
39
39
  SoftwareTokenMfaSettings: getMFASettings(totp),
40
+ EmailMfaSettings: getMFASettings(email),
40
41
  });
41
42
  }
42
43
  exports.updateMFAPreference = updateMFAPreference;
@@ -1 +1 @@
1
- {"version":3,"file":"updateMFAPreference.js","sources":["../../../../../src/providers/cognito/apis/updateMFAPreference.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getMFASettings = exports.updateMFAPreference = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"../utils/types\");\nconst utils_2 = require(\"../../../utils\");\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst factories_1 = require(\"../factories\");\n/**\n * Updates the MFA preference of the user.\n *\n * @param input - The UpdateMFAPreferenceInput object.\n * @throws -{@link SetUserMFAPreferenceException } - Service error thrown when the MFA preference cannot be updated.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function updateMFAPreference(input) {\n const { sms, totp } = input;\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const { userPoolEndpoint, userPoolId } = authConfig;\n const { tokens } = await (0, core_1.fetchAuthSession)({ forceRefresh: false });\n (0, types_1.assertAuthTokens)(tokens);\n const setUserMFAPreference = (0, cognitoIdentityProvider_1.createSetUserMFAPreferenceClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n await setUserMFAPreference({\n region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),\n userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.UpdateMFAPreference),\n }, {\n AccessToken: tokens.accessToken.toString(),\n SMSMfaSettings: getMFASettings(sms),\n SoftwareTokenMfaSettings: getMFASettings(totp),\n });\n}\nexports.updateMFAPreference = updateMFAPreference;\nfunction getMFASettings(mfaPreference) {\n if (mfaPreference === 'DISABLED') {\n return {\n Enabled: false,\n };\n }\n else if (mfaPreference === 'PREFERRED') {\n return {\n Enabled: true,\n PreferredMfa: true,\n };\n }\n else if (mfaPreference === 'ENABLED') {\n return {\n Enabled: true,\n };\n }\n else if (mfaPreference === 'NO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V,KAAK;AACL,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
1
+ {"version":3,"file":"updateMFAPreference.js","sources":["../../../../../src/providers/cognito/apis/updateMFAPreference.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getMFASettings = exports.updateMFAPreference = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"../utils/types\");\nconst utils_2 = require(\"../../../utils\");\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst factories_1 = require(\"../factories\");\n/**\n * Updates the MFA preference of the user.\n *\n * @param input - The UpdateMFAPreferenceInput object.\n * @throws -{@link SetUserMFAPreferenceException } - Service error thrown when the MFA preference cannot be updated.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function updateMFAPreference(input) {\n const { sms, totp, email } = input;\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const { userPoolEndpoint, userPoolId } = authConfig;\n const { tokens } = await (0, core_1.fetchAuthSession)({ forceRefresh: false });\n (0, types_1.assertAuthTokens)(tokens);\n const setUserMFAPreference = (0, cognitoIdentityProvider_1.createSetUserMFAPreferenceClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n await setUserMFAPreference({\n region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),\n userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.UpdateMFAPreference),\n }, {\n AccessToken: tokens.accessToken.toString(),\n SMSMfaSettings: getMFASettings(sms),\n SoftwareTokenMfaSettings: getMFASettings(totp),\n EmailMfaSettings: getMFASettings(email),\n });\n}\nexports.updateMFAPreference = updateMFAPreference;\nfunction getMFASettings(mfaPreference) {\n if (mfaPreference === 'DISABLED') {\n return {\n Enabled: false,\n };\n }\n else if (mfaPreference === 'PREFERRED') {\n return {\n Enabled: true,\n PreferredMfa: true,\n };\n }\n else if (mfaPreference === 'ENABLED') {\n return {\n Enabled: true,\n };\n }\n else if (mfaPreference === 'NOT_PREFERRED') {\n return {\n Enabled: true,\n PreferredMfa: false,\n };\n }\n}\nexports.getMFASettings = getMFASettings;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACzD,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,yBAAyB,GAAG,OAAO,CAAC,sEAAsE,CAAC,CAAC;AAClH,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,mBAAmB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;AACvC,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AAChE,IAAI,IAAI,OAAO,CAAC,yBAAyB,EAAE,UAAU,CA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zB,YAAY,YAAY,EAAE,IAAI;AAC9B,SAAS,CAAC;AACV,KAAK;AACL,SAAS,IAAI,aAAa,KAAK,SAAS,EAAE;AAC1C,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,IAAI;AACzB,SAAS,CAAC;AACV,KAAK;AACL,SAAS,IAAI,aAAa,KAAK,eAAe,EAAE;AAChD,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,IAAI;AACzB,YAAY,YAAY,EAAE,KAAK;AAC/B,SAAS,CAAC;AACV,KAAK;AACL,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
@@ -3,7 +3,7 @@
3
3
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getActiveSignInUsername = exports.setActiveSignInUsername = exports.retryOnResourceNotFoundException = exports.getNewDeviceMetadata = exports.assertUserNotAuthenticated = exports.isMFATypeEnabled = exports.parseMFATypes = exports.getMFATypes = exports.getMFAType = exports.mapMfaType = exports.handleChallengeName = exports.createAttributes = exports.parseAttributes = exports.getSignInResultFromError = exports.getTOTPSetupDetails = exports.getSignInResult = exports.handlePasswordVerifierChallenge = exports.handleCustomSRPAuthFlow = exports.handleCustomAuthFlowWithoutSRP = exports.handleUserSRPAuthFlow = exports.handleUserPasswordAuthFlow = exports.handleCompleteNewPasswordChallenge = exports.handleSoftwareTokenMFAChallenge = exports.handleSMSMFAChallenge = exports.handleSelectMFATypeChallenge = exports.handleMFASetupChallenge = exports.handleCustomChallenge = void 0;
6
+ exports.handleMFAChallenge = exports.getActiveSignInUsername = exports.setActiveSignInUsername = exports.retryOnResourceNotFoundException = exports.getNewDeviceMetadata = exports.assertUserNotAuthenticated = exports.getAllowedMfaSetupTypes = exports.parseMFATypes = exports.getMFATypes = exports.getMFAType = exports.mapMfaType = exports.handleChallengeName = exports.createAttributes = exports.parseAttributes = exports.getSignInResultFromError = exports.getTOTPSetupDetails = exports.getSignInResult = exports.handlePasswordVerifierChallenge = exports.handleCustomSRPAuthFlow = exports.handleCustomAuthFlowWithoutSRP = exports.handleUserSRPAuthFlow = exports.handleUserPasswordAuthFlow = exports.handleCompleteNewPasswordChallenge = exports.handleSelectMFATypeChallenge = exports.handleMFASetupChallenge = exports.handleCustomChallenge = void 0;
7
7
  const core_1 = require("@aws-amplify/core");
8
8
  const utils_1 = require("@aws-amplify/core/internals/utils");
9
9
  const AuthError_1 = require("../../../errors/AuthError");
@@ -69,44 +69,97 @@ async function handleCustomChallenge({ challengeResponse, clientMetadata, sessio
69
69
  exports.handleCustomChallenge = handleCustomChallenge;
70
70
  async function handleMFASetupChallenge({ challengeResponse, username, clientMetadata, session, deviceName, config, }) {
71
71
  const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
72
+ if (challengeResponse === 'EMAIL') {
73
+ return {
74
+ ChallengeName: 'MFA_SETUP',
75
+ Session: session,
76
+ ChallengeParameters: {
77
+ MFAS_CAN_SETUP: '["EMAIL_OTP"]',
78
+ },
79
+ $metadata: {},
80
+ };
81
+ }
82
+ if (challengeResponse === 'TOTP') {
83
+ return {
84
+ ChallengeName: 'MFA_SETUP',
85
+ Session: session,
86
+ ChallengeParameters: {
87
+ MFAS_CAN_SETUP: '["SOFTWARE_TOKEN_MFA"]',
88
+ },
89
+ $metadata: {},
90
+ };
91
+ }
72
92
  const challengeResponses = {
73
93
  USERNAME: username,
74
94
  };
75
- const verifySoftwareToken = (0, cognitoIdentityProvider_1.createVerifySoftwareTokenClient)({
76
- endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
77
- endpointOverride: userPoolEndpoint,
78
- }),
79
- });
80
- const { Session } = await verifySoftwareToken({
81
- region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
82
- userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
83
- }, {
84
- UserCode: challengeResponse,
85
- Session: session,
86
- FriendlyDeviceName: deviceName,
87
- });
88
- signInStore_1.signInStore.dispatch({
89
- type: 'SET_SIGN_IN_SESSION',
90
- value: Session,
91
- });
92
- const jsonReq = {
93
- ChallengeName: 'MFA_SETUP',
94
- ChallengeResponses: challengeResponses,
95
- Session,
96
- ClientMetadata: clientMetadata,
97
- ClientId: userPoolClientId,
98
- };
99
- const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
100
- endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
101
- endpointOverride: userPoolEndpoint,
102
- }),
95
+ const isTOTPCode = /^\d+$/.test(challengeResponse);
96
+ if (isTOTPCode) {
97
+ const verifySoftwareToken = (0, cognitoIdentityProvider_1.createVerifySoftwareTokenClient)({
98
+ endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
99
+ endpointOverride: userPoolEndpoint,
100
+ }),
101
+ });
102
+ const { Session } = await verifySoftwareToken({
103
+ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
104
+ userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
105
+ }, {
106
+ UserCode: challengeResponse,
107
+ Session: session,
108
+ FriendlyDeviceName: deviceName,
109
+ });
110
+ signInStore_1.signInStore.dispatch({
111
+ type: 'SET_SIGN_IN_SESSION',
112
+ value: Session,
113
+ });
114
+ const jsonReq = {
115
+ ChallengeName: 'MFA_SETUP',
116
+ ChallengeResponses: challengeResponses,
117
+ Session,
118
+ ClientMetadata: clientMetadata,
119
+ ClientId: userPoolClientId,
120
+ };
121
+ const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
122
+ endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
123
+ endpointOverride: userPoolEndpoint,
124
+ }),
125
+ });
126
+ return respondToAuthChallenge({
127
+ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
128
+ userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
129
+ }, jsonReq);
130
+ }
131
+ const isEmail = challengeResponse.includes('@');
132
+ if (isEmail) {
133
+ challengeResponses.EMAIL = challengeResponse;
134
+ const jsonReq = {
135
+ ChallengeName: 'MFA_SETUP',
136
+ ChallengeResponses: challengeResponses,
137
+ Session: session,
138
+ ClientMetadata: clientMetadata,
139
+ ClientId: userPoolClientId,
140
+ };
141
+ const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
142
+ endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
143
+ endpointOverride: userPoolEndpoint,
144
+ }),
145
+ });
146
+ return respondToAuthChallenge({
147
+ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
148
+ userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
149
+ }, jsonReq);
150
+ }
151
+ throw new AuthError_1.AuthError({
152
+ name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
153
+ message: `Cannot proceed with MFA setup using challengeResponse: ${challengeResponse}`,
154
+ recoverySuggestion: 'Try passing "EMAIL", "TOTP", a valid email, or OTP code as the challengeResponse.',
103
155
  });
104
- return respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReq);
105
156
  }
106
157
  exports.handleMFASetupChallenge = handleMFASetupChallenge;
107
158
  async function handleSelectMFATypeChallenge({ challengeResponse, username, clientMetadata, session, config, }) {
108
159
  const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
109
- (0, assertValidationError_1.assertValidationError)(challengeResponse === 'TOTP' || challengeResponse === 'SMS', validation_1.AuthValidationErrorCode.IncorrectMFAMethod);
160
+ (0, assertValidationError_1.assertValidationError)(challengeResponse === 'TOTP' ||
161
+ challengeResponse === 'SMS' ||
162
+ challengeResponse === 'EMAIL', validation_1.AuthValidationErrorCode.IncorrectMFAMethod);
110
163
  const challengeResponses = {
111
164
  USERNAME: username,
112
165
  ANSWER: mapMfaType(challengeResponse),
@@ -135,66 +188,6 @@ async function handleSelectMFATypeChallenge({ challengeResponse, username, clien
135
188
  }, jsonReq);
136
189
  }
137
190
  exports.handleSelectMFATypeChallenge = handleSelectMFATypeChallenge;
138
- async function handleSMSMFAChallenge({ challengeResponse, clientMetadata, session, username, config, }) {
139
- const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
140
- const challengeResponses = {
141
- USERNAME: username,
142
- SMS_MFA_CODE: challengeResponse,
143
- };
144
- const UserContextData = (0, userContextData_1.getUserContextData)({
145
- username,
146
- userPoolId,
147
- userPoolClientId,
148
- });
149
- const jsonReq = {
150
- ChallengeName: 'SMS_MFA',
151
- ChallengeResponses: challengeResponses,
152
- Session: session,
153
- ClientMetadata: clientMetadata,
154
- ClientId: userPoolClientId,
155
- UserContextData,
156
- };
157
- const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
158
- endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
159
- endpointOverride: userPoolEndpoint,
160
- }),
161
- });
162
- return respondToAuthChallenge({
163
- region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
164
- userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
165
- }, jsonReq);
166
- }
167
- exports.handleSMSMFAChallenge = handleSMSMFAChallenge;
168
- async function handleSoftwareTokenMFAChallenge({ challengeResponse, clientMetadata, session, username, config, }) {
169
- const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
170
- const challengeResponses = {
171
- USERNAME: username,
172
- SOFTWARE_TOKEN_MFA_CODE: challengeResponse,
173
- };
174
- const UserContextData = (0, userContextData_1.getUserContextData)({
175
- username,
176
- userPoolId,
177
- userPoolClientId,
178
- });
179
- const jsonReq = {
180
- ChallengeName: 'SOFTWARE_TOKEN_MFA',
181
- ChallengeResponses: challengeResponses,
182
- Session: session,
183
- ClientMetadata: clientMetadata,
184
- ClientId: userPoolClientId,
185
- UserContextData,
186
- };
187
- const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
188
- endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
189
- endpointOverride: userPoolEndpoint,
190
- }),
191
- });
192
- return respondToAuthChallenge({
193
- region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
194
- userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
195
- }, jsonReq);
196
- }
197
- exports.handleSoftwareTokenMFAChallenge = handleSoftwareTokenMFAChallenge;
198
191
  async function handleCompleteNewPasswordChallenge({ challengeResponse, clientMetadata, session, username, requiredAttributes, config, }) {
199
192
  const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
200
193
  const challengeResponses = {
@@ -554,30 +547,52 @@ async function getSignInResult(params) {
554
547
  };
555
548
  case 'MFA_SETUP': {
556
549
  const { signInSession, username } = signInStore_1.signInStore.getState();
557
- if (!isMFATypeEnabled(challengeParameters, 'TOTP'))
558
- throw new AuthError_1.AuthError({
559
- name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
560
- message: `Cannot initiate MFA setup from available types: ${getMFATypes(parseMFATypes(challengeParameters.MFAS_CAN_SETUP))}`,
550
+ const mfaSetupTypes = getMFATypes(parseMFATypes(challengeParameters.MFAS_CAN_SETUP)) || [];
551
+ const allowedMfaSetupTypes = getAllowedMfaSetupTypes(mfaSetupTypes);
552
+ const isTotpMfaSetupAvailable = allowedMfaSetupTypes.includes('TOTP');
553
+ const isEmailMfaSetupAvailable = allowedMfaSetupTypes.includes('EMAIL');
554
+ if (isTotpMfaSetupAvailable && isEmailMfaSetupAvailable) {
555
+ return {
556
+ isSignedIn: false,
557
+ nextStep: {
558
+ signInStep: 'CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION',
559
+ allowedMFATypes: allowedMfaSetupTypes,
560
+ },
561
+ };
562
+ }
563
+ if (isEmailMfaSetupAvailable) {
564
+ return {
565
+ isSignedIn: false,
566
+ nextStep: {
567
+ signInStep: 'CONTINUE_SIGN_IN_WITH_EMAIL_SETUP',
568
+ },
569
+ };
570
+ }
571
+ if (isTotpMfaSetupAvailable) {
572
+ const associateSoftwareToken = (0, cognitoIdentityProvider_1.createAssociateSoftwareTokenClient)({
573
+ endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
574
+ endpointOverride: authConfig.userPoolEndpoint,
575
+ }),
561
576
  });
562
- const associateSoftwareToken = (0, cognitoIdentityProvider_1.createAssociateSoftwareTokenClient)({
563
- endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
564
- endpointOverride: authConfig.userPoolEndpoint,
565
- }),
566
- });
567
- const { Session, SecretCode: secretCode } = await associateSoftwareToken({ region: (0, parsers_1.getRegionFromUserPoolId)(authConfig.userPoolId) }, {
568
- Session: signInSession,
569
- });
570
- signInStore_1.signInStore.dispatch({
571
- type: 'SET_SIGN_IN_SESSION',
572
- value: Session,
577
+ const { Session, SecretCode: secretCode } = await associateSoftwareToken({ region: (0, parsers_1.getRegionFromUserPoolId)(authConfig.userPoolId) }, {
578
+ Session: signInSession,
579
+ });
580
+ signInStore_1.signInStore.dispatch({
581
+ type: 'SET_SIGN_IN_SESSION',
582
+ value: Session,
583
+ });
584
+ return {
585
+ isSignedIn: false,
586
+ nextStep: {
587
+ signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP',
588
+ totpSetupDetails: getTOTPSetupDetails(secretCode, username),
589
+ },
590
+ };
591
+ }
592
+ throw new AuthError_1.AuthError({
593
+ name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
594
+ message: `Cannot initiate MFA setup from available types: ${mfaSetupTypes}`,
573
595
  });
574
- return {
575
- isSignedIn: false,
576
- nextStep: {
577
- signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP',
578
- totpSetupDetails: getTOTPSetupDetails(secretCode, username),
579
- },
580
- };
581
596
  }
582
597
  case 'NEW_PASSWORD_REQUIRED':
583
598
  return {
@@ -613,6 +628,17 @@ async function getSignInResult(params) {
613
628
  signInStep: 'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
614
629
  },
615
630
  };
631
+ case 'EMAIL_OTP':
632
+ return {
633
+ isSignedIn: false,
634
+ nextStep: {
635
+ signInStep: 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE',
636
+ codeDeliveryDetails: {
637
+ deliveryMedium: challengeParameters.CODE_DELIVERY_DELIVERY_MEDIUM,
638
+ destination: challengeParameters.CODE_DELIVERY_DESTINATION,
639
+ },
640
+ },
641
+ };
616
642
  }
617
643
  // TODO: remove this error message for production apps
618
644
  throw new AuthError_1.AuthError({
@@ -669,14 +695,6 @@ async function handleChallengeName(username, challengeName, session, challengeRe
669
695
  const userAttributes = options?.userAttributes;
670
696
  const deviceName = options?.friendlyDeviceName;
671
697
  switch (challengeName) {
672
- case 'SMS_MFA':
673
- return handleSMSMFAChallenge({
674
- challengeResponse,
675
- clientMetadata,
676
- session,
677
- username,
678
- config,
679
- });
680
698
  case 'SELECT_MFA_TYPE':
681
699
  return handleSelectMFATypeChallenge({
682
700
  challengeResponse,
@@ -714,8 +732,11 @@ async function handleChallengeName(username, challengeName, session, challengeRe
714
732
  tokenOrchestrator,
715
733
  },
716
734
  ], username, tokenOrchestrator);
735
+ case 'SMS_MFA':
717
736
  case 'SOFTWARE_TOKEN_MFA':
718
- return handleSoftwareTokenMFAChallenge({
737
+ case 'EMAIL_OTP':
738
+ return handleMFAChallenge({
739
+ challengeName,
719
740
  challengeResponse,
720
741
  clientMetadata,
721
742
  session,
@@ -726,7 +747,7 @@ async function handleChallengeName(username, challengeName, session, challengeRe
726
747
  // TODO: remove this error message for production apps
727
748
  throw new AuthError_1.AuthError({
728
749
  name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
729
- message: `An error occurred during the sign in process.
750
+ message: `An error occurred during the sign in process.
730
751
  ${challengeName} challengeName returned by the underlying service was not addressed.`,
731
752
  });
732
753
  }
@@ -735,6 +756,8 @@ function mapMfaType(mfa) {
735
756
  let mfaType = 'SMS_MFA';
736
757
  if (mfa === 'TOTP')
737
758
  mfaType = 'SOFTWARE_TOKEN_MFA';
759
+ if (mfa === 'EMAIL')
760
+ mfaType = 'EMAIL_OTP';
738
761
  return mfaType;
739
762
  }
740
763
  exports.mapMfaType = mapMfaType;
@@ -743,6 +766,8 @@ function getMFAType(type) {
743
766
  return 'SMS';
744
767
  if (type === 'SOFTWARE_TOKEN_MFA')
745
768
  return 'TOTP';
769
+ if (type === 'EMAIL_OTP')
770
+ return 'EMAIL';
746
771
  // TODO: log warning for unknown MFA type
747
772
  }
748
773
  exports.getMFAType = getMFAType;
@@ -758,14 +783,10 @@ function parseMFATypes(mfa) {
758
783
  return JSON.parse(mfa);
759
784
  }
760
785
  exports.parseMFATypes = parseMFATypes;
761
- function isMFATypeEnabled(challengeParams, mfaType) {
762
- const { MFAS_CAN_SETUP } = challengeParams;
763
- const mfaTypes = getMFATypes(parseMFATypes(MFAS_CAN_SETUP));
764
- if (!mfaTypes)
765
- return false;
766
- return mfaTypes.includes(mfaType);
786
+ function getAllowedMfaSetupTypes(availableMfaSetupTypes) {
787
+ return availableMfaSetupTypes.filter(authMfaType => authMfaType === 'EMAIL' || authMfaType === 'TOTP');
767
788
  }
768
- exports.isMFATypeEnabled = isMFATypeEnabled;
789
+ exports.getAllowedMfaSetupTypes = getAllowedMfaSetupTypes;
769
790
  async function assertUserNotAuthenticated() {
770
791
  let authUser;
771
792
  try {
@@ -863,4 +884,42 @@ function getActiveSignInUsername(username) {
863
884
  return state.username ?? username;
864
885
  }
865
886
  exports.getActiveSignInUsername = getActiveSignInUsername;
887
+ async function handleMFAChallenge({ challengeName, challengeResponse, clientMetadata, session, username, config, }) {
888
+ const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
889
+ const challengeResponses = {
890
+ USERNAME: username,
891
+ };
892
+ if (challengeName === 'EMAIL_OTP') {
893
+ challengeResponses.EMAIL_OTP_CODE = challengeResponse;
894
+ }
895
+ if (challengeName === 'SMS_MFA') {
896
+ challengeResponses.SMS_MFA_CODE = challengeResponse;
897
+ }
898
+ if (challengeName === 'SOFTWARE_TOKEN_MFA') {
899
+ challengeResponses.SOFTWARE_TOKEN_MFA_CODE = challengeResponse;
900
+ }
901
+ const userContextData = (0, userContextData_1.getUserContextData)({
902
+ username,
903
+ userPoolId,
904
+ userPoolClientId,
905
+ });
906
+ const jsonReq = {
907
+ ChallengeName: challengeName,
908
+ ChallengeResponses: challengeResponses,
909
+ Session: session,
910
+ ClientMetadata: clientMetadata,
911
+ ClientId: userPoolClientId,
912
+ UserContextData: userContextData,
913
+ };
914
+ const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
915
+ endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
916
+ endpointOverride: userPoolEndpoint,
917
+ }),
918
+ });
919
+ return respondToAuthChallenge({
920
+ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
921
+ userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
922
+ }, jsonReq);
923
+ }
924
+ exports.handleMFAChallenge = handleMFAChallenge;
866
925
  //# sourceMappingURL=signInHelpers.js.map