{"version":3,"file":"authNTokens.mjs","sources":["../../../../src/auth/utils/authNTokens.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { OAUTH_GRANT_TYPE } from '../constant';\nimport { createUrlSearchParamsForTokenExchange, createUrlSearchParamsForTokenRevocation, } from './createUrlSearchParams';\nimport { createRevokeEndpoint, createTokenEndpoint, } from './cognitoHostedUIEndpoints';\nexport const exchangeAuthNTokens = async ({ redirectUri, userPoolClientId, oAuthConfig, code, codeVerifier, }) => {\n    const searchParams = createUrlSearchParamsForTokenExchange({\n        client_id: userPoolClientId,\n        code,\n        redirect_uri: redirectUri,\n        code_verifier: codeVerifier,\n        grant_type: OAUTH_GRANT_TYPE,\n    });\n    const oAuthTokenEndpoint = createTokenEndpoint(oAuthConfig.domain);\n    const tokenExchangeResponse = await fetch(oAuthTokenEndpoint, {\n        method: 'POST',\n        headers: {\n            'Content-Type': 'application/x-www-form-urlencoded',\n            'Cache-Control': 'no-cache',\n        },\n        body: searchParams.toString(),\n    });\n    // Exchanging an authorization code grant with PKCE for tokens with\n    // `grant_type=authorization_code` produces a stable shape of payload.\n    // Details see https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html\n    // Possible errors: invalid_request|invalid_client|invalid_grant|unauthorized_client|unsupported_grant_type\n    // Should not happen unless configuration is wrong;\n    return (await tokenExchangeResponse.json());\n};\nexport const revokeAuthNTokens = async ({ userPoolClientId, refreshToken, endpointDomain, }) => {\n    const searchParams = createUrlSearchParamsForTokenRevocation({\n        client_id: userPoolClientId,\n        token: refreshToken,\n    });\n    const oAuthTokenRevocationEndpoint = createRevokeEndpoint(endpointDomain);\n    const response = await fetch(oAuthTokenRevocationEndpoint, {\n        method: 'POST',\n        headers: {\n            'Content-Type': 'application/x-www-form-urlencoded',\n            'Cache-Control': 'no-cache',\n        },\n        body: searchParams.toString(),\n    });\n    const contentLength = parseInt(response.headers.get('Content-Length') ?? '0', 10);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