UNPKG

@aws-amplify/auth

Version:
1 lines 5.29 kB
{"version":3,"file":"handleSelectChallengeWithPasswordSRP.mjs","sources":["../../../../../src/client/flows/userAuth/handleSelectChallengeWithPasswordSRP.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AuthAction } from '@aws-amplify/core/internals/utils';\nimport { createRespondToAuthChallengeClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../../../providers/cognito/factories';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { getAuthUserAgentValue } from '../../../utils';\nimport { getAuthenticationHelper } from '../../../providers/cognito/utils/srp';\nimport { getUserContextData } from '../../../providers/cognito/utils/userContextData';\nimport { setActiveSignInUsername } from '../../../providers/cognito/utils/setActiveSignInUsername';\nimport { retryOnResourceNotFoundException } from '../../../providers/cognito/utils/retryOnResourceNotFoundException';\nimport { handlePasswordVerifierChallenge } from '../../../providers/cognito/utils/handlePasswordVerifierChallenge';\n/**\n * Handles the SELECT_CHALLENGE response specifically for Password SRP authentication.\n * This function combines the SELECT_CHALLENGE flow with Password SRP protocol.\n *\n * @param {string} username - The username for authentication\n * @param {string} password - The user's password\n * @param {ClientMetadata} [clientMetadata] - Optional metadata to be sent with auth requests\n * @param {CognitoUserPoolConfig} config - Cognito User Pool configuration\n * @param {string} session - The current authentication session token\n * @param {AuthTokenOrchestrator} tokenOrchestrator - Token orchestrator for managing auth tokens\n *\n * @returns {Promise<RespondToAuthChallengeCommandOutput>} The challenge response\n */\nexport async function handleSelectChallengeWithPasswordSRP(username, password, clientMetadata, config, session, tokenOrchestrator) {\n const { userPoolId, userPoolClientId, userPoolEndpoint } = config;\n const userPoolName = userPoolId.split('_')[1] || '';\n const authenticationHelper = await getAuthenticationHelper(userPoolName);\n const authParameters = {\n ANSWER: 'PASSWORD_SRP',\n USERNAME: username,\n SRP_A: authenticationHelper.A.toString(16),\n };\n const userContextData = getUserContextData({\n username,\n userPoolId,\n userPoolClientId,\n });\n const respondToAuthChallenge = createRespondToAuthChallengeClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const response = await respondToAuthChallenge({\n region: getRegionFromUserPoolId(userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),\n }, {\n ChallengeName: 'SELECT_CHALLENGE',\n ChallengeResponses: authParameters,\n ClientId: userPoolClientId,\n ClientMetadata: clientMetadata,\n Session: session,\n UserContextData: userContextData,\n });\n const activeUsername = response.ChallengeParameters?.USERNAME ?? username;\n setActiveSignInUsername(activeUsername);\n if (response.ChallengeName === 'PASSWORD_VERIFIER') {\n return retryOnResourceNotFoundException(handlePasswordVerifierChallenge, [\n password,\n response.ChallengeParameters,\n clientMetadata,\n response.Session,\n authenticationHelper,\n config,\n tokenOrchestrator,\n ], activeUsername, tokenOrchestrator);\n }\n return response;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,oCAAoC,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE;AACnI,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,MAAM;AACrE,IAAI,MAAM,YAAY,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;AACvD,IAAI,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CAAC,YAAY,CAAC;AAC5E,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,MAAM,EAAE,cAAc;AAC9B,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,QAAQ,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,E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