@aws-amplify/auth 6.5.0 → 6.5.1-email-mfa-test.b78433a.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.
- package/dist/cjs/common/AuthErrorStrings.js +2 -2
- package/dist/cjs/common/AuthErrorStrings.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js +2 -2
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/updateMFAPreference.js +2 -1
- package/dist/cjs/providers/cognito/apis/updateMFAPreference.js.map +1 -1
- package/dist/cjs/providers/cognito/utils/oauth/getRedirectUrl.js +3 -1
- package/dist/cjs/providers/cognito/utils/oauth/getRedirectUrl.js.map +1 -1
- package/dist/cjs/providers/cognito/utils/signInHelpers.js +183 -130
- package/dist/cjs/providers/cognito/utils/signInHelpers.js.map +1 -1
- package/dist/esm/common/AuthErrorStrings.mjs +2 -2
- package/dist/esm/common/AuthErrorStrings.mjs.map +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/types/sdk.d.ts +24 -3
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs +2 -2
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/updateMFAPreference.mjs +2 -1
- package/dist/esm/providers/cognito/apis/updateMFAPreference.mjs.map +1 -1
- package/dist/esm/providers/cognito/types/inputs.d.ts +1 -0
- package/dist/esm/providers/cognito/utils/oauth/getRedirectUrl.mjs +3 -1
- package/dist/esm/providers/cognito/utils/oauth/getRedirectUrl.mjs.map +1 -1
- package/dist/esm/providers/cognito/utils/signInHelpers.d.ts +4 -3
- package/dist/esm/providers/cognito/utils/signInHelpers.mjs +181 -127
- package/dist/esm/providers/cognito/utils/signInHelpers.mjs.map +1 -1
- package/dist/esm/types/models.d.ts +44 -2
- package/package.json +104 -104
- package/src/common/AuthErrorStrings.ts +4 -2
- package/src/foundation/factories/serviceClients/cognitoIdentityProvider/types/sdk.ts +23 -1
- package/src/providers/cognito/apis/confirmSignIn.ts +2 -2
- package/src/providers/cognito/apis/updateMFAPreference.ts +2 -1
- package/src/providers/cognito/types/inputs.ts +1 -0
- package/src/providers/cognito/utils/oauth/getRedirectUrl.ts +1 -0
- package/src/providers/cognito/utils/signInHelpers.ts +240 -166
- 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
|
|
51
|
-
recoverySuggestion: 'Try to pass TOTP or
|
|
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
|
|
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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C,CAAC;AACzE,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,wBAAwB,CAAC;AACjE,IAAI,gBAAgB,CAAC,QAAQ,CAAC,GAAG,8BAA8B,CAAC;AAChE,IAAI,gBAAgB,CAAC,aAAa,CAAC,GAAG,kBAAkB,CAAC;AACzD,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,oCAAoC,CAAC;AAC/E,IAAI,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
|
|
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,CAAC,6CAA6C,CAAC,CAAC;AACvF,MAAM,YAAY,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AACjE,MAAM,kBAAkB,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AACvE,MAAM,aAAa,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC9D,MAAM,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACpD,MAAM,0BAA0B,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAChF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,aAAa,CAAC,KAAK,EAAE;AACpC,IAAI,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AACjD,IAAI,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,aAAa,CA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 -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 === '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,GAAG,KAAK,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,cA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CAAC,CAAC;AACP,CAAC;AACD,OAAO,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;AAClD,SAAS,cAAc,CAAC,aAAa,EAAE;AACvC,IAAI,IAAI,aAAa,KAAK,UAAU,EAAE;AACtC,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,KAAK;AAC1B,SAAS,CAAC;AACV,KAAK;AACL,SAAS,IAAI,aAAa,KAAK,WAAW,EAAE;AAC5C,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,IAAI;AACzB,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;;"}
|
|
@@ -29,7 +29,9 @@ function getRedirectUrl(redirects, preferredRedirectUrl) {
|
|
|
29
29
|
}
|
|
30
30
|
exports.getRedirectUrl = getRedirectUrl;
|
|
31
31
|
// origin + pathname => https://example.com/app
|
|
32
|
-
const isSameOriginAndPathName = (redirect) => redirect.startsWith(
|
|
32
|
+
const isSameOriginAndPathName = (redirect) => redirect.startsWith(
|
|
33
|
+
// eslint-disable-next-line no-constant-binary-expression
|
|
34
|
+
String(window.location.origin + window.location.pathname ?? '/'));
|
|
33
35
|
// domain => outlook.live.com, github.com
|
|
34
36
|
const isTheSameDomain = (redirect) => redirect.includes(String(window.location.hostname));
|
|
35
37
|
const isHttp = (redirect) => redirect.startsWith('http://');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRedirectUrl.js","sources":["../../../../../../src/providers/cognito/utils/oauth/getRedirectUrl.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getRedirectUrl = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst constants_1 = require(\"../../../../errors/constants\");\n/** @internal */\nfunction getRedirectUrl(redirects, preferredRedirectUrl) {\n if (preferredRedirectUrl) {\n const redirectUrl = redirects?.find(redirect => redirect === preferredRedirectUrl);\n if (!redirectUrl) {\n throw constants_1.invalidPreferredRedirectUrlException;\n }\n return redirectUrl;\n }\n else {\n const redirectUrlFromTheSameOrigin = redirects?.find(isSameOriginAndPathName) ??\n redirects?.find(isTheSameDomain);\n const redirectUrlFromDifferentOrigin = redirects?.find(isHttps) ?? redirects?.find(isHttp);\n if (redirectUrlFromTheSameOrigin) {\n return redirectUrlFromTheSameOrigin;\n }\n else if (redirectUrlFromDifferentOrigin) {\n throw constants_1.invalidOriginException;\n }\n throw constants_1.invalidRedirectException;\n }\n}\nexports.getRedirectUrl = getRedirectUrl;\n// origin + pathname => https://example.com/app\nconst isSameOriginAndPathName = (redirect) => redirect.startsWith(
|
|
1
|
+
{"version":3,"file":"getRedirectUrl.js","sources":["../../../../../../src/providers/cognito/utils/oauth/getRedirectUrl.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getRedirectUrl = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst constants_1 = require(\"../../../../errors/constants\");\n/** @internal */\nfunction getRedirectUrl(redirects, preferredRedirectUrl) {\n if (preferredRedirectUrl) {\n const redirectUrl = redirects?.find(redirect => redirect === preferredRedirectUrl);\n if (!redirectUrl) {\n throw constants_1.invalidPreferredRedirectUrlException;\n }\n return redirectUrl;\n }\n else {\n const redirectUrlFromTheSameOrigin = redirects?.find(isSameOriginAndPathName) ??\n redirects?.find(isTheSameDomain);\n const redirectUrlFromDifferentOrigin = redirects?.find(isHttps) ?? redirects?.find(isHttp);\n if (redirectUrlFromTheSameOrigin) {\n return redirectUrlFromTheSameOrigin;\n }\n else if (redirectUrlFromDifferentOrigin) {\n throw constants_1.invalidOriginException;\n }\n throw constants_1.invalidRedirectException;\n }\n}\nexports.getRedirectUrl = getRedirectUrl;\n// origin + pathname => https://example.com/app\nconst isSameOriginAndPathName = (redirect) => redirect.startsWith(\n// eslint-disable-next-line no-constant-binary-expression\nString(window.location.origin + window.location.pathname ?? '/'));\n// domain => outlook.live.com, github.com\nconst isTheSameDomain = (redirect) => redirect.includes(String(window.location.hostname));\nconst isHttp = (redirect) => redirect.startsWith('http://');\nconst isHttps = (redirect) => redirect.startsWith('https://');\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC;AACA;AACA,MAAM,WAAW,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC5D;AACA,SAAS,cAAc,CAAC,SAAS,EAAE,oBAAoB,EAAE;AACzD,IAAI,IAAI,oBAAoB,EAAE;AAC9B,QAAQ,MAAM,WAAW,GAAG,SAAS,EAAE,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,oBAAoB,CAAC,CAAC;AAC3F,QAAQ,IAAI,CAAC,WAAW,EAAE;AAC1B,YAAY,MAAM,WAAW,CAAC,oCAAoC,CAAC;AACnE,SAAS;AACT,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK;AACL,SAAS;AACT,QAAQ,MAAM,4BAA4B,GAAG,SAAS,EAAE,IAAI,CAAC,uBAAuB,CAAC;AACrF,YAAY,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;AAC7C,QAAQ,MAAM,8BAA8B,GAAG,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;AACnG,QAAQ,IAAI,4BAA4B,EAAE;AAC1C,YAAY,OAAO,4BAA4B,CAAC;AAChD,SAAS;AACT,aAAa,IAAI,8BAA8B,EAAE;AACjD,YAAY,MAAM,WAAW,CAAC,sBAAsB,CAAC;AACrD,SAAS;AACT,QAAQ,MAAM,WAAW,CAAC,wBAAwB,CAAC;AACnD,KAAK;AACL,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc,CAAC;AACxC;AACA,MAAM,uBAAuB,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,UAAU;AACjE;AACA,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC;AAClE;AACA,MAAM,eAAe,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1F,MAAM,MAAM,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AAC5D,MAAM,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,UAAU,CAAC,UAAU,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.
|
|
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,91 @@ 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
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
const isTOTPCode = /^\d+$/.test(challengeResponse.trim());
|
|
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({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReq);
|
|
127
|
+
}
|
|
128
|
+
const isEmail = /^\S+@\S+\.\S+$/.test(challengeResponse.trim());
|
|
129
|
+
if (isEmail) {
|
|
130
|
+
challengeResponses.EMAIL = challengeResponse;
|
|
131
|
+
const jsonReq = {
|
|
132
|
+
ChallengeName: 'MFA_SETUP',
|
|
133
|
+
ChallengeResponses: challengeResponses,
|
|
134
|
+
Session: session,
|
|
135
|
+
ClientMetadata: clientMetadata,
|
|
136
|
+
ClientId: userPoolClientId,
|
|
137
|
+
};
|
|
138
|
+
const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
|
|
139
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
140
|
+
endpointOverride: userPoolEndpoint,
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
return respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReq);
|
|
144
|
+
}
|
|
145
|
+
throw new AuthError_1.AuthError({
|
|
146
|
+
name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
|
|
147
|
+
message: `Cannot proceed with MFA setup using challengeResponse: ${challengeResponse}`,
|
|
148
|
+
recoverySuggestion: 'Try passing "EMAIL", "TOTP", a valid email, or OTP code as the challengeResponse.',
|
|
103
149
|
});
|
|
104
|
-
return respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReq);
|
|
105
150
|
}
|
|
106
151
|
exports.handleMFASetupChallenge = handleMFASetupChallenge;
|
|
107
152
|
async function handleSelectMFATypeChallenge({ challengeResponse, username, clientMetadata, session, config, }) {
|
|
108
153
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
109
|
-
(0, assertValidationError_1.assertValidationError)(challengeResponse === 'TOTP' ||
|
|
154
|
+
(0, assertValidationError_1.assertValidationError)(challengeResponse === 'TOTP' ||
|
|
155
|
+
challengeResponse === 'SMS' ||
|
|
156
|
+
challengeResponse === 'EMAIL', validation_1.AuthValidationErrorCode.IncorrectMFAMethod);
|
|
110
157
|
const challengeResponses = {
|
|
111
158
|
USERNAME: username,
|
|
112
159
|
ANSWER: mapMfaType(challengeResponse),
|
|
@@ -135,66 +182,6 @@ async function handleSelectMFATypeChallenge({ challengeResponse, username, clien
|
|
|
135
182
|
}, jsonReq);
|
|
136
183
|
}
|
|
137
184
|
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
185
|
async function handleCompleteNewPasswordChallenge({ challengeResponse, clientMetadata, session, username, requiredAttributes, config, }) {
|
|
199
186
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
200
187
|
const challengeResponses = {
|
|
@@ -554,30 +541,52 @@ async function getSignInResult(params) {
|
|
|
554
541
|
};
|
|
555
542
|
case 'MFA_SETUP': {
|
|
556
543
|
const { signInSession, username } = signInStore_1.signInStore.getState();
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
544
|
+
const mfaSetupTypes = getMFATypes(parseMFATypes(challengeParameters.MFAS_CAN_SETUP)) || [];
|
|
545
|
+
const allowedMfaSetupTypes = getAllowedMfaSetupTypes(mfaSetupTypes);
|
|
546
|
+
const isTotpMfaSetupAvailable = allowedMfaSetupTypes.includes('TOTP');
|
|
547
|
+
const isEmailMfaSetupAvailable = allowedMfaSetupTypes.includes('EMAIL');
|
|
548
|
+
if (isTotpMfaSetupAvailable && isEmailMfaSetupAvailable) {
|
|
549
|
+
return {
|
|
550
|
+
isSignedIn: false,
|
|
551
|
+
nextStep: {
|
|
552
|
+
signInStep: 'CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION',
|
|
553
|
+
allowedMFATypes: allowedMfaSetupTypes,
|
|
554
|
+
},
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
if (isEmailMfaSetupAvailable) {
|
|
558
|
+
return {
|
|
559
|
+
isSignedIn: false,
|
|
560
|
+
nextStep: {
|
|
561
|
+
signInStep: 'CONTINUE_SIGN_IN_WITH_EMAIL_SETUP',
|
|
562
|
+
},
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (isTotpMfaSetupAvailable) {
|
|
566
|
+
const associateSoftwareToken = (0, cognitoIdentityProvider_1.createAssociateSoftwareTokenClient)({
|
|
567
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
568
|
+
endpointOverride: authConfig.userPoolEndpoint,
|
|
569
|
+
}),
|
|
561
570
|
});
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
571
|
+
const { Session, SecretCode: secretCode } = await associateSoftwareToken({ region: (0, parsers_1.getRegionFromUserPoolId)(authConfig.userPoolId) }, {
|
|
572
|
+
Session: signInSession,
|
|
573
|
+
});
|
|
574
|
+
signInStore_1.signInStore.dispatch({
|
|
575
|
+
type: 'SET_SIGN_IN_SESSION',
|
|
576
|
+
value: Session,
|
|
577
|
+
});
|
|
578
|
+
return {
|
|
579
|
+
isSignedIn: false,
|
|
580
|
+
nextStep: {
|
|
581
|
+
signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP',
|
|
582
|
+
totpSetupDetails: getTOTPSetupDetails(secretCode, username),
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
throw new AuthError_1.AuthError({
|
|
587
|
+
name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
|
|
588
|
+
message: `Cannot initiate MFA setup from available types: ${mfaSetupTypes}`,
|
|
573
589
|
});
|
|
574
|
-
return {
|
|
575
|
-
isSignedIn: false,
|
|
576
|
-
nextStep: {
|
|
577
|
-
signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP',
|
|
578
|
-
totpSetupDetails: getTOTPSetupDetails(secretCode, username),
|
|
579
|
-
},
|
|
580
|
-
};
|
|
581
590
|
}
|
|
582
591
|
case 'NEW_PASSWORD_REQUIRED':
|
|
583
592
|
return {
|
|
@@ -613,6 +622,17 @@ async function getSignInResult(params) {
|
|
|
613
622
|
signInStep: 'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
|
|
614
623
|
},
|
|
615
624
|
};
|
|
625
|
+
case 'EMAIL_OTP':
|
|
626
|
+
return {
|
|
627
|
+
isSignedIn: false,
|
|
628
|
+
nextStep: {
|
|
629
|
+
signInStep: 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE',
|
|
630
|
+
codeDeliveryDetails: {
|
|
631
|
+
deliveryMedium: challengeParameters.CODE_DELIVERY_DELIVERY_MEDIUM,
|
|
632
|
+
destination: challengeParameters.CODE_DELIVERY_DESTINATION,
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
};
|
|
616
636
|
}
|
|
617
637
|
// TODO: remove this error message for production apps
|
|
618
638
|
throw new AuthError_1.AuthError({
|
|
@@ -669,14 +689,6 @@ async function handleChallengeName(username, challengeName, session, challengeRe
|
|
|
669
689
|
const userAttributes = options?.userAttributes;
|
|
670
690
|
const deviceName = options?.friendlyDeviceName;
|
|
671
691
|
switch (challengeName) {
|
|
672
|
-
case 'SMS_MFA':
|
|
673
|
-
return handleSMSMFAChallenge({
|
|
674
|
-
challengeResponse,
|
|
675
|
-
clientMetadata,
|
|
676
|
-
session,
|
|
677
|
-
username,
|
|
678
|
-
config,
|
|
679
|
-
});
|
|
680
692
|
case 'SELECT_MFA_TYPE':
|
|
681
693
|
return handleSelectMFATypeChallenge({
|
|
682
694
|
challengeResponse,
|
|
@@ -714,8 +726,11 @@ async function handleChallengeName(username, challengeName, session, challengeRe
|
|
|
714
726
|
tokenOrchestrator,
|
|
715
727
|
},
|
|
716
728
|
], username, tokenOrchestrator);
|
|
729
|
+
case 'SMS_MFA':
|
|
717
730
|
case 'SOFTWARE_TOKEN_MFA':
|
|
718
|
-
|
|
731
|
+
case 'EMAIL_OTP':
|
|
732
|
+
return handleMFAChallenge({
|
|
733
|
+
challengeName,
|
|
719
734
|
challengeResponse,
|
|
720
735
|
clientMetadata,
|
|
721
736
|
session,
|
|
@@ -726,7 +741,7 @@ async function handleChallengeName(username, challengeName, session, challengeRe
|
|
|
726
741
|
// TODO: remove this error message for production apps
|
|
727
742
|
throw new AuthError_1.AuthError({
|
|
728
743
|
name: AuthErrorStrings_1.AuthErrorCodes.SignInException,
|
|
729
|
-
message: `An error occurred during the sign in process.
|
|
744
|
+
message: `An error occurred during the sign in process.
|
|
730
745
|
${challengeName} challengeName returned by the underlying service was not addressed.`,
|
|
731
746
|
});
|
|
732
747
|
}
|
|
@@ -735,6 +750,8 @@ function mapMfaType(mfa) {
|
|
|
735
750
|
let mfaType = 'SMS_MFA';
|
|
736
751
|
if (mfa === 'TOTP')
|
|
737
752
|
mfaType = 'SOFTWARE_TOKEN_MFA';
|
|
753
|
+
if (mfa === 'EMAIL')
|
|
754
|
+
mfaType = 'EMAIL_OTP';
|
|
738
755
|
return mfaType;
|
|
739
756
|
}
|
|
740
757
|
exports.mapMfaType = mapMfaType;
|
|
@@ -743,6 +760,8 @@ function getMFAType(type) {
|
|
|
743
760
|
return 'SMS';
|
|
744
761
|
if (type === 'SOFTWARE_TOKEN_MFA')
|
|
745
762
|
return 'TOTP';
|
|
763
|
+
if (type === 'EMAIL_OTP')
|
|
764
|
+
return 'EMAIL';
|
|
746
765
|
// TODO: log warning for unknown MFA type
|
|
747
766
|
}
|
|
748
767
|
exports.getMFAType = getMFAType;
|
|
@@ -758,14 +777,10 @@ function parseMFATypes(mfa) {
|
|
|
758
777
|
return JSON.parse(mfa);
|
|
759
778
|
}
|
|
760
779
|
exports.parseMFATypes = parseMFATypes;
|
|
761
|
-
function
|
|
762
|
-
|
|
763
|
-
const mfaTypes = getMFATypes(parseMFATypes(MFAS_CAN_SETUP));
|
|
764
|
-
if (!mfaTypes)
|
|
765
|
-
return false;
|
|
766
|
-
return mfaTypes.includes(mfaType);
|
|
780
|
+
function getAllowedMfaSetupTypes(availableMfaSetupTypes) {
|
|
781
|
+
return availableMfaSetupTypes.filter(authMfaType => authMfaType === 'EMAIL' || authMfaType === 'TOTP');
|
|
767
782
|
}
|
|
768
|
-
exports.
|
|
783
|
+
exports.getAllowedMfaSetupTypes = getAllowedMfaSetupTypes;
|
|
769
784
|
async function assertUserNotAuthenticated() {
|
|
770
785
|
let authUser;
|
|
771
786
|
try {
|
|
@@ -863,4 +878,42 @@ function getActiveSignInUsername(username) {
|
|
|
863
878
|
return state.username ?? username;
|
|
864
879
|
}
|
|
865
880
|
exports.getActiveSignInUsername = getActiveSignInUsername;
|
|
881
|
+
async function handleMFAChallenge({ challengeName, challengeResponse, clientMetadata, session, username, config, }) {
|
|
882
|
+
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
883
|
+
const challengeResponses = {
|
|
884
|
+
USERNAME: username,
|
|
885
|
+
};
|
|
886
|
+
if (challengeName === 'EMAIL_OTP') {
|
|
887
|
+
challengeResponses.EMAIL_OTP_CODE = challengeResponse;
|
|
888
|
+
}
|
|
889
|
+
if (challengeName === 'SMS_MFA') {
|
|
890
|
+
challengeResponses.SMS_MFA_CODE = challengeResponse;
|
|
891
|
+
}
|
|
892
|
+
if (challengeName === 'SOFTWARE_TOKEN_MFA') {
|
|
893
|
+
challengeResponses.SOFTWARE_TOKEN_MFA_CODE = challengeResponse;
|
|
894
|
+
}
|
|
895
|
+
const userContextData = (0, userContextData_1.getUserContextData)({
|
|
896
|
+
username,
|
|
897
|
+
userPoolId,
|
|
898
|
+
userPoolClientId,
|
|
899
|
+
});
|
|
900
|
+
const jsonReq = {
|
|
901
|
+
ChallengeName: challengeName,
|
|
902
|
+
ChallengeResponses: challengeResponses,
|
|
903
|
+
Session: session,
|
|
904
|
+
ClientMetadata: clientMetadata,
|
|
905
|
+
ClientId: userPoolClientId,
|
|
906
|
+
UserContextData: userContextData,
|
|
907
|
+
};
|
|
908
|
+
const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
|
|
909
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
910
|
+
endpointOverride: userPoolEndpoint,
|
|
911
|
+
}),
|
|
912
|
+
});
|
|
913
|
+
return respondToAuthChallenge({
|
|
914
|
+
region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId),
|
|
915
|
+
userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.ConfirmSignIn),
|
|
916
|
+
}, jsonReq);
|
|
917
|
+
}
|
|
918
|
+
exports.handleMFAChallenge = handleMFAChallenge;
|
|
866
919
|
//# sourceMappingURL=signInHelpers.js.map
|