UNPKG

@aws-amplify/auth

Version:
1 lines 4.23 kB
{"version":3,"file":"associateWebAuthnCredential.mjs","sources":["../../../../src/client/apis/associateWebAuthnCredential.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify, fetchAuthSession } from '@aws-amplify/core';\nimport { AuthAction, assertTokenProviderConfig, } from '@aws-amplify/core/internals/utils';\nimport { assertAuthTokens } from '../../providers/cognito/utils/types';\nimport { createCognitoUserPoolEndpointResolver } from '../../providers/cognito/factories';\nimport { getRegionFromUserPoolId } from '../../foundation/parsers';\nimport { getAuthUserAgentValue } from '../../utils';\nimport { registerPasskey } from '../utils';\nimport { createCompleteWebAuthnRegistrationClient, createStartWebAuthnRegistrationClient, } from '../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { assertValidCredentialCreationOptions } from '../utils/passkey/types';\n/**\n * Registers a new passkey for an authenticated user\n *\n * @returns Promise<void>\n * @throws - {@link PasskeyError}:\n * - Thrown when intermediate state is invalid\n * @throws - {@link AuthError}:\n * - Thrown when user is unauthenticated\n * @throws - {@link StartWebAuthnRegistrationException}\n * - Thrown due to a service error retrieving WebAuthn registration options\n * @throws - {@link CompleteWebAuthnRegistrationException}\n * - Thrown due to a service error when verifying WebAuthn registration result\n */\nexport async function associateWebAuthnCredential() {\n const authConfig = Amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n const { userPoolEndpoint, userPoolId } = authConfig;\n const { tokens } = await fetchAuthSession();\n assertAuthTokens(tokens);\n const startWebAuthnRegistration = createStartWebAuthnRegistrationClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { CredentialCreationOptions: credentialCreationOptions } = await startWebAuthnRegistration({\n region: getRegionFromUserPoolId(userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.StartWebAuthnRegistration),\n }, {\n AccessToken: tokens.accessToken.toString(),\n });\n assertValidCredentialCreationOptions(credentialCreationOptions);\n const cred = await registerPasskey(credentialCreationOptions);\n const completeWebAuthnRegistration = createCompleteWebAuthnRegistrationClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n await completeWebAuthnRegistration({\n region: getRegionFromUserPoolId(userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.CompleteWebAuthnRegistration),\n }, {\n AccessToken: tokens.accessToken.toString(),\n Credential: cred,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,2BAA2B,GAAG;AACpD,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO;AACxD,IAAI,yBAAyB,CAAC,UAAU,CAAC;AACzC,IAAI,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,UAAU;AACvD,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAgB,EAAE;AAC/C,IAAI,gBAAgB,CAAC,MAAM,CAAC;AAC5B,IAAI,MAAM,yBAAyB,GAAG,qCAAqC,CAAC;AAC5E,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC;AACN,IAAI,MAAM,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,GAAG,MAAM,yBAAyB,CAAC;AACrG,QAAQ,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC;AACnD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,yBAAyB,CAAC;AACnF,KAAK,EAAE;AACP,QAAQ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;AAClD,KAAK,CAAC;AACN,IAAI,oCAAoC,CAAC,yBAAyB,CAAC;AAC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