UNPKG

@aws-amplify/auth

Version:
1 lines 3.81 kB
{"version":3,"file":"handleSelectChallengeWithPassword.mjs","sources":["../../../../../src/client/flows/userAuth/handleSelectChallengeWithPassword.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 { getUserContextData } from '../../../providers/cognito/utils/userContextData';\nimport { setActiveSignInUsername } from '../../../providers/cognito/utils/setActiveSignInUsername';\n/**\n * Handles the SELECT_CHALLENGE response specifically for Password authentication.\n * This function combines the SELECT_CHALLENGE flow with standard password authentication.\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 *\n * @returns {Promise<RespondToAuthChallengeCommandOutput>} The challenge response\n */\nexport async function handleSelectChallengeWithPassword(username, password, clientMetadata, config, session) {\n const { userPoolId, userPoolClientId, userPoolEndpoint } = config;\n const authParameters = {\n ANSWER: 'PASSWORD',\n USERNAME: username,\n PASSWORD: password,\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 return response;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,iCAAiC,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE;AAC7G,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,MAAM;AACrE,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,MAAM,EAAE,UAAU;AAC1B,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,KAAK;AACL,IAAI,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAC/C,QAAQ,QAAQ;AAChB,QAAQ,UAAU;AAClB,QAAQ,gBAAgB;AACxB,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;AACN,IAAI,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC;AAClD,QAAQ,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC;AACnD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,aAAa,CAAC;AACvE,KAAK,EAAE;AACP,QAAQ,aAAa,EAAE,kBAAkB;AACzC,QAAQ,kBAAkB,EAAE,cAAc;AAC1C,QAAQ,QAAQ,EAAE,gBAAgB;AAClC,QAAQ,cAAc,EAAE,cAAc;AACtC,QAAQ,OAAO,EAAE,OAAO;AACxB,QAAQ,eAAe,EAAE,eAAe;AACxC,KAAK,CAAC;AACN,IAAI,MAAM,cAAc,GAAG,QAAQ,CAAC,mBAAmB,EAAE,QAAQ,IAAI,QAAQ;AAC7E,IAAI,uBAAuB,CAAC,cAAc,CAAC;AAC3C,IAAI,OAAO,QAAQ;AACnB;;;;"}