@aws-amplify/auth 6.10.2-unstable.ba025e5.0 → 6.10.2
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/client/flows/shared/handlePasswordSRP.js +5 -3
- package/dist/cjs/client/flows/shared/handlePasswordSRP.js.map +1 -1
- package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPassword.js +2 -2
- package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPassword.js.map +1 -1
- package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.js +5 -3
- package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.js.map +1 -1
- package/dist/cjs/client/flows/userAuth/handleUserAuthFlow.js +2 -2
- package/dist/cjs/client/flows/userAuth/handleUserAuthFlow.js.map +1 -1
- package/dist/cjs/client/flows/userAuth/handleWebAuthnSignInResult.js +4 -4
- package/dist/cjs/client/flows/userAuth/handleWebAuthnSignInResult.js.map +1 -1
- package/dist/cjs/client/flows/userAuth/types.js +6 -0
- package/dist/cjs/client/flows/userAuth/types.js.map +1 -0
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js +2 -1
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithCustomAuth.js +4 -2
- package/dist/cjs/providers/cognito/apis/signInWithCustomAuth.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithCustomSRPAuth.js +2 -1
- package/dist/cjs/providers/cognito/apis/signInWithCustomSRPAuth.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithSRP.js +2 -1
- package/dist/cjs/providers/cognito/apis/signInWithSRP.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithUserAuth.js +2 -1
- package/dist/cjs/providers/cognito/apis/signInWithUserAuth.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithUserPassword.js +4 -2
- package/dist/cjs/providers/cognito/apis/signInWithUserPassword.js.map +1 -1
- package/dist/cjs/providers/cognito/utils/getNewDeviceMetadata.js +64 -0
- package/dist/cjs/providers/cognito/utils/getNewDeviceMetadata.js.map +1 -0
- package/dist/cjs/providers/cognito/utils/handleDeviceSRPAuth.js +88 -0
- package/dist/cjs/providers/cognito/utils/handleDeviceSRPAuth.js.map +1 -0
- package/dist/cjs/providers/cognito/utils/handlePasswordVerifierChallenge.js +79 -0
- package/dist/cjs/providers/cognito/utils/handlePasswordVerifierChallenge.js.map +1 -0
- package/dist/cjs/providers/cognito/utils/retryOnResourceNotFoundException.js +28 -0
- package/dist/cjs/providers/cognito/utils/retryOnResourceNotFoundException.js.map +1 -0
- package/dist/cjs/providers/cognito/utils/setActiveSignInUsername.js +13 -0
- package/dist/cjs/providers/cognito/utils/setActiveSignInUsername.js.map +1 -0
- package/dist/cjs/providers/cognito/utils/signInHelpers.js +23 -227
- package/dist/cjs/providers/cognito/utils/signInHelpers.js.map +1 -1
- package/dist/esm/client/flows/shared/handlePasswordSRP.mjs +3 -1
- package/dist/esm/client/flows/shared/handlePasswordSRP.mjs.map +1 -1
- package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPassword.mjs +1 -1
- package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPassword.mjs.map +1 -1
- package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.mjs +3 -1
- package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.mjs.map +1 -1
- package/dist/esm/client/flows/userAuth/handleUserAuthFlow.mjs +1 -1
- package/dist/esm/client/flows/userAuth/handleUserAuthFlow.mjs.map +1 -1
- package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.d.ts +2 -2
- package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.mjs +3 -3
- package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.mjs.map +1 -1
- package/dist/esm/client/flows/userAuth/types.d.ts +6 -0
- package/dist/esm/client/flows/userAuth/types.mjs +2 -0
- package/dist/esm/client/flows/userAuth/types.mjs.map +1 -0
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs +2 -1
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithCustomAuth.mjs +3 -1
- package/dist/esm/providers/cognito/apis/signInWithCustomAuth.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithCustomSRPAuth.mjs +2 -1
- package/dist/esm/providers/cognito/apis/signInWithCustomSRPAuth.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithSRP.mjs +2 -1
- package/dist/esm/providers/cognito/apis/signInWithSRP.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithUserAuth.mjs +2 -1
- package/dist/esm/providers/cognito/apis/signInWithUserAuth.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithUserPassword.mjs +3 -1
- package/dist/esm/providers/cognito/apis/signInWithUserPassword.mjs.map +1 -1
- package/dist/esm/providers/cognito/utils/getNewDeviceMetadata.d.ts +17 -0
- package/dist/esm/providers/cognito/utils/getNewDeviceMetadata.mjs +71 -0
- package/dist/esm/providers/cognito/utils/getNewDeviceMetadata.mjs.map +1 -0
- package/dist/esm/providers/cognito/utils/handleDeviceSRPAuth.d.ts +13 -0
- package/dist/esm/providers/cognito/utils/handleDeviceSRPAuth.mjs +97 -0
- package/dist/esm/providers/cognito/utils/handleDeviceSRPAuth.mjs.map +1 -0
- package/dist/esm/providers/cognito/utils/handlePasswordVerifierChallenge.d.ts +6 -0
- package/dist/esm/providers/cognito/utils/handlePasswordVerifierChallenge.mjs +88 -0
- package/dist/esm/providers/cognito/utils/handlePasswordVerifierChallenge.mjs.map +1 -0
- package/dist/esm/providers/cognito/utils/retryOnResourceNotFoundException.d.ts +7 -0
- package/dist/esm/providers/cognito/utils/retryOnResourceNotFoundException.mjs +26 -0
- package/dist/esm/providers/cognito/utils/retryOnResourceNotFoundException.mjs.map +1 -0
- package/dist/esm/providers/cognito/utils/setActiveSignInUsername.d.ts +1 -0
- package/dist/esm/providers/cognito/utils/setActiveSignInUsername.mjs +12 -0
- package/dist/esm/providers/cognito/utils/setActiveSignInUsername.mjs.map +1 -0
- package/dist/esm/providers/cognito/utils/signInHelpers.d.ts +2 -26
- package/dist/esm/providers/cognito/utils/signInHelpers.mjs +18 -220
- package/dist/esm/providers/cognito/utils/signInHelpers.mjs.map +1 -1
- package/package.json +106 -106
- package/src/client/flows/shared/handlePasswordSRP.ts +3 -5
- package/src/client/flows/userAuth/handleSelectChallengeWithPassword.ts +1 -1
- package/src/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.ts +3 -5
- package/src/client/flows/userAuth/handleUserAuthFlow.ts +1 -1
- package/src/client/flows/userAuth/handleWebAuthnSignInResult.ts +6 -8
- package/src/client/flows/userAuth/types.ts +15 -0
- package/src/providers/cognito/apis/confirmSignIn.ts +1 -1
- package/src/providers/cognito/apis/signInWithCustomAuth.ts +2 -2
- package/src/providers/cognito/apis/signInWithCustomSRPAuth.ts +1 -1
- package/src/providers/cognito/apis/signInWithSRP.ts +1 -1
- package/src/providers/cognito/apis/signInWithUserAuth.ts +1 -1
- package/src/providers/cognito/apis/signInWithUserPassword.ts +2 -2
- package/src/providers/cognito/utils/getNewDeviceMetadata.ts +88 -0
- package/src/providers/cognito/utils/handleDeviceSRPAuth.ts +146 -0
- package/src/providers/cognito/utils/handlePasswordVerifierChallenge.ts +106 -0
- package/src/providers/cognito/utils/retryOnResourceNotFoundException.ts +34 -0
- package/src/providers/cognito/utils/setActiveSignInUsername.ts +10 -0
- package/src/providers/cognito/utils/signInHelpers.ts +19 -327
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInWithUserAuth.js","sources":["../../../../../src/providers/cognito/apis/signInWithUserAuth.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.signInWithUserAuth = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst store_1 = require(\"../../../client/utils/store\");\nconst signInStore_1 = require(\"../../../client/utils/store/signInStore\");\nconst cacheTokens_1 = require(\"../tokenProvider/cacheTokens\");\nconst dispatchSignedInHubEvent_1 = require(\"../utils/dispatchSignedInHubEvent\");\nconst tokenProvider_1 = require(\"../tokenProvider\");\nconst handleUserAuthFlow_1 = require(\"../../../client/flows/userAuth/handleUserAuthFlow\");\nconst autoSignIn_1 = require(\"./autoSignIn\");\n/**\n * Signs a user in through a registered email or phone number without a password by by receiving and entering an OTP.\n *\n * @param input - The SignInWithUserAuthInput object\n * @returns SignInWithUserAuthOutput\n * @throws service: {@link InitiateAuthException }, {@link RespondToAuthChallengeException } - Cognito service errors\n * thrown during the sign-in process.\n * @throws validation: {@link AuthValidationErrorCode } - Validation errors thrown when either username or password -- needs to change\n * are not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function signInWithUserAuth(input) {\n const { username, password, options } = input;\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n const signInDetails = {\n loginId: username,\n authFlowType: 'USER_AUTH',\n };\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const clientMetaData = options?.clientMetadata;\n const preferredChallenge = options?.preferredChallenge;\n (0, assertValidationError_1.assertValidationError)(!!username, validation_1.AuthValidationErrorCode.EmptySignInUsername);\n try {\n const handleUserAuthFlowInput = {\n username,\n config: authConfig,\n tokenOrchestrator: tokenProvider_1.tokenOrchestrator,\n clientMetadata: clientMetaData,\n preferredChallenge,\n password,\n };\n const autoSignInStoreState = store_1.autoSignInStore.getState();\n if (autoSignInStoreState.active &&\n autoSignInStoreState.username === username) {\n handleUserAuthFlowInput.session = autoSignInStoreState.session;\n }\n const response = await (0, handleUserAuthFlow_1.handleUserAuthFlow)(handleUserAuthFlowInput);\n const activeUsername = (0, signInHelpers_1.getActiveSignInUsername)(username);\n (0, signInStore_1.setActiveSignInState)({\n signInSession: response.Session,\n username: activeUsername,\n challengeName: response.ChallengeName,\n signInDetails,\n });\n if (response.AuthenticationResult) {\n await (0, cacheTokens_1.cacheCognitoTokens)({\n username: activeUsername,\n ...response.AuthenticationResult,\n NewDeviceMetadata: await (0,
|
|
1
|
+
{"version":3,"file":"signInWithUserAuth.js","sources":["../../../../../src/providers/cognito/apis/signInWithUserAuth.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.signInWithUserAuth = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst store_1 = require(\"../../../client/utils/store\");\nconst signInStore_1 = require(\"../../../client/utils/store/signInStore\");\nconst cacheTokens_1 = require(\"../tokenProvider/cacheTokens\");\nconst dispatchSignedInHubEvent_1 = require(\"../utils/dispatchSignedInHubEvent\");\nconst tokenProvider_1 = require(\"../tokenProvider\");\nconst handleUserAuthFlow_1 = require(\"../../../client/flows/userAuth/handleUserAuthFlow\");\nconst getNewDeviceMetadata_1 = require(\"../utils/getNewDeviceMetadata\");\nconst autoSignIn_1 = require(\"./autoSignIn\");\n/**\n * Signs a user in through a registered email or phone number without a password by by receiving and entering an OTP.\n *\n * @param input - The SignInWithUserAuthInput object\n * @returns SignInWithUserAuthOutput\n * @throws service: {@link InitiateAuthException }, {@link RespondToAuthChallengeException } - Cognito service errors\n * thrown during the sign-in process.\n * @throws validation: {@link AuthValidationErrorCode } - Validation errors thrown when either username or password -- needs to change\n * are not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function signInWithUserAuth(input) {\n const { username, password, options } = input;\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n const signInDetails = {\n loginId: username,\n authFlowType: 'USER_AUTH',\n };\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const clientMetaData = options?.clientMetadata;\n const preferredChallenge = options?.preferredChallenge;\n (0, assertValidationError_1.assertValidationError)(!!username, validation_1.AuthValidationErrorCode.EmptySignInUsername);\n try {\n const handleUserAuthFlowInput = {\n username,\n config: authConfig,\n tokenOrchestrator: tokenProvider_1.tokenOrchestrator,\n clientMetadata: clientMetaData,\n preferredChallenge,\n password,\n };\n const autoSignInStoreState = store_1.autoSignInStore.getState();\n if (autoSignInStoreState.active &&\n autoSignInStoreState.username === username) {\n handleUserAuthFlowInput.session = autoSignInStoreState.session;\n }\n const response = await (0, handleUserAuthFlow_1.handleUserAuthFlow)(handleUserAuthFlowInput);\n const activeUsername = (0, signInHelpers_1.getActiveSignInUsername)(username);\n (0, signInStore_1.setActiveSignInState)({\n signInSession: response.Session,\n username: activeUsername,\n challengeName: response.ChallengeName,\n signInDetails,\n });\n if (response.AuthenticationResult) {\n await (0, cacheTokens_1.cacheCognitoTokens)({\n username: activeUsername,\n ...response.AuthenticationResult,\n NewDeviceMetadata: await (0, getNewDeviceMetadata_1.getNewDeviceMetadata)({\n userPoolId: authConfig.userPoolId,\n userPoolEndpoint: authConfig.userPoolEndpoint,\n newDeviceMetadata: response.AuthenticationResult.NewDeviceMetadata,\n accessToken: response.AuthenticationResult.AccessToken,\n }),\n signInDetails,\n });\n (0, signInStore_1.resetActiveSignInState)();\n await (0, dispatchSignedInHubEvent_1.dispatchSignedInHubEvent)();\n (0, autoSignIn_1.resetAutoSignIn)();\n return {\n isSignedIn: true,\n nextStep: { signInStep: 'DONE' },\n };\n }\n return (0, signInHelpers_1.getSignInResult)({\n challengeName: response.ChallengeName,\n challengeParameters: response.ChallengeParameters,\n availableChallenges: 'AvailableChallenges' in response\n ? response.AvailableChallenges\n : undefined,\n });\n }\n catch (error) {\n (0, signInStore_1.resetActiveSignInState)();\n (0, autoSignIn_1.resetAutoSignIn)();\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.signInWithUserAuth = signInWithUserAuth;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AACjE,MAAM,uBAAuB,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;AACvF,MAAM,oBAAoB,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AACjF,MAAM,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACvD,MAAM,aAAa,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACzE,MAAM,aAAa,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC9D,MAAM,0BAA0B,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAChF,MAAM,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACpD,MAAM,oBAAoB,GAAG,OAAO,CAAC,mDAAmD,CAA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,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,QAAQ,CAAC,aAAa;AACjD,YAAY,mBAAmB,EAAE,QAAQ,CAAC,mBAAmB;AAC7D,YAAY,mBAAmB,EAAE,qBAAqB,IAAI,QAAQ;AAClE,kBAAkB,QAAQ,CAAC,mBAAmB;AAC9C,kBAAkB,SAAS;AAC3B,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,aAAa,CAAC,sBAAsB,GAAG,CAAC;AACpD,QAAQ,IAAI,YAAY,CAAC,eAAe,GAAG,CAAC;AAC5C,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,kBAAkB,GAAG,kBAAkB;;"}
|
|
@@ -14,6 +14,8 @@ const signInStore_1 = require("../../../client/utils/store/signInStore");
|
|
|
14
14
|
const cacheTokens_1 = require("../tokenProvider/cacheTokens");
|
|
15
15
|
const tokenProvider_1 = require("../tokenProvider");
|
|
16
16
|
const dispatchSignedInHubEvent_1 = require("../utils/dispatchSignedInHubEvent");
|
|
17
|
+
const retryOnResourceNotFoundException_1 = require("../utils/retryOnResourceNotFoundException");
|
|
18
|
+
const getNewDeviceMetadata_1 = require("../utils/getNewDeviceMetadata");
|
|
17
19
|
const autoSignIn_1 = require("./autoSignIn");
|
|
18
20
|
/**
|
|
19
21
|
* Signs a user in using USER_PASSWORD_AUTH AuthFlowType
|
|
@@ -37,7 +39,7 @@ async function signInWithUserPassword(input) {
|
|
|
37
39
|
(0, assertValidationError_1.assertValidationError)(!!username, validation_1.AuthValidationErrorCode.EmptySignInUsername);
|
|
38
40
|
(0, assertValidationError_1.assertValidationError)(!!password, validation_1.AuthValidationErrorCode.EmptySignInPassword);
|
|
39
41
|
try {
|
|
40
|
-
const { ChallengeName: retiredChallengeName, ChallengeParameters: retriedChallengeParameters, AuthenticationResult, Session, } = await (0,
|
|
42
|
+
const { ChallengeName: retiredChallengeName, ChallengeParameters: retriedChallengeParameters, AuthenticationResult, Session, } = await (0, retryOnResourceNotFoundException_1.retryOnResourceNotFoundException)(signInHelpers_1.handleUserPasswordAuthFlow, [username, password, metadata, authConfig, tokenProvider_1.tokenOrchestrator], username, tokenProvider_1.tokenOrchestrator);
|
|
41
43
|
const activeUsername = (0, signInHelpers_1.getActiveSignInUsername)(username);
|
|
42
44
|
// sets up local state used during the sign-in process
|
|
43
45
|
(0, signInStore_1.setActiveSignInState)({
|
|
@@ -50,7 +52,7 @@ async function signInWithUserPassword(input) {
|
|
|
50
52
|
await (0, cacheTokens_1.cacheCognitoTokens)({
|
|
51
53
|
...AuthenticationResult,
|
|
52
54
|
username: activeUsername,
|
|
53
|
-
NewDeviceMetadata: await (0,
|
|
55
|
+
NewDeviceMetadata: await (0, getNewDeviceMetadata_1.getNewDeviceMetadata)({
|
|
54
56
|
userPoolId: authConfig.userPoolId,
|
|
55
57
|
userPoolEndpoint: authConfig.userPoolEndpoint,
|
|
56
58
|
newDeviceMetadata: AuthenticationResult.NewDeviceMetadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInWithUserPassword.js","sources":["../../../../../src/providers/cognito/apis/signInWithUserPassword.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.signInWithUserPassword = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst signInStore_1 = require(\"../../../client/utils/store/signInStore\");\nconst cacheTokens_1 = require(\"../tokenProvider/cacheTokens\");\nconst tokenProvider_1 = require(\"../tokenProvider\");\nconst dispatchSignedInHubEvent_1 = require(\"../utils/dispatchSignedInHubEvent\");\nconst autoSignIn_1 = require(\"./autoSignIn\");\n/**\n * Signs a user in using USER_PASSWORD_AUTH AuthFlowType\n *\n * @param input - The SignInWithUserPasswordInput object\n * @returns SignInWithUserPasswordOutput\n * @throws service: {@link InitiateAuthException } - Cognito service error thrown during the sign-in process.\n * @throws validation: {@link AuthValidationErrorCode } - Validation errors thrown when either username or password\n * are not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function signInWithUserPassword(input) {\n const { username, password, options } = input;\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n const signInDetails = {\n loginId: username,\n authFlowType: 'USER_PASSWORD_AUTH',\n };\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const metadata = options?.clientMetadata;\n (0, assertValidationError_1.assertValidationError)(!!username, validation_1.AuthValidationErrorCode.EmptySignInUsername);\n (0, assertValidationError_1.assertValidationError)(!!password, validation_1.AuthValidationErrorCode.EmptySignInPassword);\n try {\n const { ChallengeName: retiredChallengeName, ChallengeParameters: retriedChallengeParameters, AuthenticationResult, Session, } = await (0,
|
|
1
|
+
{"version":3,"file":"signInWithUserPassword.js","sources":["../../../../../src/providers/cognito/apis/signInWithUserPassword.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.signInWithUserPassword = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst validation_1 = require(\"../../../errors/types/validation\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst assertValidationError_1 = require(\"../../../errors/utils/assertValidationError\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst signInStore_1 = require(\"../../../client/utils/store/signInStore\");\nconst cacheTokens_1 = require(\"../tokenProvider/cacheTokens\");\nconst tokenProvider_1 = require(\"../tokenProvider\");\nconst dispatchSignedInHubEvent_1 = require(\"../utils/dispatchSignedInHubEvent\");\nconst retryOnResourceNotFoundException_1 = require(\"../utils/retryOnResourceNotFoundException\");\nconst getNewDeviceMetadata_1 = require(\"../utils/getNewDeviceMetadata\");\nconst autoSignIn_1 = require(\"./autoSignIn\");\n/**\n * Signs a user in using USER_PASSWORD_AUTH AuthFlowType\n *\n * @param input - The SignInWithUserPasswordInput object\n * @returns SignInWithUserPasswordOutput\n * @throws service: {@link InitiateAuthException } - Cognito service error thrown during the sign-in process.\n * @throws validation: {@link AuthValidationErrorCode } - Validation errors thrown when either username or password\n * are not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nasync function signInWithUserPassword(input) {\n const { username, password, options } = input;\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n const signInDetails = {\n loginId: username,\n authFlowType: 'USER_PASSWORD_AUTH',\n };\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n const metadata = options?.clientMetadata;\n (0, assertValidationError_1.assertValidationError)(!!username, validation_1.AuthValidationErrorCode.EmptySignInUsername);\n (0, assertValidationError_1.assertValidationError)(!!password, validation_1.AuthValidationErrorCode.EmptySignInPassword);\n try {\n const { ChallengeName: retiredChallengeName, ChallengeParameters: retriedChallengeParameters, AuthenticationResult, Session, } = await (0, retryOnResourceNotFoundException_1.retryOnResourceNotFoundException)(signInHelpers_1.handleUserPasswordAuthFlow, [username, password, metadata, authConfig, tokenProvider_1.tokenOrchestrator], username, tokenProvider_1.tokenOrchestrator);\n const activeUsername = (0, signInHelpers_1.getActiveSignInUsername)(username);\n // sets up local state used during the sign-in process\n (0, signInStore_1.setActiveSignInState)({\n signInSession: Session,\n username: activeUsername,\n challengeName: retiredChallengeName,\n signInDetails,\n });\n if (AuthenticationResult) {\n await (0, cacheTokens_1.cacheCognitoTokens)({\n ...AuthenticationResult,\n username: activeUsername,\n NewDeviceMetadata: await (0, getNewDeviceMetadata_1.getNewDeviceMetadata)({\n userPoolId: authConfig.userPoolId,\n userPoolEndpoint: authConfig.userPoolEndpoint,\n newDeviceMetadata: AuthenticationResult.NewDeviceMetadata,\n accessToken: AuthenticationResult.AccessToken,\n }),\n signInDetails,\n });\n (0, signInStore_1.resetActiveSignInState)();\n await (0, dispatchSignedInHubEvent_1.dispatchSignedInHubEvent)();\n (0, autoSignIn_1.resetAutoSignIn)();\n return {\n isSignedIn: true,\n nextStep: { signInStep: 'DONE' },\n };\n }\n return (0, signInHelpers_1.getSignInResult)({\n challengeName: retiredChallengeName,\n challengeParameters: retriedChallengeParameters,\n });\n }\n catch (error) {\n (0, signInStore_1.resetActiveSignInState)();\n (0, autoSignIn_1.resetAutoSignIn)();\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.signInWithUserPassword = signInWithUserPassword;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AACxC,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mC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AAW;AACjE,iBAAiB,CAAC;AAClB,gBAAgB,aAAa;AAC7B,aAAa,CAAC,CAAC;AACf,YAAY,CAAC,CAAC,EAAE,aAAa,CAAC,sBAAsB,GAAG,CAAC;AACxD,YAAY,MAAM,CAAC,CAAC,EAAE,0BAA0B,CAAC,wBAAwB,GAAG,CAAC;AAC7E,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,eAAe,GAAG,CAAC;AAChD,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,aAAa,CAAC,sBAAsB,GAAG,CAAC;AACpD,QAAQ,IAAI,YAAY,CAAC,eAAe,GAAG,CAAC;AAC5C,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,sBAAsB,GAAG,sBAAsB;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getNewDeviceMetadata = void 0;
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const cognitoIdentityProvider_1 = require("../../../foundation/factories/serviceClients/cognitoIdentityProvider");
|
|
9
|
+
const factories_1 = require("../factories");
|
|
10
|
+
const parsers_1 = require("../../../foundation/parsers");
|
|
11
|
+
const srp_1 = require("./srp");
|
|
12
|
+
/**
|
|
13
|
+
* This function is used to kick off the device management flow.
|
|
14
|
+
*
|
|
15
|
+
* If an error is thrown while generating a hash device or calling the `ConfirmDevice`
|
|
16
|
+
* client, then this API will ignore the error and return undefined. Otherwise the authentication
|
|
17
|
+
* flow will not complete and the user won't be able to be signed in.
|
|
18
|
+
*
|
|
19
|
+
* @returns DeviceMetadata | undefined
|
|
20
|
+
*/
|
|
21
|
+
async function getNewDeviceMetadata({ userPoolId, userPoolEndpoint, newDeviceMetadata, accessToken, }) {
|
|
22
|
+
if (!newDeviceMetadata)
|
|
23
|
+
return undefined;
|
|
24
|
+
const userPoolName = userPoolId.split('_')[1] || '';
|
|
25
|
+
const authenticationHelper = await (0, srp_1.getAuthenticationHelper)(userPoolName);
|
|
26
|
+
const deviceKey = newDeviceMetadata?.DeviceKey;
|
|
27
|
+
const deviceGroupKey = newDeviceMetadata?.DeviceGroupKey;
|
|
28
|
+
try {
|
|
29
|
+
await authenticationHelper.generateHashDevice(deviceGroupKey ?? '', deviceKey ?? '');
|
|
30
|
+
}
|
|
31
|
+
catch (errGenHash) {
|
|
32
|
+
// TODO: log error here
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const deviceSecretVerifierConfig = {
|
|
36
|
+
Salt: utils_1.base64Encoder.convert((0, srp_1.getBytesFromHex)(authenticationHelper.getSaltToHashDevices())),
|
|
37
|
+
PasswordVerifier: utils_1.base64Encoder.convert((0, srp_1.getBytesFromHex)(authenticationHelper.getVerifierDevices())),
|
|
38
|
+
};
|
|
39
|
+
const randomPassword = authenticationHelper.getRandomPassword();
|
|
40
|
+
try {
|
|
41
|
+
const confirmDevice = (0, cognitoIdentityProvider_1.createConfirmDeviceClient)({
|
|
42
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
43
|
+
endpointOverride: userPoolEndpoint,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
await confirmDevice({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, {
|
|
47
|
+
AccessToken: accessToken,
|
|
48
|
+
DeviceName: await (0, utils_1.getDeviceName)(),
|
|
49
|
+
DeviceKey: newDeviceMetadata?.DeviceKey,
|
|
50
|
+
DeviceSecretVerifierConfig: deviceSecretVerifierConfig,
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
deviceKey,
|
|
54
|
+
deviceGroupKey,
|
|
55
|
+
randomPassword,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// TODO: log error here
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.getNewDeviceMetadata = getNewDeviceMetadata;
|
|
64
|
+
//# sourceMappingURL=getNewDeviceMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNewDeviceMetadata.js","sources":["../../../../../src/providers/cognito/utils/getNewDeviceMetadata.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.getNewDeviceMetadata = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst factories_1 = require(\"../factories\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst srp_1 = require(\"./srp\");\n/**\n * This function is used to kick off the device management flow.\n *\n * If an error is thrown while generating a hash device or calling the `ConfirmDevice`\n * client, then this API will ignore the error and return undefined. Otherwise the authentication\n * flow will not complete and the user won't be able to be signed in.\n *\n * @returns DeviceMetadata | undefined\n */\nasync function getNewDeviceMetadata({ userPoolId, userPoolEndpoint, newDeviceMetadata, accessToken, }) {\n if (!newDeviceMetadata)\n return undefined;\n const userPoolName = userPoolId.split('_')[1] || '';\n const authenticationHelper = await (0, srp_1.getAuthenticationHelper)(userPoolName);\n const deviceKey = newDeviceMetadata?.DeviceKey;\n const deviceGroupKey = newDeviceMetadata?.DeviceGroupKey;\n try {\n await authenticationHelper.generateHashDevice(deviceGroupKey ?? '', deviceKey ?? '');\n }\n catch (errGenHash) {\n // TODO: log error here\n return undefined;\n }\n const deviceSecretVerifierConfig = {\n Salt: utils_1.base64Encoder.convert((0, srp_1.getBytesFromHex)(authenticationHelper.getSaltToHashDevices())),\n PasswordVerifier: utils_1.base64Encoder.convert((0, srp_1.getBytesFromHex)(authenticationHelper.getVerifierDevices())),\n };\n const randomPassword = authenticationHelper.getRandomPassword();\n try {\n const confirmDevice = (0, cognitoIdentityProvider_1.createConfirmDeviceClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n await confirmDevice({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, {\n AccessToken: accessToken,\n DeviceName: await (0, utils_1.getDeviceName)(),\n DeviceKey: newDeviceMetadata?.DeviceKey,\n DeviceSecretVerifierConfig: deviceSecretVerifierConfig,\n });\n return {\n deviceKey,\n deviceGroupKey,\n randomPassword,\n };\n }\n catch (error) {\n // TODO: log error here\n return undefined;\n }\n}\nexports.getNewDeviceMetadata = getNewDeviceMetadata;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AACtC,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,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E,CAAC,CAAC;AAC9H,KAAK,CAAC;AACN,IAAI,MAAM,cAAc,GAAG,oBAAoB,CAAC,iBAAiB,EAAE,CAAC;AACpE,IAAI,IAAI;AACR,QAAQ,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC,yBAAyB,EAAE;AACvF,YAAY,gBAAgB,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,qCAAqC,EAAE;AACrF,gBAAgB,gBAAgB,EAAE,gBAAgB;AAClD,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,uBAAuB,EAAE,UAAU,CAAC,EAAE,EAAE;AAC5F,YAAY,WAAW,EAAE,WAAW;AACpC,YAAY,UAAU,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,aAAa,GAAG;AAC1D,YAAY,SAAS,EAAE,iBAAiB,EAAE,SAAS;AACnD,YAAY,0BAA0B,EAAE,0BAA0B;AAClE,SAAS,CAAC,CAAC;AACX,QAAQ,OAAO;AACf,YAAY,SAAS;AACrB,YAAY,cAAc;AAC1B,YAAY,cAAc;AAC1B,SAAS,CAAC;AACV,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB;AACA,QAAQ,OAAO,SAAS,CAAC;AACzB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,oBAAoB,GAAG,oBAAoB;;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleDeviceSRPAuth = void 0;
|
|
7
|
+
const cognitoIdentityProvider_1 = require("../../../foundation/factories/serviceClients/cognitoIdentityProvider");
|
|
8
|
+
const factories_1 = require("../factories");
|
|
9
|
+
const parsers_1 = require("../../../foundation/parsers");
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const srp_1 = require("./srp");
|
|
12
|
+
const BigInteger_1 = require("./srp/BigInteger");
|
|
13
|
+
const userContextData_1 = require("./userContextData");
|
|
14
|
+
async function handleDeviceSRPAuth({ username, config, clientMetadata, session, tokenOrchestrator, }) {
|
|
15
|
+
const { userPoolId, userPoolEndpoint } = config;
|
|
16
|
+
const clientId = config.userPoolClientId;
|
|
17
|
+
const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);
|
|
18
|
+
(0, types_1.assertDeviceMetadata)(deviceMetadata);
|
|
19
|
+
const authenticationHelper = await (0, srp_1.getAuthenticationHelper)(deviceMetadata.deviceGroupKey);
|
|
20
|
+
const challengeResponses = {
|
|
21
|
+
USERNAME: username,
|
|
22
|
+
SRP_A: authenticationHelper.A.toString(16),
|
|
23
|
+
DEVICE_KEY: deviceMetadata.deviceKey,
|
|
24
|
+
};
|
|
25
|
+
const jsonReqResponseChallenge = {
|
|
26
|
+
ChallengeName: 'DEVICE_SRP_AUTH',
|
|
27
|
+
ClientId: clientId,
|
|
28
|
+
ChallengeResponses: challengeResponses,
|
|
29
|
+
ClientMetadata: clientMetadata,
|
|
30
|
+
Session: session,
|
|
31
|
+
};
|
|
32
|
+
const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
|
|
33
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
34
|
+
endpointOverride: userPoolEndpoint,
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const { ChallengeParameters: respondedChallengeParameters, Session } = await respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReqResponseChallenge);
|
|
38
|
+
return handleDevicePasswordVerifier(username, respondedChallengeParameters, clientMetadata, Session, authenticationHelper, config, tokenOrchestrator);
|
|
39
|
+
}
|
|
40
|
+
exports.handleDeviceSRPAuth = handleDeviceSRPAuth;
|
|
41
|
+
async function handleDevicePasswordVerifier(username, challengeParameters, clientMetadata, session, authenticationHelper, { userPoolId, userPoolClientId, userPoolEndpoint }, tokenOrchestrator) {
|
|
42
|
+
const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);
|
|
43
|
+
(0, types_1.assertDeviceMetadata)(deviceMetadata);
|
|
44
|
+
const serverBValue = new BigInteger_1.BigInteger(challengeParameters?.SRP_B, 16);
|
|
45
|
+
const salt = new BigInteger_1.BigInteger(challengeParameters?.SALT, 16);
|
|
46
|
+
const { deviceKey } = deviceMetadata;
|
|
47
|
+
const { deviceGroupKey } = deviceMetadata;
|
|
48
|
+
const hkdf = await authenticationHelper.getPasswordAuthenticationKey({
|
|
49
|
+
username: deviceMetadata.deviceKey,
|
|
50
|
+
password: deviceMetadata.randomPassword,
|
|
51
|
+
serverBValue,
|
|
52
|
+
salt,
|
|
53
|
+
});
|
|
54
|
+
const dateNow = (0, srp_1.getNowString)();
|
|
55
|
+
const challengeResponses = {
|
|
56
|
+
USERNAME: challengeParameters?.USERNAME ?? username,
|
|
57
|
+
PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,
|
|
58
|
+
TIMESTAMP: dateNow,
|
|
59
|
+
PASSWORD_CLAIM_SIGNATURE: (0, srp_1.getSignatureString)({
|
|
60
|
+
username: deviceKey,
|
|
61
|
+
userPoolName: deviceGroupKey,
|
|
62
|
+
challengeParameters,
|
|
63
|
+
dateNow,
|
|
64
|
+
hkdf,
|
|
65
|
+
}),
|
|
66
|
+
DEVICE_KEY: deviceKey,
|
|
67
|
+
};
|
|
68
|
+
const UserContextData = (0, userContextData_1.getUserContextData)({
|
|
69
|
+
username,
|
|
70
|
+
userPoolId,
|
|
71
|
+
userPoolClientId,
|
|
72
|
+
});
|
|
73
|
+
const jsonReqResponseChallenge = {
|
|
74
|
+
ChallengeName: 'DEVICE_PASSWORD_VERIFIER',
|
|
75
|
+
ClientId: userPoolClientId,
|
|
76
|
+
ChallengeResponses: challengeResponses,
|
|
77
|
+
Session: session,
|
|
78
|
+
ClientMetadata: clientMetadata,
|
|
79
|
+
UserContextData,
|
|
80
|
+
};
|
|
81
|
+
const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
|
|
82
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
83
|
+
endpointOverride: userPoolEndpoint,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
return respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReqResponseChallenge);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=handleDeviceSRPAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleDeviceSRPAuth.js","sources":["../../../../../src/providers/cognito/utils/handleDeviceSRPAuth.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.handleDeviceSRPAuth = void 0;\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst factories_1 = require(\"../factories\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"./types\");\nconst srp_1 = require(\"./srp\");\nconst BigInteger_1 = require(\"./srp/BigInteger\");\nconst userContextData_1 = require(\"./userContextData\");\nasync function handleDeviceSRPAuth({ username, config, clientMetadata, session, tokenOrchestrator, }) {\n const { userPoolId, userPoolEndpoint } = config;\n const clientId = config.userPoolClientId;\n const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);\n (0, types_1.assertDeviceMetadata)(deviceMetadata);\n const authenticationHelper = await (0, srp_1.getAuthenticationHelper)(deviceMetadata.deviceGroupKey);\n const challengeResponses = {\n USERNAME: username,\n SRP_A: authenticationHelper.A.toString(16),\n DEVICE_KEY: deviceMetadata.deviceKey,\n };\n const jsonReqResponseChallenge = {\n ChallengeName: 'DEVICE_SRP_AUTH',\n ClientId: clientId,\n ChallengeResponses: challengeResponses,\n ClientMetadata: clientMetadata,\n Session: session,\n };\n const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { ChallengeParameters: respondedChallengeParameters, Session } = await respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReqResponseChallenge);\n return handleDevicePasswordVerifier(username, respondedChallengeParameters, clientMetadata, Session, authenticationHelper, config, tokenOrchestrator);\n}\nexports.handleDeviceSRPAuth = handleDeviceSRPAuth;\nasync function handleDevicePasswordVerifier(username, challengeParameters, clientMetadata, session, authenticationHelper, { userPoolId, userPoolClientId, userPoolEndpoint }, tokenOrchestrator) {\n const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);\n (0, types_1.assertDeviceMetadata)(deviceMetadata);\n const serverBValue = new BigInteger_1.BigInteger(challengeParameters?.SRP_B, 16);\n const salt = new BigInteger_1.BigInteger(challengeParameters?.SALT, 16);\n const { deviceKey } = deviceMetadata;\n const { deviceGroupKey } = deviceMetadata;\n const hkdf = await authenticationHelper.getPasswordAuthenticationKey({\n username: deviceMetadata.deviceKey,\n password: deviceMetadata.randomPassword,\n serverBValue,\n salt,\n });\n const dateNow = (0, srp_1.getNowString)();\n const challengeResponses = {\n USERNAME: challengeParameters?.USERNAME ?? username,\n PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,\n TIMESTAMP: dateNow,\n PASSWORD_CLAIM_SIGNATURE: (0, srp_1.getSignatureString)({\n username: deviceKey,\n userPoolName: deviceGroupKey,\n challengeParameters,\n dateNow,\n hkdf,\n }),\n DEVICE_KEY: deviceKey,\n };\n const UserContextData = (0, userContextData_1.getUserContextData)({\n username,\n userPoolId,\n userPoolClientId,\n });\n const jsonReqResponseChallenge = {\n ChallengeName: 'DEVICE_PASSWORD_VERIFIER',\n ClientId: userPoolClientId,\n ChallengeResponses: challengeResponses,\n Session: session,\n ClientMetadata: clientMetadata,\n UserContextData,\n };\n const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n return respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReqResponseChallenge);\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AACrC,MAAM,yBAAyB,GAAG,OAAO,CAAC,sEAAsE,CAAC,CAAC;AAClH,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACzD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACjD,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACvD,eAAe,mBAAmB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,EAAE;AACtG,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;AACpD,IAAI,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAC7C,IAAI,MAAM,cAAc,GAAG,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,QAA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,CAAC;AACV,QAAQ,UAAU,EAAE,SAAS;AAC7B,KAAK,CAAC;AACN,IAAI,MAAM,eAAe,GAAG,IAAI,iBAAiB,CAAC,kBAAkB,EAAE;AACtE,QAAQ,QAAQ;AAChB,QAAQ,UAAU;AAClB,QAAQ,gBAAgB;AACxB,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,wBAAwB,GAAG;AACrC,QAAQ,aAAa,EAAE,0BAA0B;AACjD,QAAQ,QAAQ,EAAE,gBAAgB;AAClC,QAAQ,kBAAkB,EAAE,kBAAkB;AAC9C,QAAQ,OAAO,EAAE,OAAO;AACxB,QAAQ,cAAc,EAAE,cAAc;AACtC,QAAQ,eAAe;AACvB,KAAK,CAAC;AACN,IAAI,MAAM,sBAAsB,GAAG,IAAI,yBAAyB,CAAC,kCAAkC,EAAE;AACrG,QAAQ,gBAAgB,EAAE,IAAI,WAAW,CAAC,qCAAqC,EAAE;AACjF,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,sBAAsB,CAAC,EAAE,MAAM,EAAE,IAAI,SAAS,CAAC,uBAAuB,EAAE,UAAU,CAAC,EAAE,EAAE,wBAAwB,CAAC,CAAC;AAC5H;;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handlePasswordVerifierChallenge = void 0;
|
|
7
|
+
const AuthError_1 = require("../../../errors/AuthError");
|
|
8
|
+
const cognitoIdentityProvider_1 = require("../../../foundation/factories/serviceClients/cognitoIdentityProvider");
|
|
9
|
+
const factories_1 = require("../factories");
|
|
10
|
+
const parsers_1 = require("../../../foundation/parsers");
|
|
11
|
+
const srp_1 = require("./srp");
|
|
12
|
+
const BigInteger_1 = require("./srp/BigInteger");
|
|
13
|
+
const userContextData_1 = require("./userContextData");
|
|
14
|
+
const handleDeviceSRPAuth_1 = require("./handleDeviceSRPAuth");
|
|
15
|
+
async function handlePasswordVerifierChallenge(password, challengeParameters, clientMetadata, session, authenticationHelper, config, tokenOrchestrator) {
|
|
16
|
+
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
17
|
+
const userPoolName = userPoolId?.split('_')[1] || '';
|
|
18
|
+
const serverBValue = new BigInteger_1.BigInteger(challengeParameters?.SRP_B, 16);
|
|
19
|
+
const salt = new BigInteger_1.BigInteger(challengeParameters?.SALT, 16);
|
|
20
|
+
const username = challengeParameters?.USER_ID_FOR_SRP;
|
|
21
|
+
if (!username)
|
|
22
|
+
throw new AuthError_1.AuthError({
|
|
23
|
+
name: 'EmptyUserIdForSRPException',
|
|
24
|
+
message: 'USER_ID_FOR_SRP was not found in challengeParameters',
|
|
25
|
+
});
|
|
26
|
+
const hkdf = await authenticationHelper.getPasswordAuthenticationKey({
|
|
27
|
+
username,
|
|
28
|
+
password,
|
|
29
|
+
serverBValue,
|
|
30
|
+
salt,
|
|
31
|
+
});
|
|
32
|
+
const dateNow = (0, srp_1.getNowString)();
|
|
33
|
+
const challengeResponses = {
|
|
34
|
+
USERNAME: username,
|
|
35
|
+
PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,
|
|
36
|
+
TIMESTAMP: dateNow,
|
|
37
|
+
PASSWORD_CLAIM_SIGNATURE: (0, srp_1.getSignatureString)({
|
|
38
|
+
username,
|
|
39
|
+
userPoolName,
|
|
40
|
+
challengeParameters,
|
|
41
|
+
dateNow,
|
|
42
|
+
hkdf,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
const deviceMetadata = await tokenOrchestrator.getDeviceMetadata(username);
|
|
46
|
+
if (deviceMetadata && deviceMetadata.deviceKey) {
|
|
47
|
+
challengeResponses.DEVICE_KEY = deviceMetadata.deviceKey;
|
|
48
|
+
}
|
|
49
|
+
const UserContextData = (0, userContextData_1.getUserContextData)({
|
|
50
|
+
username,
|
|
51
|
+
userPoolId,
|
|
52
|
+
userPoolClientId,
|
|
53
|
+
});
|
|
54
|
+
const jsonReqResponseChallenge = {
|
|
55
|
+
ChallengeName: 'PASSWORD_VERIFIER',
|
|
56
|
+
ChallengeResponses: challengeResponses,
|
|
57
|
+
ClientMetadata: clientMetadata,
|
|
58
|
+
Session: session,
|
|
59
|
+
ClientId: userPoolClientId,
|
|
60
|
+
UserContextData,
|
|
61
|
+
};
|
|
62
|
+
const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({
|
|
63
|
+
endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({
|
|
64
|
+
endpointOverride: userPoolEndpoint,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
const response = await respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReqResponseChallenge);
|
|
68
|
+
if (response.ChallengeName === 'DEVICE_SRP_AUTH')
|
|
69
|
+
return (0, handleDeviceSRPAuth_1.handleDeviceSRPAuth)({
|
|
70
|
+
username,
|
|
71
|
+
config,
|
|
72
|
+
clientMetadata,
|
|
73
|
+
session: response.Session,
|
|
74
|
+
tokenOrchestrator,
|
|
75
|
+
});
|
|
76
|
+
return response;
|
|
77
|
+
}
|
|
78
|
+
exports.handlePasswordVerifierChallenge = handlePasswordVerifierChallenge;
|
|
79
|
+
//# sourceMappingURL=handlePasswordVerifierChallenge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePasswordVerifierChallenge.js","sources":["../../../../../src/providers/cognito/utils/handlePasswordVerifierChallenge.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.handlePasswordVerifierChallenge = void 0;\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst factories_1 = require(\"../factories\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst srp_1 = require(\"./srp\");\nconst BigInteger_1 = require(\"./srp/BigInteger\");\nconst userContextData_1 = require(\"./userContextData\");\nconst handleDeviceSRPAuth_1 = require(\"./handleDeviceSRPAuth\");\nasync function handlePasswordVerifierChallenge(password, challengeParameters, clientMetadata, session, authenticationHelper, config, tokenOrchestrator) {\n const { userPoolId, userPoolClientId, userPoolEndpoint } = config;\n const userPoolName = userPoolId?.split('_')[1] || '';\n const serverBValue = new BigInteger_1.BigInteger(challengeParameters?.SRP_B, 16);\n const salt = new BigInteger_1.BigInteger(challengeParameters?.SALT, 16);\n const username = challengeParameters?.USER_ID_FOR_SRP;\n if (!username)\n throw new AuthError_1.AuthError({\n name: 'EmptyUserIdForSRPException',\n message: 'USER_ID_FOR_SRP was not found in challengeParameters',\n });\n const hkdf = await authenticationHelper.getPasswordAuthenticationKey({\n username,\n password,\n serverBValue,\n salt,\n });\n const dateNow = (0, srp_1.getNowString)();\n const challengeResponses = {\n USERNAME: username,\n PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,\n TIMESTAMP: dateNow,\n PASSWORD_CLAIM_SIGNATURE: (0, srp_1.getSignatureString)({\n username,\n userPoolName,\n challengeParameters,\n dateNow,\n hkdf,\n }),\n };\n const deviceMetadata = await tokenOrchestrator.getDeviceMetadata(username);\n if (deviceMetadata && deviceMetadata.deviceKey) {\n challengeResponses.DEVICE_KEY = deviceMetadata.deviceKey;\n }\n const UserContextData = (0, userContextData_1.getUserContextData)({\n username,\n userPoolId,\n userPoolClientId,\n });\n const jsonReqResponseChallenge = {\n ChallengeName: 'PASSWORD_VERIFIER',\n ChallengeResponses: challengeResponses,\n ClientMetadata: clientMetadata,\n Session: session,\n ClientId: userPoolClientId,\n UserContextData,\n };\n const respondToAuthChallenge = (0, cognitoIdentityProvider_1.createRespondToAuthChallengeClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const response = await respondToAuthChallenge({ region: (0, parsers_1.getRegionFromUserPoolId)(userPoolId) }, jsonReqResponseChallenge);\n if (response.ChallengeName === 'DEVICE_SRP_AUTH')\n return (0, handleDeviceSRPAuth_1.handleDeviceSRPAuth)({\n username,\n config,\n clientMetadata,\n session: response.Session,\n tokenOrchestrator,\n });\n return response;\n}\nexports.handlePasswordVerifierChallenge = handlePasswordVerifierChallenge;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,+BAA+B,GAAG,KAAK,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,yBAAyB,GAAG,OAAO,CAAC,sEAAsE,CAAC,CAAC;AAClH,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACzD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACjD,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACvD,MAAM,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAC/D,eAAe,+BAA+B,CAAC,QAAQ,EAAE,mBAAmB,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,iBAAiB,EAAE;AACxJ,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;AAC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
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.retryOnResourceNotFoundException = void 0;
|
|
7
|
+
const AuthError_1 = require("../../../errors/AuthError");
|
|
8
|
+
/**
|
|
9
|
+
* It will retry the function if the error is a `ResourceNotFoundException` and
|
|
10
|
+
* will clean the device keys stored in the storage mechanism.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
async function retryOnResourceNotFoundException(func, args, username, tokenOrchestrator) {
|
|
14
|
+
try {
|
|
15
|
+
return await func(...args);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof AuthError_1.AuthError &&
|
|
19
|
+
error.name === 'ResourceNotFoundException' &&
|
|
20
|
+
error.message.includes('Device does not exist.')) {
|
|
21
|
+
await tokenOrchestrator.clearDeviceMetadata(username);
|
|
22
|
+
return func(...args);
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.retryOnResourceNotFoundException = retryOnResourceNotFoundException;
|
|
28
|
+
//# sourceMappingURL=retryOnResourceNotFoundException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryOnResourceNotFoundException.js","sources":["../../../../../src/providers/cognito/utils/retryOnResourceNotFoundException.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.retryOnResourceNotFoundException = void 0;\nconst AuthError_1 = require(\"../../../errors/AuthError\");\n/**\n * It will retry the function if the error is a `ResourceNotFoundException` and\n * will clean the device keys stored in the storage mechanism.\n *\n */\nasync function retryOnResourceNotFoundException(func, args, username, tokenOrchestrator) {\n try {\n return await func(...args);\n }\n catch (error) {\n if (error instanceof AuthError_1.AuthError &&\n error.name === 'ResourceNotFoundException' &&\n error.message.includes('Device does not exist.')) {\n await tokenOrchestrator.clearDeviceMetadata(username);\n return func(...args);\n }\n throw error;\n }\n}\nexports.retryOnResourceNotFoundException = retryOnResourceNotFoundException;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC,CAAC;AAClD,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD;AACA;AACA;AACA;AACA;AACA,eAAe,gCAAgC,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE;AACzF,IAAI,IAAI;AACR,QAAQ,OAAO,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AACnC,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,YAAY,WAAW,CAAC,SAAS;AAClD,YAAY,KAAK,CAAC,IAAI,KAAK,2BAA2B;AACtD,YAAY,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE;AAC9D,YAAY,MAAM,iBAAiB,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAClE,YAAY,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AACjC,SAAS;AACT,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,gCAAgC,GAAG,gCAAgC;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setActiveSignInUsername = void 0;
|
|
7
|
+
const store_1 = require("../../../client/utils/store");
|
|
8
|
+
function setActiveSignInUsername(username) {
|
|
9
|
+
const { dispatch } = store_1.signInStore;
|
|
10
|
+
dispatch({ type: 'SET_USERNAME', value: username });
|
|
11
|
+
}
|
|
12
|
+
exports.setActiveSignInUsername = setActiveSignInUsername;
|
|
13
|
+
//# sourceMappingURL=setActiveSignInUsername.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setActiveSignInUsername.js","sources":["../../../../../src/providers/cognito/utils/setActiveSignInUsername.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.setActiveSignInUsername = void 0;\nconst store_1 = require(\"../../../client/utils/store\");\nfunction setActiveSignInUsername(username) {\n const { dispatch } = store_1.signInStore;\n dispatch({ type: 'SET_USERNAME', value: username });\n}\nexports.setActiveSignInUsername = setActiveSignInUsername;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,uBAAuB,GAAG,KAAK,CAAC,CAAC;AACzC,MAAM,OAAO,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACvD,SAAS,uBAAuB,CAAC,QAAQ,EAAE;AAC3C,IAAI,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;AAC7C,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AACxD,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB;;"}
|