{"version":3,"file":"SilentCacheClient.js","sources":["../../src/interaction_client/SilentCacheClient.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { StandardInteractionClient } from \"./StandardInteractionClient\";\r\nimport { CommonSilentFlowRequest, AuthenticationResult, SilentFlowClient, ServerTelemetryManager, AccountInfo, AzureCloudOptions, PerformanceEvents, AuthError } from \"@azure/msal-common\";\r\nimport { SilentRequest } from \"../request/SilentRequest\";\r\nimport { ApiId } from \"../utils/BrowserConstants\";\r\nimport { BrowserAuthError, BrowserAuthErrorMessage } from \"../error/BrowserAuthError\";\r\n\r\nexport class SilentCacheClient extends StandardInteractionClient {\r\n /**\r\n * Returns unexpired tokens from the cache, if available\r\n * @param silentRequest\r\n */\r\n async acquireToken(silentRequest: CommonSilentFlowRequest): Promise {\r\n const acquireTokenMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SilentCacheClientAcquireToken, silentRequest.correlationId);\r\n // Telemetry manager only used to increment cacheHits here\r\n const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);\r\n\r\n const silentAuthClient = await this.createSilentFlowClient(serverTelemetryManager, silentRequest.authority, silentRequest.azureCloudOptions);\r\n this.logger.verbose(\"Silent auth client created\");\r\n\r\n try {\r\n const cachedToken = await silentAuthClient.acquireCachedToken(silentRequest);\r\n\r\n acquireTokenMeasurement.endMeasurement({\r\n success: true,\r\n fromCache: true\r\n });\r\n return cachedToken;\r\n } catch (error) {\r\n if (error instanceof BrowserAuthError && error.errorCode === BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code) {\r\n this.logger.verbose(\"Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.\");\r\n }\r\n acquireTokenMeasurement.endMeasurement({\r\n errorCode: error instanceof AuthError && error.errorCode || undefined,\r\n subErrorCode: error instanceof AuthError && error.subError || undefined,\r\n success: false\r\n });\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Currently Unsupported\r\n */\r\n logout(): Promise {\r\n // Synchronous so we must reject\r\n return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());\r\n }\r\n\r\n /**\r\n * Creates an Silent Flow Client with the given authority, or the default authority.\r\n * @param serverTelemetryManager\r\n * @param authorityUrl\r\n */\r\n protected async createSilentFlowClient(serverTelemetryManager: ServerTelemetryManager, authorityUrl?: string, azureCloudOptions?: AzureCloudOptions): Promise {\r\n // Create auth module.\r\n this.performanceClient.setPreQueueTime(PerformanceEvents.StandardInteractionClientGetClientConfiguration, this.correlationId);\r\n const clientConfig = await this.getClientConfiguration(serverTelemetryManager, authorityUrl, azureCloudOptions);\r\n return new SilentFlowClient(clientConfig, this.performanceClient);\r\n }\r\n\r\n async initializeSilentRequest(request: SilentRequest, account: AccountInfo): Promise {\r\n this.performanceClient.addQueueMeasurement(PerformanceEvents.InitializeSilentRequest, this.correlationId);\r\n\r\n this.performanceClient.setPreQueueTime(PerformanceEvents.InitializeBaseRequest, this.correlationId);\r\n return {\r\n ...request,\r\n ...await this.initializeBaseRequest(request, account),\r\n account: account,\r\n forceRefresh: request.forceRefresh || false\r\n };\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;IAWuC,qCAAyB;IAAhE;;KAiEC;;;;;IA5DS,wCAAY,GAAlB,UAAmB,aAAsC;;;;;;wBAC/C,uBAAuB,GAAG,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,6BAA6B,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;wBAEhJ,sBAAsB,GAAG,IAAI,CAAC,gCAAgC,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;wBAEjF,qBAAM,IAAI,CAAC,sBAAsB,CAAC,sBAAsB,EAAE,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,iBAAiB,CAAC,EAAA;;wBAAtI,gBAAgB,GAAG,SAAmH;wBAC5I,IAAI,CAAC,MA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