{"version":3,"file":"SilentCacheClient.js","sources":["../../src/interaction_client/SilentCacheClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { StandardInteractionClient } from \"./StandardInteractionClient\";\nimport { CommonSilentFlowRequest, AuthenticationResult, SilentFlowClient, ServerTelemetryManager, AccountInfo, AzureCloudOptions, PerformanceEvents, AuthError } from \"@azure/msal-common\";\nimport { SilentRequest } from \"../request/SilentRequest\";\nimport { ApiId } from \"../utils/BrowserConstants\";\nimport { BrowserAuthError, BrowserAuthErrorMessage } from \"../error/BrowserAuthError\";\n\nexport class SilentCacheClient extends StandardInteractionClient {\n /**\n * Returns unexpired tokens from the cache, if available\n * @param silentRequest\n */\n async acquireToken(silentRequest: CommonSilentFlowRequest): Promise {\n const acquireTokenMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SilentCacheClientAcquireToken, silentRequest.correlationId);\n // Telemetry manager only used to increment cacheHits here\n const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);\n\n const silentAuthClient = await this.createSilentFlowClient(serverTelemetryManager, silentRequest.authority, silentRequest.azureCloudOptions);\n this.logger.verbose(\"Silent auth client created\");\n\n try {\n const cachedToken = await silentAuthClient.acquireCachedToken(silentRequest);\n\n acquireTokenMeasurement.endMeasurement({\n success: true,\n fromCache: true\n });\n return cachedToken;\n } catch (error) {\n if (error instanceof BrowserAuthError && error.errorCode === BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code) {\n this.logger.verbose(\"Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.\");\n }\n acquireTokenMeasurement.endMeasurement({\n errorCode: error instanceof AuthError && error.errorCode || undefined,\n subErrorCode: error instanceof AuthError && error.subError || undefined,\n success: false\n });\n throw error;\n }\n }\n\n /**\n * Currently Unsupported\n */\n logout(): Promise {\n // Synchronous so we must reject\n return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());\n }\n\n /**\n * Creates an Silent Flow Client with the given authority, or the default authority.\n * @param serverTelemetryManager\n * @param authorityUrl\n */\n protected async createSilentFlowClient(serverTelemetryManager: ServerTelemetryManager, authorityUrl?: string, azureCloudOptions?: AzureCloudOptions): Promise {\n // Create auth module.\n const clientConfig = await this.getClientConfiguration(serverTelemetryManager, authorityUrl, azureCloudOptions);\n return new SilentFlowClient(clientConfig, this.performanceClient);\n }\n\n async initializeSilentRequest(request: SilentRequest, account: AccountInfo): Promise {\n return {\n ...request,\n ...await this.initializeBaseRequest(request),\n account: account,\n forceRefresh: request.forceRefresh || false\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;IAWuC,qCAAyB;IAAhE;;KA6DC;;;;;IAxDS,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,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;;;;wBAG1B,qBAAM,gBAAgB,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAA;;wBAAtE,WAAW,GAAG,SAAwD;wBAE5E,uBAAuB,CAAC,cAAc,CAAC;4BACnC,OAAO,EAAE,IAAI;4BACb,SAAS,EAAE,IAAI;yBAClB,CAAC,CAAC;wBACH,sBAAO,WAAW,EAAC;;;wBAEnB,IAAI,OAAK,YAAY,gBAAgB,IAAI,OAAK,CAAC,SAAS,KAAK,uBAAuB,CAAC,2BAA2B,CAAC,IAAI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