{"version":3,"file":"SilentIframeClient.js","sources":["../../src/interaction_client/SilentIframeClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthenticationResult, ICrypto, Logger, StringUtils, PromptValue, CommonAuthorizationCodeRequest, AuthorizationCodeClient, AuthError, Constants, UrlString, ServerAuthorizationCodeResponse, ProtocolUtils, IPerformanceClient, PerformanceEvents } from \"@azure/msal-common\";\nimport { StandardInteractionClient } from \"./StandardInteractionClient\";\nimport { AuthorizationUrlRequest } from \"../request/AuthorizationUrlRequest\";\nimport { BrowserConfiguration } from \"../config/Configuration\";\nimport { BrowserCacheManager } from \"../cache/BrowserCacheManager\";\nimport { EventHandler } from \"../event/EventHandler\";\nimport { INavigationClient } from \"../navigation/INavigationClient\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { InteractionType, ApiId } from \"../utils/BrowserConstants\";\nimport { SilentHandler } from \"../interaction_handler/SilentHandler\";\nimport { SsoSilentRequest } from \"../request/SsoSilentRequest\";\nimport { NativeMessageHandler } from \"../broker/nativeBroker/NativeMessageHandler\";\nimport { NativeInteractionClient } from \"./NativeInteractionClient\";\n\nexport class SilentIframeClient extends StandardInteractionClient {\n protected apiId: ApiId;\n protected nativeStorage: BrowserCacheManager;\n\n constructor(config: BrowserConfiguration, storageImpl: BrowserCacheManager, browserCrypto: ICrypto, logger: Logger, eventHandler: EventHandler, navigationClient: INavigationClient, apiId: ApiId, performanceClient: IPerformanceClient, nativeStorageImpl: BrowserCacheManager, nativeMessageHandler?: NativeMessageHandler, correlationId?: string) {\n super(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, performanceClient, nativeMessageHandler, correlationId);\n this.apiId = apiId;\n this.nativeStorage = nativeStorageImpl;\n }\n\n /**\n * Acquires a token silently by opening a hidden iframe to the /authorize endpoint with prompt=none or prompt=no_session\n * @param request\n */\n async acquireToken(request: SsoSilentRequest): Promise {\n this.logger.verbose(\"acquireTokenByIframe called\");\n const acquireTokenMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SilentIframeClientAcquireToken, request.correlationId);\n // Check that we have some SSO data\n if (StringUtils.isEmpty(request.loginHint) && StringUtils.isEmpty(request.sid) && (!request.account || StringUtils.isEmpty(request.account.username))) {\n this.logger.warning(\"No user hint provided. The authorization server may need more information to complete this request.\");\n }\n\n // Check that prompt is set to none or no_session, throw error if it is set to anything else.\n if (request.prompt && (request.prompt !== PromptValue.NONE) && (request.prompt !== PromptValue.NO_SESSION)) {\n acquireTokenMeasurement.endMeasurement({\n success: false\n });\n throw BrowserAuthError.createSilentPromptValueError(request.prompt);\n }\n\n // Create silent request\n const silentRequest: AuthorizationUrlRequest = await this.initializeAuthorizationRequest({\n ...request,\n prompt: request.prompt || PromptValue.NONE\n }, InteractionType.Silent);\n this.browserStorage.updateCacheEntries(silentRequest.state, silentRequest.nonce, silentRequest.authority, silentRequest.loginHint || Constants.EMPTY_STRING, silentRequest.account || null);\n\n const serverTelemetryManager = this.initializeServerTelemetryManager(this.apiId);\n\n try {\n // Initialize the client\n const authClient: AuthorizationCodeClient = await this.createAuthCodeClient(serverTelemetryManager, silentRequest.authority, silentRequest.azureCloudOptions);\n this.logger.verbose(\"Auth code client created\");\n\n return await this.silentTokenHelper(authClient, silentRequest).then((result: AuthenticationResult) => {\n acquireTokenMeasurement.endMeasurement({\n success: true,\n fromCache: false,\n requestId: result.requestId\n });\n return result;\n });\n } catch (e) {\n if (e instanceof AuthError) {\n (e as AuthError).setCorrelationId(this.correlationId);\n }\n serverTelemetryManager.cacheFailedRequest(e);\n this.browserStorage.cleanRequestByState(silentRequest.state);\n acquireTokenMeasurement.endMeasurement({\n errorCode: e instanceof AuthError && e.errorCode || undefined,\n subErrorCode: e instanceof AuthError && e.subError || undefined,\n success: false\n });\n throw e;\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 * Helper which acquires an authorization code silently using a hidden iframe from given url\n * using the scopes requested as part of the id, and exchanges the code for a set of OAuth tokens.\n * @param navigateUrl\n * @param userRequestScopes\n */\n protected async silentTokenHelper(authClient: AuthorizationCodeClient, silentRequest: AuthorizationUrlRequest): Promise {\n // Create auth code request and generate PKCE params\n const authCodeRequest: CommonAuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(silentRequest);\n // Create authorize request url\n const navigateUrl = await authClient.getAuthCodeUrl({\n ...silentRequest,\n nativeBroker: NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeMessageHandler, silentRequest.authenticationScheme)\n });\n // Create silent handler\n const silentHandler = new SilentHandler(authClient, this.browserStorage, authCodeRequest, this.logger, this.config.system);\n // Get the frame handle for the silent request\n const msalFrame = await silentHandler.initiateAuthRequest(navigateUrl);\n // Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.\n const hash = await silentHandler.monitorIframeForHash(msalFrame, this.config.system.iframeHashTimeout);\n // Deserialize hash fragment response parameters.\n const serverParams: ServerAuthorizationCodeResponse = UrlString.getDeserializedHash(hash);\n const state = this.validateAndExtractStateFromHash(serverParams, InteractionType.Silent, authCodeRequest.correlationId);\n\n if (serverParams.accountId) {\n this.logger.verbose(\"Account id found in hash, calling WAM for token\");\n if (!this.nativeMessageHandler) {\n throw BrowserAuthError.createNativeConnectionNotEstablishedError();\n }\n const nativeInteractionClient = new NativeInteractionClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.apiId, this.performanceClient, this.nativeMessageHandler, serverParams.accountId, this.browserStorage, this.correlationId);\n const { userRequestState } = ProtocolUtils.parseRequestState(this.browserCrypto, state);\n return nativeInteractionClient.acquireToken({\n ...silentRequest,\n state: userRequestState,\n prompt: silentRequest.prompt || PromptValue.NONE\n }).finally(() => {\n this.browserStorage.cleanRequestByState(state);\n });\n }\n\n // Handle response from hash string\n return silentHandler.handleCodeResponseFromHash(hash, state,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