UNPKG

aws-amplify

Version:

AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.

34 lines (32 loc) • 1.74 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.createUserPoolsTokenProvider = void 0; const cognito_1 = require("@aws-amplify/auth/cognito"); const utils_1 = require("@aws-amplify/core/internals/utils"); /** * Creates an object that implements {@link TokenProvider}. * @param authConfig The Auth config that the credentials provider needs to function. * @param keyValueStorage An object that implements the {@link KeyValueStorageInterface}. * @returns An object that implements {@link TokenProvider}. */ const createUserPoolsTokenProvider = (authConfig, keyValueStorage) => { const authTokenStore = new cognito_1.DefaultTokenStore(); authTokenStore.setAuthConfig(authConfig); authTokenStore.setKeyValueStorage(keyValueStorage); const tokenOrchestrator = new cognito_1.TokenOrchestrator(); tokenOrchestrator.setAuthConfig(authConfig); tokenOrchestrator.setAuthTokenStore(authTokenStore); tokenOrchestrator.setTokenRefresher(cognito_1.refreshAuthTokensWithoutDedupe); const provider = { getTokens: ({ forceRefresh } = { forceRefresh: false }) => tokenOrchestrator.getTokens({ forceRefresh }), }; // Register the per-context orchestrator so token writes performed through a // local context (e.g. `createAmplifyContext`) can be routed to this // write-capable orchestrator instead of the global singleton. (0, utils_1.registerContextTokenOrchestrator)(provider, tokenOrchestrator); return provider; }; exports.createUserPoolsTokenProvider = createUserPoolsTokenProvider; //# sourceMappingURL=createUserPoolsTokenProvider.js.map