@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.
Files changed (99) hide show
  1. package/dist/cjs/client/flows/shared/handlePasswordSRP.js +5 -3
  2. package/dist/cjs/client/flows/shared/handlePasswordSRP.js.map +1 -1
  3. package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPassword.js +2 -2
  4. package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPassword.js.map +1 -1
  5. package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.js +5 -3
  6. package/dist/cjs/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.js.map +1 -1
  7. package/dist/cjs/client/flows/userAuth/handleUserAuthFlow.js +2 -2
  8. package/dist/cjs/client/flows/userAuth/handleUserAuthFlow.js.map +1 -1
  9. package/dist/cjs/client/flows/userAuth/handleWebAuthnSignInResult.js +4 -4
  10. package/dist/cjs/client/flows/userAuth/handleWebAuthnSignInResult.js.map +1 -1
  11. package/dist/cjs/client/flows/userAuth/types.js +6 -0
  12. package/dist/cjs/client/flows/userAuth/types.js.map +1 -0
  13. package/dist/cjs/providers/cognito/apis/confirmSignIn.js +2 -1
  14. package/dist/cjs/providers/cognito/apis/confirmSignIn.js.map +1 -1
  15. package/dist/cjs/providers/cognito/apis/signInWithCustomAuth.js +4 -2
  16. package/dist/cjs/providers/cognito/apis/signInWithCustomAuth.js.map +1 -1
  17. package/dist/cjs/providers/cognito/apis/signInWithCustomSRPAuth.js +2 -1
  18. package/dist/cjs/providers/cognito/apis/signInWithCustomSRPAuth.js.map +1 -1
  19. package/dist/cjs/providers/cognito/apis/signInWithSRP.js +2 -1
  20. package/dist/cjs/providers/cognito/apis/signInWithSRP.js.map +1 -1
  21. package/dist/cjs/providers/cognito/apis/signInWithUserAuth.js +2 -1
  22. package/dist/cjs/providers/cognito/apis/signInWithUserAuth.js.map +1 -1
  23. package/dist/cjs/providers/cognito/apis/signInWithUserPassword.js +4 -2
  24. package/dist/cjs/providers/cognito/apis/signInWithUserPassword.js.map +1 -1
  25. package/dist/cjs/providers/cognito/utils/getNewDeviceMetadata.js +64 -0
  26. package/dist/cjs/providers/cognito/utils/getNewDeviceMetadata.js.map +1 -0
  27. package/dist/cjs/providers/cognito/utils/handleDeviceSRPAuth.js +88 -0
  28. package/dist/cjs/providers/cognito/utils/handleDeviceSRPAuth.js.map +1 -0
  29. package/dist/cjs/providers/cognito/utils/handlePasswordVerifierChallenge.js +79 -0
  30. package/dist/cjs/providers/cognito/utils/handlePasswordVerifierChallenge.js.map +1 -0
  31. package/dist/cjs/providers/cognito/utils/retryOnResourceNotFoundException.js +28 -0
  32. package/dist/cjs/providers/cognito/utils/retryOnResourceNotFoundException.js.map +1 -0
  33. package/dist/cjs/providers/cognito/utils/setActiveSignInUsername.js +13 -0
  34. package/dist/cjs/providers/cognito/utils/setActiveSignInUsername.js.map +1 -0
  35. package/dist/cjs/providers/cognito/utils/signInHelpers.js +23 -227
  36. package/dist/cjs/providers/cognito/utils/signInHelpers.js.map +1 -1
  37. package/dist/esm/client/flows/shared/handlePasswordSRP.mjs +3 -1
  38. package/dist/esm/client/flows/shared/handlePasswordSRP.mjs.map +1 -1
  39. package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPassword.mjs +1 -1
  40. package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPassword.mjs.map +1 -1
  41. package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.mjs +3 -1
  42. package/dist/esm/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.mjs.map +1 -1
  43. package/dist/esm/client/flows/userAuth/handleUserAuthFlow.mjs +1 -1
  44. package/dist/esm/client/flows/userAuth/handleUserAuthFlow.mjs.map +1 -1
  45. package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.d.ts +2 -2
  46. package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.mjs +3 -3
  47. package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.mjs.map +1 -1
  48. package/dist/esm/client/flows/userAuth/types.d.ts +6 -0
  49. package/dist/esm/client/flows/userAuth/types.mjs +2 -0
  50. package/dist/esm/client/flows/userAuth/types.mjs.map +1 -0
  51. package/dist/esm/providers/cognito/apis/confirmSignIn.mjs +2 -1
  52. package/dist/esm/providers/cognito/apis/confirmSignIn.mjs.map +1 -1
  53. package/dist/esm/providers/cognito/apis/signInWithCustomAuth.mjs +3 -1
  54. package/dist/esm/providers/cognito/apis/signInWithCustomAuth.mjs.map +1 -1
  55. package/dist/esm/providers/cognito/apis/signInWithCustomSRPAuth.mjs +2 -1
  56. package/dist/esm/providers/cognito/apis/signInWithCustomSRPAuth.mjs.map +1 -1
  57. package/dist/esm/providers/cognito/apis/signInWithSRP.mjs +2 -1
  58. package/dist/esm/providers/cognito/apis/signInWithSRP.mjs.map +1 -1
  59. package/dist/esm/providers/cognito/apis/signInWithUserAuth.mjs +2 -1
  60. package/dist/esm/providers/cognito/apis/signInWithUserAuth.mjs.map +1 -1
  61. package/dist/esm/providers/cognito/apis/signInWithUserPassword.mjs +3 -1
  62. package/dist/esm/providers/cognito/apis/signInWithUserPassword.mjs.map +1 -1
  63. package/dist/esm/providers/cognito/utils/getNewDeviceMetadata.d.ts +17 -0
  64. package/dist/esm/providers/cognito/utils/getNewDeviceMetadata.mjs +71 -0
  65. package/dist/esm/providers/cognito/utils/getNewDeviceMetadata.mjs.map +1 -0
  66. package/dist/esm/providers/cognito/utils/handleDeviceSRPAuth.d.ts +13 -0
  67. package/dist/esm/providers/cognito/utils/handleDeviceSRPAuth.mjs +97 -0
  68. package/dist/esm/providers/cognito/utils/handleDeviceSRPAuth.mjs.map +1 -0
  69. package/dist/esm/providers/cognito/utils/handlePasswordVerifierChallenge.d.ts +6 -0
  70. package/dist/esm/providers/cognito/utils/handlePasswordVerifierChallenge.mjs +88 -0
  71. package/dist/esm/providers/cognito/utils/handlePasswordVerifierChallenge.mjs.map +1 -0
  72. package/dist/esm/providers/cognito/utils/retryOnResourceNotFoundException.d.ts +7 -0
  73. package/dist/esm/providers/cognito/utils/retryOnResourceNotFoundException.mjs +26 -0
  74. package/dist/esm/providers/cognito/utils/retryOnResourceNotFoundException.mjs.map +1 -0
  75. package/dist/esm/providers/cognito/utils/setActiveSignInUsername.d.ts +1 -0
  76. package/dist/esm/providers/cognito/utils/setActiveSignInUsername.mjs +12 -0
  77. package/dist/esm/providers/cognito/utils/setActiveSignInUsername.mjs.map +1 -0
  78. package/dist/esm/providers/cognito/utils/signInHelpers.d.ts +2 -26
  79. package/dist/esm/providers/cognito/utils/signInHelpers.mjs +18 -220
  80. package/dist/esm/providers/cognito/utils/signInHelpers.mjs.map +1 -1
  81. package/package.json +106 -106
  82. package/src/client/flows/shared/handlePasswordSRP.ts +3 -5
  83. package/src/client/flows/userAuth/handleSelectChallengeWithPassword.ts +1 -1
  84. package/src/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.ts +3 -5
  85. package/src/client/flows/userAuth/handleUserAuthFlow.ts +1 -1
  86. package/src/client/flows/userAuth/handleWebAuthnSignInResult.ts +6 -8
  87. package/src/client/flows/userAuth/types.ts +15 -0
  88. package/src/providers/cognito/apis/confirmSignIn.ts +1 -1
  89. package/src/providers/cognito/apis/signInWithCustomAuth.ts +2 -2
  90. package/src/providers/cognito/apis/signInWithCustomSRPAuth.ts +1 -1
  91. package/src/providers/cognito/apis/signInWithSRP.ts +1 -1
  92. package/src/providers/cognito/apis/signInWithUserAuth.ts +1 -1
  93. package/src/providers/cognito/apis/signInWithUserPassword.ts +2 -2
  94. package/src/providers/cognito/utils/getNewDeviceMetadata.ts +88 -0
  95. package/src/providers/cognito/utils/handleDeviceSRPAuth.ts +146 -0
  96. package/src/providers/cognito/utils/handlePasswordVerifierChallenge.ts +106 -0
  97. package/src/providers/cognito/utils/retryOnResourceNotFoundException.ts +34 -0
  98. package/src/providers/cognito/utils/setActiveSignInUsername.ts +10 -0
  99. package/src/providers/cognito/utils/signInHelpers.ts +19 -327
@@ -0,0 +1,17 @@
1
+ import { DeviceMetadata } from '../tokenProvider/types';
2
+ import { NewDeviceMetadataType } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
3
+ /**
4
+ * This function is used to kick off the device management flow.
5
+ *
6
+ * If an error is thrown while generating a hash device or calling the `ConfirmDevice`
7
+ * client, then this API will ignore the error and return undefined. Otherwise the authentication
8
+ * flow will not complete and the user won't be able to be signed in.
9
+ *
10
+ * @returns DeviceMetadata | undefined
11
+ */
12
+ export declare function getNewDeviceMetadata({ userPoolId, userPoolEndpoint, newDeviceMetadata, accessToken, }: {
13
+ userPoolId: string;
14
+ userPoolEndpoint: string | undefined;
15
+ newDeviceMetadata?: NewDeviceMetadataType;
16
+ accessToken?: string;
17
+ }): Promise<DeviceMetadata | undefined>;
@@ -0,0 +1,71 @@
1
+ import { base64Encoder, getDeviceName } from '@aws-amplify/core/internals/utils';
2
+ import '@aws-amplify/core/internals/aws-client-utils/composers';
3
+ import '@aws-amplify/core/internals/aws-client-utils';
4
+ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/shared/handler/cognitoUserPoolTransferHandler.mjs';
5
+ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/constants.mjs';
6
+ import '../../../common/AuthErrorStrings.mjs';
7
+ import '../../../errors/types/validation.mjs';
8
+ import '../types/errors.mjs';
9
+ import { createConfirmDeviceClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/createConfirmDeviceClient.mjs';
10
+ import { createCognitoUserPoolEndpointResolver } from '../factories/createCognitoUserPoolEndpointResolver.mjs';
11
+ import { getRegionFromUserPoolId } from '../../../foundation/parsers/regionParsers.mjs';
12
+ import { getAuthenticationHelper } from './srp/getAuthenticationHelper.mjs';
13
+ import { getBytesFromHex } from './srp/getBytesFromHex.mjs';
14
+ import '@aws-crypto/sha256-js';
15
+
16
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
17
+ // SPDX-License-Identifier: Apache-2.0
18
+ /**
19
+ * This function is used to kick off the device management flow.
20
+ *
21
+ * If an error is thrown while generating a hash device or calling the `ConfirmDevice`
22
+ * client, then this API will ignore the error and return undefined. Otherwise the authentication
23
+ * flow will not complete and the user won't be able to be signed in.
24
+ *
25
+ * @returns DeviceMetadata | undefined
26
+ */
27
+ async function getNewDeviceMetadata({ userPoolId, userPoolEndpoint, newDeviceMetadata, accessToken, }) {
28
+ if (!newDeviceMetadata)
29
+ return undefined;
30
+ const userPoolName = userPoolId.split('_')[1] || '';
31
+ const authenticationHelper = await getAuthenticationHelper(userPoolName);
32
+ const deviceKey = newDeviceMetadata?.DeviceKey;
33
+ const deviceGroupKey = newDeviceMetadata?.DeviceGroupKey;
34
+ try {
35
+ await authenticationHelper.generateHashDevice(deviceGroupKey ?? '', deviceKey ?? '');
36
+ }
37
+ catch (errGenHash) {
38
+ // TODO: log error here
39
+ return undefined;
40
+ }
41
+ const deviceSecretVerifierConfig = {
42
+ Salt: base64Encoder.convert(getBytesFromHex(authenticationHelper.getSaltToHashDevices())),
43
+ PasswordVerifier: base64Encoder.convert(getBytesFromHex(authenticationHelper.getVerifierDevices())),
44
+ };
45
+ const randomPassword = authenticationHelper.getRandomPassword();
46
+ try {
47
+ const confirmDevice = createConfirmDeviceClient({
48
+ endpointResolver: createCognitoUserPoolEndpointResolver({
49
+ endpointOverride: userPoolEndpoint,
50
+ }),
51
+ });
52
+ await confirmDevice({ region: getRegionFromUserPoolId(userPoolId) }, {
53
+ AccessToken: accessToken,
54
+ DeviceName: await getDeviceName(),
55
+ DeviceKey: newDeviceMetadata?.DeviceKey,
56
+ DeviceSecretVerifierConfig: deviceSecretVerifierConfig,
57
+ });
58
+ return {
59
+ deviceKey,
60
+ deviceGroupKey,
61
+ randomPassword,
62
+ };
63
+ }
64
+ catch (error) {
65
+ // TODO: log error here
66
+ return undefined;
67
+ }
68
+ }
69
+
70
+ export { getNewDeviceMetadata };
71
+ //# sourceMappingURL=getNewDeviceMetadata.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNewDeviceMetadata.mjs","sources":["../../../../../src/providers/cognito/utils/getNewDeviceMetadata.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { base64Encoder, getDeviceName, } from '@aws-amplify/core/internals/utils';\nimport { createConfirmDeviceClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { getAuthenticationHelper, getBytesFromHex } from './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 */\nexport async function getNewDeviceMetadata({ userPoolId, userPoolEndpoint, newDeviceMetadata, accessToken, }) {\n if (!newDeviceMetadata)\n return undefined;\n const userPoolName = userPoolId.split('_')[1] || '';\n const authenticationHelper = await 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: base64Encoder.convert(getBytesFromHex(authenticationHelper.getSaltToHashDevices())),\n PasswordVerifier: base64Encoder.convert(getBytesFromHex(authenticationHelper.getVerifierDevices())),\n };\n const randomPassword = authenticationHelper.getRandomPassword();\n try {\n const confirmDevice = createConfirmDeviceClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n await confirmDevice({ region: getRegionFromUserPoolId(userPoolId) }, {\n AccessToken: accessToken,\n DeviceName: await 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}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,oBAAoB,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,GAAG,EAAE;AAC9G,IAAI,IAAI,CAAC,iBAAiB;AAC1B,QAAQ,OAAO,SAAS,CAAC;AACzB,IAAI,MAAM,YAAY,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACxD,IAAI,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CAAC,YAAY,CAAC,CAAC;AAC7E,IAAI,MAAM,SAAS,GAAG,iBAAiB,EAAE,SAAS,CAAC;AACnD,IAAI,MAAM,cAAc,GAAG,iBAAiB,EAAE,cAAc,CAAC;AAC7D,IAAI,IAAI;AACR,QAAQ,MAAM,oBAAoB,CAAC,kBAAkB,CAAC,cAAc,IAAI,EAAE,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;AAC7F,KAAK;AACL,IAAI,OAAO,UAAU,EAAE;AACvB;AACA,QAAQ,OAAO,SAAS,CAAC;AACzB,KAAK;AACL,IAAI,MAAM,0BAA0B,GAAG;AACvC,QAAQ,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,oBAAoB,EAAE,CAAC,CAAC;AACjG,QAAQ,gBAAgB,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,CAAC;AAC3G,KAAK,CAAC;AACN,IAAI,MAAM,cAAc,GAAG,oBAAoB,CAAC,iBAAiB,EAAE,CAAC;AACpE,IAAI,IAAI;AACR,QAAQ,MAAM,aAAa,GAAG,yBAAyB,CAAC;AACxD,YAAY,gBAAgB,EAAE,qCAAqC,CAAC;AACpE,gBAAgB,gBAAgB,EAAE,gBAAgB;AAClD,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,aAAa,CAAC,EAAE,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC,EAAE,EAAE;AAC7E,YAAY,WAAW,EAAE,WAAW;AACpC,YAAY,UAAU,EAAE,MAAM,aAAa,EAAE;AAC7C,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;;;;"}
@@ -0,0 +1,13 @@
1
+ import { CognitoUserPoolConfig } from '@aws-amplify/core';
2
+ import { ClientMetadata } from '../types';
3
+ import { AuthTokenOrchestrator } from '../tokenProvider/types';
4
+ import { RespondToAuthChallengeCommandOutput } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
5
+ interface HandleDeviceSRPInput {
6
+ username: string;
7
+ config: CognitoUserPoolConfig;
8
+ clientMetadata: ClientMetadata | undefined;
9
+ session: string | undefined;
10
+ tokenOrchestrator?: AuthTokenOrchestrator;
11
+ }
12
+ export declare function handleDeviceSRPAuth({ username, config, clientMetadata, session, tokenOrchestrator, }: HandleDeviceSRPInput): Promise<RespondToAuthChallengeCommandOutput>;
13
+ export {};
@@ -0,0 +1,97 @@
1
+ import '@aws-amplify/core/internals/aws-client-utils/composers';
2
+ import '@aws-amplify/core/internals/aws-client-utils';
3
+ import '@aws-amplify/core/internals/utils';
4
+ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/shared/handler/cognitoUserPoolTransferHandler.mjs';
5
+ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/constants.mjs';
6
+ import '../../../common/AuthErrorStrings.mjs';
7
+ import '../../../errors/types/validation.mjs';
8
+ import '../types/errors.mjs';
9
+ import { createRespondToAuthChallengeClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/createRespondToAuthChallengeClient.mjs';
10
+ import { createCognitoUserPoolEndpointResolver } from '../factories/createCognitoUserPoolEndpointResolver.mjs';
11
+ import { getRegionFromUserPoolId } from '../../../foundation/parsers/regionParsers.mjs';
12
+ import { assertDeviceMetadata } from './types.mjs';
13
+ import { getAuthenticationHelper } from './srp/getAuthenticationHelper.mjs';
14
+ import './srp/constants.mjs';
15
+ import { getNowString } from './srp/getNowString.mjs';
16
+ import { getSignatureString } from './srp/getSignatureString.mjs';
17
+ import BigInteger from './srp/BigInteger/BigInteger.mjs';
18
+ import { getUserContextData } from './userContextData.mjs';
19
+
20
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
21
+ // SPDX-License-Identifier: Apache-2.0
22
+ async function handleDeviceSRPAuth({ username, config, clientMetadata, session, tokenOrchestrator, }) {
23
+ const { userPoolId, userPoolEndpoint } = config;
24
+ const clientId = config.userPoolClientId;
25
+ const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);
26
+ assertDeviceMetadata(deviceMetadata);
27
+ const authenticationHelper = await getAuthenticationHelper(deviceMetadata.deviceGroupKey);
28
+ const challengeResponses = {
29
+ USERNAME: username,
30
+ SRP_A: authenticationHelper.A.toString(16),
31
+ DEVICE_KEY: deviceMetadata.deviceKey,
32
+ };
33
+ const jsonReqResponseChallenge = {
34
+ ChallengeName: 'DEVICE_SRP_AUTH',
35
+ ClientId: clientId,
36
+ ChallengeResponses: challengeResponses,
37
+ ClientMetadata: clientMetadata,
38
+ Session: session,
39
+ };
40
+ const respondToAuthChallenge = createRespondToAuthChallengeClient({
41
+ endpointResolver: createCognitoUserPoolEndpointResolver({
42
+ endpointOverride: userPoolEndpoint,
43
+ }),
44
+ });
45
+ const { ChallengeParameters: respondedChallengeParameters, Session } = await respondToAuthChallenge({ region: getRegionFromUserPoolId(userPoolId) }, jsonReqResponseChallenge);
46
+ return handleDevicePasswordVerifier(username, respondedChallengeParameters, clientMetadata, Session, authenticationHelper, config, tokenOrchestrator);
47
+ }
48
+ async function handleDevicePasswordVerifier(username, challengeParameters, clientMetadata, session, authenticationHelper, { userPoolId, userPoolClientId, userPoolEndpoint }, tokenOrchestrator) {
49
+ const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);
50
+ assertDeviceMetadata(deviceMetadata);
51
+ const serverBValue = new BigInteger(challengeParameters?.SRP_B, 16);
52
+ const salt = new BigInteger(challengeParameters?.SALT, 16);
53
+ const { deviceKey } = deviceMetadata;
54
+ const { deviceGroupKey } = deviceMetadata;
55
+ const hkdf = await authenticationHelper.getPasswordAuthenticationKey({
56
+ username: deviceMetadata.deviceKey,
57
+ password: deviceMetadata.randomPassword,
58
+ serverBValue,
59
+ salt,
60
+ });
61
+ const dateNow = getNowString();
62
+ const challengeResponses = {
63
+ USERNAME: challengeParameters?.USERNAME ?? username,
64
+ PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,
65
+ TIMESTAMP: dateNow,
66
+ PASSWORD_CLAIM_SIGNATURE: getSignatureString({
67
+ username: deviceKey,
68
+ userPoolName: deviceGroupKey,
69
+ challengeParameters,
70
+ dateNow,
71
+ hkdf,
72
+ }),
73
+ DEVICE_KEY: deviceKey,
74
+ };
75
+ const UserContextData = getUserContextData({
76
+ username,
77
+ userPoolId,
78
+ userPoolClientId,
79
+ });
80
+ const jsonReqResponseChallenge = {
81
+ ChallengeName: 'DEVICE_PASSWORD_VERIFIER',
82
+ ClientId: userPoolClientId,
83
+ ChallengeResponses: challengeResponses,
84
+ Session: session,
85
+ ClientMetadata: clientMetadata,
86
+ UserContextData,
87
+ };
88
+ const respondToAuthChallenge = createRespondToAuthChallengeClient({
89
+ endpointResolver: createCognitoUserPoolEndpointResolver({
90
+ endpointOverride: userPoolEndpoint,
91
+ }),
92
+ });
93
+ return respondToAuthChallenge({ region: getRegionFromUserPoolId(userPoolId) }, jsonReqResponseChallenge);
94
+ }
95
+
96
+ export { handleDeviceSRPAuth };
97
+ //# sourceMappingURL=handleDeviceSRPAuth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleDeviceSRPAuth.mjs","sources":["../../../../../src/providers/cognito/utils/handleDeviceSRPAuth.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createRespondToAuthChallengeClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { assertDeviceMetadata } from './types';\nimport { getAuthenticationHelper, getNowString, getSignatureString, } from './srp';\nimport { BigInteger } from './srp/BigInteger';\nimport { getUserContextData } from './userContextData';\nexport async 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 assertDeviceMetadata(deviceMetadata);\n const authenticationHelper = await 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 = createRespondToAuthChallengeClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { ChallengeParameters: respondedChallengeParameters, Session } = await respondToAuthChallenge({ region: getRegionFromUserPoolId(userPoolId) }, jsonReqResponseChallenge);\n return handleDevicePasswordVerifier(username, respondedChallengeParameters, clientMetadata, Session, authenticationHelper, config, tokenOrchestrator);\n}\nasync function handleDevicePasswordVerifier(username, challengeParameters, clientMetadata, session, authenticationHelper, { userPoolId, userPoolClientId, userPoolEndpoint }, tokenOrchestrator) {\n const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata(username);\n assertDeviceMetadata(deviceMetadata);\n const serverBValue = new BigInteger(challengeParameters?.SRP_B, 16);\n const salt = new 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 = getNowString();\n const challengeResponses = {\n USERNAME: challengeParameters?.USERNAME ?? username,\n PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,\n TIMESTAMP: dateNow,\n PASSWORD_CLAIM_SIGNATURE: getSignatureString({\n username: deviceKey,\n userPoolName: deviceGroupKey,\n challengeParameters,\n dateNow,\n hkdf,\n }),\n DEVICE_KEY: deviceKey,\n };\n const UserContextData = 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 = createRespondToAuthChallengeClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n return respondToAuthChallenge({ region: getRegionFromUserPoolId(userPoolId) }, jsonReqResponseChallenge);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AAQO,eAAe,mBAAmB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE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S,CAAC;AACV,QAAQ,UAAU,EAAE,SAAS;AAC7B,KAAK,CAAC;AACN,IAAI,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAC/C,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,kCAAkC,CAAC;AACtE,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,sBAAsB,CAAC,EAAE,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC,EAAE,EAAE,wBAAwB,CAAC,CAAC;AAC7G;;;;"}
@@ -0,0 +1,6 @@
1
+ import { CognitoUserPoolConfig } from '@aws-amplify/core';
2
+ import { ClientMetadata } from '../types';
3
+ import { AuthTokenOrchestrator } from '../tokenProvider/types';
4
+ import { ChallengeParameters, RespondToAuthChallengeCommandOutput } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
5
+ import { AuthenticationHelper } from './srp/AuthenticationHelper';
6
+ export declare function handlePasswordVerifierChallenge(password: string, challengeParameters: ChallengeParameters, clientMetadata: ClientMetadata | undefined, session: string | undefined, authenticationHelper: AuthenticationHelper, config: CognitoUserPoolConfig, tokenOrchestrator: AuthTokenOrchestrator): Promise<RespondToAuthChallengeCommandOutput>;
@@ -0,0 +1,88 @@
1
+ import { AuthError } from '../../../errors/AuthError.mjs';
2
+ import '@aws-amplify/core/internals/aws-client-utils/composers';
3
+ import '@aws-amplify/core/internals/aws-client-utils';
4
+ import '@aws-amplify/core/internals/utils';
5
+ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/shared/handler/cognitoUserPoolTransferHandler.mjs';
6
+ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/constants.mjs';
7
+ import '../../../common/AuthErrorStrings.mjs';
8
+ import '../../../errors/types/validation.mjs';
9
+ import '../types/errors.mjs';
10
+ import { createRespondToAuthChallengeClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/createRespondToAuthChallengeClient.mjs';
11
+ import { createCognitoUserPoolEndpointResolver } from '../factories/createCognitoUserPoolEndpointResolver.mjs';
12
+ import { getRegionFromUserPoolId } from '../../../foundation/parsers/regionParsers.mjs';
13
+ import BigInteger from './srp/BigInteger/BigInteger.mjs';
14
+ import './srp/constants.mjs';
15
+ import '@aws-crypto/sha256-js';
16
+ import { getNowString } from './srp/getNowString.mjs';
17
+ import { getSignatureString } from './srp/getSignatureString.mjs';
18
+ import { getUserContextData } from './userContextData.mjs';
19
+ import { handleDeviceSRPAuth } from './handleDeviceSRPAuth.mjs';
20
+
21
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
+ // SPDX-License-Identifier: Apache-2.0
23
+ async function handlePasswordVerifierChallenge(password, challengeParameters, clientMetadata, session, authenticationHelper, config, tokenOrchestrator) {
24
+ const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
25
+ const userPoolName = userPoolId?.split('_')[1] || '';
26
+ const serverBValue = new BigInteger(challengeParameters?.SRP_B, 16);
27
+ const salt = new BigInteger(challengeParameters?.SALT, 16);
28
+ const username = challengeParameters?.USER_ID_FOR_SRP;
29
+ if (!username)
30
+ throw new AuthError({
31
+ name: 'EmptyUserIdForSRPException',
32
+ message: 'USER_ID_FOR_SRP was not found in challengeParameters',
33
+ });
34
+ const hkdf = await authenticationHelper.getPasswordAuthenticationKey({
35
+ username,
36
+ password,
37
+ serverBValue,
38
+ salt,
39
+ });
40
+ const dateNow = getNowString();
41
+ const challengeResponses = {
42
+ USERNAME: username,
43
+ PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,
44
+ TIMESTAMP: dateNow,
45
+ PASSWORD_CLAIM_SIGNATURE: getSignatureString({
46
+ username,
47
+ userPoolName,
48
+ challengeParameters,
49
+ dateNow,
50
+ hkdf,
51
+ }),
52
+ };
53
+ const deviceMetadata = await tokenOrchestrator.getDeviceMetadata(username);
54
+ if (deviceMetadata && deviceMetadata.deviceKey) {
55
+ challengeResponses.DEVICE_KEY = deviceMetadata.deviceKey;
56
+ }
57
+ const UserContextData = getUserContextData({
58
+ username,
59
+ userPoolId,
60
+ userPoolClientId,
61
+ });
62
+ const jsonReqResponseChallenge = {
63
+ ChallengeName: 'PASSWORD_VERIFIER',
64
+ ChallengeResponses: challengeResponses,
65
+ ClientMetadata: clientMetadata,
66
+ Session: session,
67
+ ClientId: userPoolClientId,
68
+ UserContextData,
69
+ };
70
+ const respondToAuthChallenge = createRespondToAuthChallengeClient({
71
+ endpointResolver: createCognitoUserPoolEndpointResolver({
72
+ endpointOverride: userPoolEndpoint,
73
+ }),
74
+ });
75
+ const response = await respondToAuthChallenge({ region: getRegionFromUserPoolId(userPoolId) }, jsonReqResponseChallenge);
76
+ if (response.ChallengeName === 'DEVICE_SRP_AUTH')
77
+ return handleDeviceSRPAuth({
78
+ username,
79
+ config,
80
+ clientMetadata,
81
+ session: response.Session,
82
+ tokenOrchestrator,
83
+ });
84
+ return response;
85
+ }
86
+
87
+ export { handlePasswordVerifierChallenge };
88
+ //# sourceMappingURL=handlePasswordVerifierChallenge.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePasswordVerifierChallenge.mjs","sources":["../../../../../src/providers/cognito/utils/handlePasswordVerifierChallenge.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AuthError } from '../../../errors/AuthError';\nimport { createRespondToAuthChallengeClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { getNowString, getSignatureString } from './srp';\nimport { BigInteger } from './srp/BigInteger';\nimport { getUserContextData } from './userContextData';\nimport { handleDeviceSRPAuth } from './handleDeviceSRPAuth';\nexport async 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(challengeParameters?.SRP_B, 16);\n const salt = new BigInteger(challengeParameters?.SALT, 16);\n const username = challengeParameters?.USER_ID_FOR_SRP;\n if (!username)\n throw new 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 = getNowString();\n const challengeResponses = {\n USERNAME: username,\n PASSWORD_CLAIM_SECRET_BLOCK: challengeParameters?.SECRET_BLOCK,\n TIMESTAMP: dateNow,\n PASSWORD_CLAIM_SIGNATURE: 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 = 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 = createRespondToAuthChallengeClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const response = await respondToAuthChallenge({ region: getRegionFromUserPoolId(userPoolId) }, jsonReqResponseChallenge);\n if (response.ChallengeName === 'DEVICE_SRP_AUTH')\n return handleDeviceSRPAuth({\n username,\n config,\n clientMetadata,\n session: response.Session,\n tokenOrchestrator,\n });\n return response;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AASO,eAAe,+BAA+B,CAAC,QAAQ,EAAE,mBAAmB,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,iBAAiB,EAAE;AAC/J,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;AACtE,IAAI,MAAM,YAAY,GAAG,UAAU,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACzD,IAAI,MAAM,YAAY,GAAG,IAAI,UAAU,CAAC,mBAAmB,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AACxE,IAAI,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,mBAAmB,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AAC/D,IAAI,MAAM,QAAQ,GAAG,mBAAmB,EAAE,eAAe,CAAC;AAC1D,IAAI,IAAI,CAAC,QAAQ;AACjB,QAAQ,MAAM,IAAI,SAAS,CAAC;AAC5B,YAAY,IAAI,EAAE,4BAA4B;AAC9C,YAAY,OAAO,EAAE,sDAAsD;AAC3E,SAAS,CAAC,CAAC;AACX,IAAI,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,4BAA4B,CAAC;AACzE,QAAQ,QAAQ;AAChB,QAAQ,QAAQ;AAChB,QAAQ,YAAY;AACpB,QAAQ,IAAI;AACZ,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;AACnC,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,QAAQ,2B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AM;AAClB,YAAY,cAAc;AAC1B,YAAY,OAAO,EAAE,QAAQ,CAAC,OAAO;AACrC,YAAY,iBAAiB;AAC7B,SAAS,CAAC,CAAC;AACX,IAAI,OAAO,QAAQ,CAAC;AACpB;;;;"}
@@ -0,0 +1,7 @@
1
+ import { AuthTokenOrchestrator } from '../tokenProvider/types';
2
+ /**
3
+ * It will retry the function if the error is a `ResourceNotFoundException` and
4
+ * will clean the device keys stored in the storage mechanism.
5
+ *
6
+ */
7
+ export declare function retryOnResourceNotFoundException<F extends (...args: any[]) => any>(func: F, args: Parameters<F>, username: string, tokenOrchestrator: AuthTokenOrchestrator): Promise<ReturnType<F>>;
@@ -0,0 +1,26 @@
1
+ import { AuthError } from '../../../errors/AuthError.mjs';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ /**
6
+ * It will retry the function if the error is a `ResourceNotFoundException` and
7
+ * will clean the device keys stored in the storage mechanism.
8
+ *
9
+ */
10
+ async function retryOnResourceNotFoundException(func, args, username, tokenOrchestrator) {
11
+ try {
12
+ return await func(...args);
13
+ }
14
+ catch (error) {
15
+ if (error instanceof AuthError &&
16
+ error.name === 'ResourceNotFoundException' &&
17
+ error.message.includes('Device does not exist.')) {
18
+ await tokenOrchestrator.clearDeviceMetadata(username);
19
+ return func(...args);
20
+ }
21
+ throw error;
22
+ }
23
+ }
24
+
25
+ export { retryOnResourceNotFoundException };
26
+ //# sourceMappingURL=retryOnResourceNotFoundException.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryOnResourceNotFoundException.mjs","sources":["../../../../../src/providers/cognito/utils/retryOnResourceNotFoundException.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AuthError } from '../../../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 */\nexport async function retryOnResourceNotFoundException(func, args, username, tokenOrchestrator) {\n try {\n return await func(...args);\n }\n catch (error) {\n if (error instanceof 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}\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACO,eAAe,gCAAgC,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE;AAChG,IAAI,IAAI;AACR,QAAQ,OAAO,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AACnC,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,YAAY,SAAS;AACtC,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;;;;"}
@@ -0,0 +1 @@
1
+ export declare function setActiveSignInUsername(username: string): void;
@@ -0,0 +1,12 @@
1
+ import '../../../client/utils/store/autoSignInStore.mjs';
2
+ import { signInStore } from '../../../client/utils/store/signInStore.mjs';
3
+
4
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ function setActiveSignInUsername(username) {
7
+ const { dispatch } = signInStore;
8
+ dispatch({ type: 'SET_USERNAME', value: username });
9
+ }
10
+
11
+ export { setActiveSignInUsername };
12
+ //# sourceMappingURL=setActiveSignInUsername.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setActiveSignInUsername.mjs","sources":["../../../../../src/providers/cognito/utils/setActiveSignInUsername.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { signInStore } from '../../../client/utils/store';\nexport function setActiveSignInUsername(username) {\n const { dispatch } = signInStore;\n dispatch({ type: 'SET_USERNAME', value: username });\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAEO,SAAS,uBAAuB,CAAC,QAAQ,EAAE;AAClD,IAAI,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;AACrC,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AACxD;;;;"}
@@ -2,9 +2,8 @@ import { CognitoUserPoolConfig } from '@aws-amplify/core';
2
2
  import { ClientMetadata, ConfirmSignInOptions } from '../types';
3
3
  import { AuthSignInOutput } from '../../../types';
4
4
  import { AuthMFAType, AuthTOTPSetupDetails, AuthUserAttributes } from '../../../types/models';
5
- import { AuthTokenOrchestrator, DeviceMetadata } from '../tokenProvider/types';
6
- import { ChallengeName, ChallengeParameters, CognitoMFAType, InitiateAuthCommandOutput, NewDeviceMetadataType, RespondToAuthChallengeCommandOutput } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
7
- import { AuthenticationHelper } from './srp/AuthenticationHelper';
5
+ import { AuthTokenOrchestrator } from '../tokenProvider/types';
6
+ import { ChallengeName, ChallengeParameters, CognitoMFAType, InitiateAuthCommandOutput, RespondToAuthChallengeCommandOutput } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
8
7
  interface HandleAuthChallengeRequest {
9
8
  challengeResponse: string;
10
9
  username: string;
@@ -24,7 +23,6 @@ export declare function handleUserPasswordAuthFlow(username: string, password: s
24
23
  export declare function handleUserSRPAuthFlow(username: string, password: string, clientMetadata: ClientMetadata | undefined, config: CognitoUserPoolConfig, tokenOrchestrator: AuthTokenOrchestrator): Promise<RespondToAuthChallengeCommandOutput>;
25
24
  export declare function handleCustomAuthFlowWithoutSRP(username: string, clientMetadata: ClientMetadata | undefined, config: CognitoUserPoolConfig, tokenOrchestrator: AuthTokenOrchestrator): Promise<InitiateAuthCommandOutput>;
26
25
  export declare function handleCustomSRPAuthFlow(username: string, password: string, clientMetadata: ClientMetadata | undefined, config: CognitoUserPoolConfig, tokenOrchestrator: AuthTokenOrchestrator): Promise<RespondToAuthChallengeCommandOutput>;
27
- export declare function handlePasswordVerifierChallenge(password: string, challengeParameters: ChallengeParameters, clientMetadata: ClientMetadata | undefined, session: string | undefined, authenticationHelper: AuthenticationHelper, config: CognitoUserPoolConfig, tokenOrchestrator: AuthTokenOrchestrator): Promise<RespondToAuthChallengeCommandOutput>;
28
26
  export declare function getSignInResult(params: {
29
27
  challengeName: ChallengeName;
30
28
  challengeParameters: ChallengeParameters;
@@ -41,28 +39,6 @@ export declare function getMFATypes(types?: string[]): AuthMFAType[] | undefined
41
39
  export declare function parseMFATypes(mfa?: string): CognitoMFAType[];
42
40
  export declare function getAllowedMfaSetupTypes(availableMfaSetupTypes: AuthMFAType[]): AuthMFAType[];
43
41
  export declare function assertUserNotAuthenticated(): Promise<void>;
44
- /**
45
- * This function is used to kick off the device management flow.
46
- *
47
- * If an error is thrown while generating a hash device or calling the `ConfirmDevice`
48
- * client, then this API will ignore the error and return undefined. Otherwise the authentication
49
- * flow will not complete and the user won't be able to be signed in.
50
- *
51
- * @returns DeviceMetadata | undefined
52
- */
53
- export declare function getNewDeviceMetadata({ userPoolId, userPoolEndpoint, newDeviceMetadata, accessToken, }: {
54
- userPoolId: string;
55
- userPoolEndpoint: string | undefined;
56
- newDeviceMetadata?: NewDeviceMetadataType;
57
- accessToken?: string;
58
- }): Promise<DeviceMetadata | undefined>;
59
- /**
60
- * It will retry the function if the error is a `ResourceNotFoundException` and
61
- * will clean the device keys stored in the storage mechanism.
62
- *
63
- */
64
- export declare function retryOnResourceNotFoundException<F extends (...args: any[]) => any>(func: F, args: Parameters<F>, username: string, tokenOrchestrator: AuthTokenOrchestrator): Promise<ReturnType<F>>;
65
- export declare function setActiveSignInUsername(username: string): void;
66
42
  export declare function getActiveSignInUsername(username: string): string;
67
43
  export declare function handleMFAChallenge({ challengeName, challengeResponse, clientMetadata, session, username, config, }: HandleAuthChallengeRequest & {
68
44
  challengeName: Extract<ChallengeName, 'EMAIL_OTP' | 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA' | 'SMS_OTP'>;