@aws-amplify/core
Version:
Core category of aws-amplify
1 lines • 4.16 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../../src/singleton/Auth/index.ts"],"sourcesContent":["export function isTokenExpired({ expiresAt, clockDrift, }) {\n const currentTime = Date.now();\n return currentTime + clockDrift > expiresAt;\n}\nexport class AuthClass {\n constructor() { }\n /**\n * Configure Auth category\n *\n * @internal\n *\n * @param authResourcesConfig - Resources configurations required by Auth providers.\n * @param authOptions - Client options used by library\n *\n * @returns void\n */\n configure(authResourcesConfig, authOptions) {\n this.authConfig = authResourcesConfig;\n this.authOptions = authOptions;\n }\n async fetchAuthSession(options = {}) {\n let tokens;\n let credentialsAndIdentityId;\n let userSub;\n // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available\n tokens = await this.getTokens(options);\n if (tokens) {\n userSub = tokens.accessToken?.payload?.sub;\n // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)\n credentialsAndIdentityId =\n await this.authOptions?.credentialsProvider?.getCredentialsAndIdentityId({\n authConfig: this.authConfig,\n tokens,\n authenticated: true,\n forceRefresh: options.forceRefresh,\n });\n }\n else {\n // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)\n credentialsAndIdentityId =\n await this.authOptions?.credentialsProvider?.getCredentialsAndIdentityId({\n authConfig: this.authConfig,\n authenticated: false,\n forceRefresh: options.forceRefresh,\n });\n }\n return {\n tokens,\n credentials: credentialsAndIdentityId?.credentials,\n identityId: credentialsAndIdentityId?.identityId,\n userSub,\n };\n }\n async clearCredentials() {\n if (this.authOptions?.credentialsProvider) {\n return await this.authOptions.credentialsProvider.clearCredentialsAndIdentityId();\n }\n }\n async getTokens(options) {\n return ((await this.authOptions?.tokenProvider?.getTokens(options)) ?? undefined);\n }\n}\n"],"names":[],"mappings":"AAAO,SAAS,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,GAAG,EAAE;AAC3D,IAAI,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AACnC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