@azure/msal-browser 2.29.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +1 -2
  2. package/dist/_virtual/_tslib.js +1 -1
  3. package/dist/app/ClientApplication.d.ts.map +1 -1
  4. package/dist/app/ClientApplication.js +13 -9
  5. package/dist/app/ClientApplication.js.map +1 -1
  6. package/dist/app/IPublicClientApplication.js +1 -1
  7. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  8. package/dist/app/PublicClientApplication.js +8 -6
  9. package/dist/app/PublicClientApplication.js.map +1 -1
  10. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +11 -0
  11. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  12. package/dist/broker/nativeBroker/NativeMessageHandler.js +16 -1
  13. package/dist/broker/nativeBroker/NativeMessageHandler.js.map +1 -1
  14. package/dist/cache/AsyncMemoryStorage.js +1 -1
  15. package/dist/cache/BrowserCacheManager.js +1 -1
  16. package/dist/cache/BrowserStorage.js +1 -1
  17. package/dist/cache/CryptoKeyStore.js +1 -1
  18. package/dist/cache/DatabaseStorage.js +1 -1
  19. package/dist/cache/ITokenCache.d.ts +6 -3
  20. package/dist/cache/ITokenCache.d.ts.map +1 -1
  21. package/dist/cache/MemoryStorage.js +1 -1
  22. package/dist/cache/TokenCache.d.ts +33 -5
  23. package/dist/cache/TokenCache.d.ts.map +1 -1
  24. package/dist/cache/TokenCache.js +121 -20
  25. package/dist/cache/TokenCache.js.map +1 -1
  26. package/dist/config/Configuration.d.ts +4 -0
  27. package/dist/config/Configuration.d.ts.map +1 -1
  28. package/dist/config/Configuration.js +3 -3
  29. package/dist/config/Configuration.js.map +1 -1
  30. package/dist/crypto/BrowserCrypto.js +1 -1
  31. package/dist/crypto/CryptoOps.js +1 -1
  32. package/dist/crypto/GuidGenerator.js +1 -1
  33. package/dist/crypto/ModernBrowserCrypto.js +1 -1
  34. package/dist/crypto/MsBrowserCrypto.js +1 -1
  35. package/dist/crypto/MsrBrowserCrypto.js +1 -1
  36. package/dist/crypto/PkceGenerator.js +1 -1
  37. package/dist/crypto/SignedHttpRequest.js +1 -1
  38. package/dist/encode/Base64Decode.js +1 -1
  39. package/dist/encode/Base64Encode.js +1 -1
  40. package/dist/error/BrowserAuthError.js +1 -1
  41. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  42. package/dist/error/NativeAuthError.js +1 -1
  43. package/dist/event/EventHandler.js +1 -1
  44. package/dist/event/EventMessage.js +1 -1
  45. package/dist/event/EventType.js +1 -1
  46. package/dist/index.cjs.js +296 -132
  47. package/dist/index.cjs.js.map +1 -1
  48. package/dist/index.js +1 -1
  49. package/dist/interaction_client/BaseInteractionClient.js +1 -1
  50. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
  51. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  52. package/dist/interaction_client/NativeInteractionClient.js +28 -7
  53. package/dist/interaction_client/NativeInteractionClient.js.map +1 -1
  54. package/dist/interaction_client/PopupClient.js +4 -4
  55. package/dist/interaction_client/PopupClient.js.map +1 -1
  56. package/dist/interaction_client/RedirectClient.js +1 -1
  57. package/dist/interaction_client/SilentAuthCodeClient.js +2 -2
  58. package/dist/interaction_client/SilentAuthCodeClient.js.map +1 -1
  59. package/dist/interaction_client/SilentCacheClient.js +1 -1
  60. package/dist/interaction_client/SilentIframeClient.js +2 -2
  61. package/dist/interaction_client/SilentIframeClient.js.map +1 -1
  62. package/dist/interaction_client/SilentRefreshClient.js +1 -1
  63. package/dist/interaction_client/StandardInteractionClient.js +1 -1
  64. package/dist/interaction_handler/InteractionHandler.js +1 -1
  65. package/dist/interaction_handler/RedirectHandler.js +1 -1
  66. package/dist/interaction_handler/SilentHandler.d.ts +3 -1
  67. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  68. package/dist/interaction_handler/SilentHandler.js +5 -5
  69. package/dist/interaction_handler/SilentHandler.js.map +1 -1
  70. package/dist/internals.js +1 -1
  71. package/dist/navigation/NavigationClient.js +1 -1
  72. package/dist/network/FetchClient.js +1 -1
  73. package/dist/network/XhrClient.js +1 -1
  74. package/dist/packageMetadata.d.ts +1 -1
  75. package/dist/packageMetadata.js +2 -2
  76. package/dist/packageMetadata.js.map +1 -1
  77. package/dist/telemetry/BrowserPerformanceClient.js +1 -1
  78. package/dist/telemetry/BrowserPerformanceMeasurement.js +1 -1
  79. package/dist/utils/BrowserConstants.d.ts +1 -1
  80. package/dist/utils/BrowserConstants.js +2 -2
  81. package/dist/utils/BrowserConstants.js.map +1 -1
  82. package/dist/utils/BrowserProtocolUtils.js +1 -1
  83. package/dist/utils/BrowserStringUtils.js +1 -1
  84. package/dist/utils/BrowserUtils.js +1 -1
  85. package/dist/utils/MathUtils.js +1 -1
  86. package/lib/msal-browser.js +296 -132
  87. package/lib/msal-browser.js.map +1 -1
  88. package/lib/msal-browser.min.js +44 -44
  89. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"PublicClientApplication.js","sources":["../../src/app/PublicClientApplication.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AccountInfo, AuthenticationResult, Constants, RequestThumbprint, AuthError, PerformanceEvents, ServerError, InteractionRequiredAuthError } from \"@azure/msal-common\";\nimport { Configuration } from \"../config/Configuration\";\nimport { DEFAULT_REQUEST, InteractionType, ApiId, CacheLookupPolicy, BrowserConstants } from \"../utils/BrowserConstants\";\nimport { IPublicClientApplication } from \"./IPublicClientApplication\";\nimport { RedirectRequest } from \"../request/RedirectRequest\";\nimport { PopupRequest } from \"../request/PopupRequest\";\nimport { ClientApplication } from \"./ClientApplication\";\nimport { SilentRequest } from \"../request/SilentRequest\";\nimport { EventType } from \"../event/EventType\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { NativeAuthError } from \"../error/NativeAuthError\";\nimport { NativeMessageHandler } from \"../broker/nativeBroker/NativeMessageHandler\";\nimport { BrowserUtils } from \"../utils/BrowserUtils\";\n\n/**\n * The PublicClientApplication class is the object exposed by the library to perform authentication and authorization functions in Single Page Applications\n * to obtain JWT tokens as described in the OAuth 2.0 Authorization Code Flow with PKCE specification.\n */\nexport class PublicClientApplication extends ClientApplication implements IPublicClientApplication {\n\n // Active requests\n private activeSilentTokenRequests: Map<string, Promise<AuthenticationResult>>;\n\n /**\n * @constructor\n * Constructor for the PublicClientApplication used to instantiate the PublicClientApplication object\n *\n * Important attributes in the Configuration object for auth are:\n * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview\n * - authority: the authority URL for your application.\n * - redirect_uri: the uri of your application registered in the portal.\n *\n * In Azure AD, authority is a URL indicating the Azure active directory that MSAL uses to obtain tokens.\n * It is of the form https://login.microsoftonline.com/{Enter_the_Tenant_Info_Here}\n * If your application supports Accounts in one organizational directory, replace \"Enter_the_Tenant_Info_Here\" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).\n * If your application supports Accounts in any organizational directory, replace \"Enter_the_Tenant_Info_Here\" value with organizations.\n * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace \"Enter_the_Tenant_Info_Here\" value with common.\n * To restrict support to Personal Microsoft accounts only, replace \"Enter_the_Tenant_Info_Here\" value with consumers.\n *\n * In Azure B2C, authority is of the form https://{instance}/tfp/{tenant}/{policyName}/\n * Full B2C functionality will be available in this library in future versions.\n *\n * @param configuration object for the MSAL PublicClientApplication instance\n */\n constructor(configuration: Configuration) {\n super(configuration);\n\n this.activeSilentTokenRequests = new Map();\n }\n\n /**\n * Use when initiating the login process by redirecting the user's browser to the authorization endpoint. This function redirects the page, so\n * any code that follows this function will not execute.\n *\n * IMPORTANT: It is NOT recommended to have code that is dependent on the resolution of the Promise. This function will navigate away from the current\n * browser window. It currently returns a Promise in order to reflect the asynchronous nature of the code running in this function.\n *\n * @param request\n */\n async loginRedirect(request?: RedirectRequest): Promise<void> {\n const correlationId: string = this.getRequestCorrelationId(request);\n this.logger.verbose(\"loginRedirect called\", correlationId);\n return this.acquireTokenRedirect({\n correlationId,\n ...(request || DEFAULT_REQUEST)\n });\n }\n\n /**\n * Use when initiating the login process via opening a popup window in the user's browser\n *\n * @param request\n *\n * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.\n */\n loginPopup(request?: PopupRequest): Promise<AuthenticationResult> {\n const correlationId: string = this.getRequestCorrelationId(request);\n this.logger.verbose(\"loginPopup called\", correlationId);\n return this.acquireTokenPopup({\n correlationId,\n ...(request || DEFAULT_REQUEST)\n });\n }\n\n /**\n * Silently acquire an access token for a given set of scopes. Returns currently processing promise if parallel requests are made.\n *\n * @param {@link (SilentRequest:type)}\n * @returns {Promise.<AuthenticationResult>} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object\n */\n async acquireTokenSilent(request: SilentRequest): Promise<AuthenticationResult> {\n const correlationId = this.getRequestCorrelationId(request);\n const atsMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenSilent, correlationId);\n \n this.preflightBrowserEnvironmentCheck(InteractionType.Silent);\n this.logger.verbose(\"acquireTokenSilent called\", correlationId);\n\n const account = request.account || this.getActiveAccount();\n if (!account) {\n throw BrowserAuthError.createNoAccountError();\n }\n\n const thumbprint: RequestThumbprint = {\n clientId: this.config.auth.clientId,\n authority: request.authority || Constants.EMPTY_STRING,\n scopes: request.scopes,\n homeAccountIdentifier: account.homeAccountId,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n const silentRequestKey = JSON.stringify(thumbprint);\n\n const cachedResponse = this.activeSilentTokenRequests.get(silentRequestKey);\n if (typeof cachedResponse === \"undefined\") {\n this.logger.verbose(\"acquireTokenSilent called for the first time, storing active request\", correlationId);\n\n const response = this.acquireTokenSilentAsync({\n ...request,\n correlationId\n }, account)\n .then((result) => {\n this.activeSilentTokenRequests.delete(silentRequestKey);\n atsMeasurement.endMeasurement({\n success: true,\n fromCache: result.fromCache,\n accessTokenSize: result.accessToken.length,\n idTokenSize: result.idToken.length,\n isNativeBroker: result.fromNativeBroker,\n cacheLookupPolicy: request.cacheLookupPolicy,\n requestId: result.requestId\n });\n atsMeasurement.flushMeasurement();\n return result;\n })\n .catch((error: AuthError) => {\n this.activeSilentTokenRequests.delete(silentRequestKey);\n atsMeasurement.endMeasurement({\n errorCode: error.errorCode,\n subErrorCode: error.subError,\n success: false\n });\n atsMeasurement.flushMeasurement();\n throw error;\n });\n this.activeSilentTokenRequests.set(silentRequestKey, response);\n return response;\n } else {\n this.logger.verbose(\"acquireTokenSilent has been called previously, returning the result from the first call\", correlationId);\n atsMeasurement.endMeasurement({\n success: true\n });\n // Discard measurements for memoized calls, as they are usually only a couple of ms and will artificially deflate metrics\n atsMeasurement.discardMeasurement();\n return cachedResponse;\n }\n }\n\n /**\n * Silently acquire an access token for a given set of scopes. Will use cached token if available, otherwise will attempt to acquire a new token from the network via refresh token.\n * @param {@link (SilentRequest:type)}\n * @param {@link (AccountInfo:type)}\n * @returns {Promise.<AuthenticationResult>} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} \n */\n protected async acquireTokenSilentAsync(request: SilentRequest, account: AccountInfo): Promise<AuthenticationResult>{\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Silent, request);\n const astsAsyncMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenSilentAsync, request.correlationId);\n\n let result: Promise<AuthenticationResult>;\n if (NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeExtensionProvider, request.authenticationScheme) && account.nativeAccountId) {\n this.logger.verbose(\"acquireTokenSilent - attempting to acquire token from native platform\");\n const silentRequest: SilentRequest = {\n ...request,\n account\n };\n result = this.acquireTokenNative(silentRequest, ApiId.acquireTokenSilent_silentFlow).catch(async (e: AuthError) => {\n // If native token acquisition fails for availability reasons fallback to web flow\n if (e instanceof NativeAuthError && e.isFatal()) {\n this.logger.verbose(\"acquireTokenSilent - native platform unavailable, falling back to web flow\");\n this.nativeExtensionProvider = undefined; // Prevent future requests from continuing to attempt \n\n // Cache will not contain tokens, given that previous WAM requests succeeded. Skip cache and RT renewal and go straight to iframe renewal\n const silentIframeClient = this.createSilentIframeClient(request.correlationId);\n return silentIframeClient.acquireToken(request);\n }\n throw e;\n }); \n } else {\n this.logger.verbose(\"acquireTokenSilent - attempting to acquire token from web flow\");\n\n const silentCacheClient = this.createSilentCacheClient(request.correlationId);\n const silentRequest = await silentCacheClient.initializeSilentRequest(request, account);\n \n const requestWithCLP = {\n ...request,\n // set the request's CacheLookupPolicy to Default if it was not optionally passed in\n cacheLookupPolicy: request.cacheLookupPolicy || CacheLookupPolicy.Default\n };\n\n result = this.acquireTokenFromCache(silentCacheClient, silentRequest, requestWithCLP).catch((cacheError: AuthError) => {\n if (requestWithCLP.cacheLookupPolicy === CacheLookupPolicy.AccessToken) {\n throw cacheError;\n }\n\n // block the reload if it occurred inside a hidden iframe\n BrowserUtils.blockReloadInHiddenIframes();\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_NETWORK_START, InteractionType.Silent, silentRequest);\n\n return this.acquireTokenByRefreshToken(silentRequest, requestWithCLP).catch((refreshTokenError: AuthError) => {\n const isServerError = refreshTokenError instanceof ServerError;\n const isInteractionRequiredError = refreshTokenError instanceof InteractionRequiredAuthError;\n const isInvalidGrantError = (refreshTokenError.errorCode === BrowserConstants.INVALID_GRANT_ERROR);\n\n if ((!isServerError ||\n !isInvalidGrantError ||\n isInteractionRequiredError ||\n requestWithCLP.cacheLookupPolicy === CacheLookupPolicy.AccessTokenAndRefreshToken ||\n requestWithCLP.cacheLookupPolicy === CacheLookupPolicy.RefreshToken)\n && (requestWithCLP.cacheLookupPolicy !== CacheLookupPolicy.Skip)\n ) {\n throw refreshTokenError;\n }\n \n this.logger.verbose(\"Refresh token expired/invalid or CacheLookupPolicy is set to Skip, attempting acquire token by iframe.\", request.correlationId);\n return this.acquireTokenBySilentIframe(silentRequest);\n });\n });\n }\n\n return result.then((response) => {\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Silent, response);\n astsAsyncMeasurement.endMeasurement({\n success: true,\n fromCache: response.fromCache,\n accessTokenSize: response.accessToken.length,\n idTokenSize: response.idToken.length,\n isNativeBroker: response.fromNativeBroker,\n requestId: response.requestId\n });\n return response;\n }).catch((tokenRenewalError: AuthError) => {\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Silent, null, tokenRenewalError);\n astsAsyncMeasurement.endMeasurement({\n errorCode: tokenRenewalError.errorCode,\n subErrorCode: tokenRenewalError.subError,\n success: false\n });\n throw tokenRenewalError;\n });\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAmBA;;;;;IAI6C,2CAAiB;;;;;;;;;;;;;;;;;;;;;;IA0B1D,iCAAY,aAA4B;QAAxC,YACI,kBAAM,aAAa,CAAC,SAGvB;QADG,KAAI,CAAC,yBAAyB,GAAG,IAAI,GAAG,EAAE,CAAC;;KAC9C;;;;;;;;;;IAWK,+CAAa,GAAnB,UAAoB,OAAyB;;;;gBACnC,aAAa,GAAW,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;gBACpE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;gBAC3D,sBAAO,IAAI,CAAC,oBAAoB,YAC5B,aAAa,eAAA,KACT,OAAO,IAAI,eAAe,GAChC,EAAC;;;KACN;;;;;;;;IASD,4CAAU,GAAV,UAAW,OAAsB;QAC7B,IAAM,aAAa,GAAW,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACpE,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ACN;IACL,8BAAC;AAAD,CA3OA,CAA6C,iBAAiB;;;;"}
1
+ {"version":3,"file":"PublicClientApplication.js","sources":["../../src/app/PublicClientApplication.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AccountInfo, AuthenticationResult, Constants, RequestThumbprint, AuthError, PerformanceEvents, ServerError, InteractionRequiredAuthError } from \"@azure/msal-common\";\nimport { Configuration } from \"../config/Configuration\";\nimport { DEFAULT_REQUEST, InteractionType, ApiId, CacheLookupPolicy, BrowserConstants } from \"../utils/BrowserConstants\";\nimport { IPublicClientApplication } from \"./IPublicClientApplication\";\nimport { RedirectRequest } from \"../request/RedirectRequest\";\nimport { PopupRequest } from \"../request/PopupRequest\";\nimport { ClientApplication } from \"./ClientApplication\";\nimport { SilentRequest } from \"../request/SilentRequest\";\nimport { EventType } from \"../event/EventType\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { NativeAuthError } from \"../error/NativeAuthError\";\nimport { NativeMessageHandler } from \"../broker/nativeBroker/NativeMessageHandler\";\nimport { BrowserUtils } from \"../utils/BrowserUtils\";\n\n/**\n * The PublicClientApplication class is the object exposed by the library to perform authentication and authorization functions in Single Page Applications\n * to obtain JWT tokens as described in the OAuth 2.0 Authorization Code Flow with PKCE specification.\n */\nexport class PublicClientApplication extends ClientApplication implements IPublicClientApplication {\n\n // Active requests\n private activeSilentTokenRequests: Map<string, Promise<AuthenticationResult>>;\n\n /**\n * @constructor\n * Constructor for the PublicClientApplication used to instantiate the PublicClientApplication object\n *\n * Important attributes in the Configuration object for auth are:\n * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview\n * - authority: the authority URL for your application.\n * - redirect_uri: the uri of your application registered in the portal.\n *\n * In Azure AD, authority is a URL indicating the Azure active directory that MSAL uses to obtain tokens.\n * It is of the form https://login.microsoftonline.com/{Enter_the_Tenant_Info_Here}\n * If your application supports Accounts in one organizational directory, replace \"Enter_the_Tenant_Info_Here\" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).\n * If your application supports Accounts in any organizational directory, replace \"Enter_the_Tenant_Info_Here\" value with organizations.\n * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace \"Enter_the_Tenant_Info_Here\" value with common.\n * To restrict support to Personal Microsoft accounts only, replace \"Enter_the_Tenant_Info_Here\" value with consumers.\n *\n * In Azure B2C, authority is of the form https://{instance}/tfp/{tenant}/{policyName}/\n * Full B2C functionality will be available in this library in future versions.\n *\n * @param configuration object for the MSAL PublicClientApplication instance\n */\n constructor(configuration: Configuration) {\n super(configuration);\n\n this.activeSilentTokenRequests = new Map();\n }\n\n /**\n * Use when initiating the login process by redirecting the user's browser to the authorization endpoint. This function redirects the page, so\n * any code that follows this function will not execute.\n *\n * IMPORTANT: It is NOT recommended to have code that is dependent on the resolution of the Promise. This function will navigate away from the current\n * browser window. It currently returns a Promise in order to reflect the asynchronous nature of the code running in this function.\n *\n * @param request\n */\n async loginRedirect(request?: RedirectRequest): Promise<void> {\n const correlationId: string = this.getRequestCorrelationId(request);\n this.logger.verbose(\"loginRedirect called\", correlationId);\n return this.acquireTokenRedirect({\n correlationId,\n ...(request || DEFAULT_REQUEST)\n });\n }\n\n /**\n * Use when initiating the login process via opening a popup window in the user's browser\n *\n * @param request\n *\n * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.\n */\n loginPopup(request?: PopupRequest): Promise<AuthenticationResult> {\n const correlationId: string = this.getRequestCorrelationId(request);\n this.logger.verbose(\"loginPopup called\", correlationId);\n return this.acquireTokenPopup({\n correlationId,\n ...(request || DEFAULT_REQUEST)\n });\n }\n\n /**\n * Silently acquire an access token for a given set of scopes. Returns currently processing promise if parallel requests are made.\n *\n * @param {@link (SilentRequest:type)}\n * @returns {Promise.<AuthenticationResult>} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object\n */\n async acquireTokenSilent(request: SilentRequest): Promise<AuthenticationResult> {\n const correlationId = this.getRequestCorrelationId(request);\n const atsMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenSilent, correlationId);\n atsMeasurement.addStaticFields({\n cacheLookupPolicy: request.cacheLookupPolicy\n });\n \n this.preflightBrowserEnvironmentCheck(InteractionType.Silent);\n this.logger.verbose(\"acquireTokenSilent called\", correlationId);\n\n const account = request.account || this.getActiveAccount();\n if (!account) {\n throw BrowserAuthError.createNoAccountError();\n }\n\n const thumbprint: RequestThumbprint = {\n clientId: this.config.auth.clientId,\n authority: request.authority || Constants.EMPTY_STRING,\n scopes: request.scopes,\n homeAccountIdentifier: account.homeAccountId,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n const silentRequestKey = JSON.stringify(thumbprint);\n\n const cachedResponse = this.activeSilentTokenRequests.get(silentRequestKey);\n if (typeof cachedResponse === \"undefined\") {\n this.logger.verbose(\"acquireTokenSilent called for the first time, storing active request\", correlationId);\n\n const response = this.acquireTokenSilentAsync({\n ...request,\n correlationId\n }, account)\n .then((result) => {\n this.activeSilentTokenRequests.delete(silentRequestKey);\n atsMeasurement.addStaticFields({\n accessTokenSize: result.accessToken.length,\n idTokenSize: result.idToken.length\n });\n atsMeasurement.endMeasurement({\n success: true,\n fromCache: result.fromCache,\n isNativeBroker: result.fromNativeBroker,\n requestId: result.requestId\n });\n atsMeasurement.flushMeasurement();\n return result;\n })\n .catch((error: AuthError) => {\n this.activeSilentTokenRequests.delete(silentRequestKey);\n atsMeasurement.endMeasurement({\n errorCode: error.errorCode,\n subErrorCode: error.subError,\n success: false\n });\n atsMeasurement.flushMeasurement();\n throw error;\n });\n this.activeSilentTokenRequests.set(silentRequestKey, response);\n return response;\n } else {\n this.logger.verbose(\"acquireTokenSilent has been called previously, returning the result from the first call\", correlationId);\n atsMeasurement.endMeasurement({\n success: true\n });\n // Discard measurements for memoized calls, as they are usually only a couple of ms and will artificially deflate metrics\n atsMeasurement.discardMeasurement();\n return cachedResponse;\n }\n }\n\n /**\n * Silently acquire an access token for a given set of scopes. Will use cached token if available, otherwise will attempt to acquire a new token from the network via refresh token.\n * @param {@link (SilentRequest:type)}\n * @param {@link (AccountInfo:type)}\n * @returns {Promise.<AuthenticationResult>} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} \n */\n protected async acquireTokenSilentAsync(request: SilentRequest, account: AccountInfo): Promise<AuthenticationResult>{\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Silent, request);\n const astsAsyncMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenSilentAsync, request.correlationId);\n\n let result: Promise<AuthenticationResult>;\n if (NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeExtensionProvider, request.authenticationScheme) && account.nativeAccountId) {\n this.logger.verbose(\"acquireTokenSilent - attempting to acquire token from native platform\");\n const silentRequest: SilentRequest = {\n ...request,\n account\n };\n result = this.acquireTokenNative(silentRequest, ApiId.acquireTokenSilent_silentFlow).catch(async (e: AuthError) => {\n // If native token acquisition fails for availability reasons fallback to web flow\n if (e instanceof NativeAuthError && e.isFatal()) {\n this.logger.verbose(\"acquireTokenSilent - native platform unavailable, falling back to web flow\");\n this.nativeExtensionProvider = undefined; // Prevent future requests from continuing to attempt \n\n // Cache will not contain tokens, given that previous WAM requests succeeded. Skip cache and RT renewal and go straight to iframe renewal\n const silentIframeClient = this.createSilentIframeClient(request.correlationId);\n return silentIframeClient.acquireToken(request);\n }\n throw e;\n }); \n } else {\n this.logger.verbose(\"acquireTokenSilent - attempting to acquire token from web flow\");\n\n const silentCacheClient = this.createSilentCacheClient(request.correlationId);\n const silentRequest = await silentCacheClient.initializeSilentRequest(request, account);\n \n const requestWithCLP = {\n ...request,\n // set the request's CacheLookupPolicy to Default if it was not optionally passed in\n cacheLookupPolicy: request.cacheLookupPolicy || CacheLookupPolicy.Default\n };\n\n result = this.acquireTokenFromCache(silentCacheClient, silentRequest, requestWithCLP).catch((cacheError: AuthError) => {\n if (requestWithCLP.cacheLookupPolicy === CacheLookupPolicy.AccessToken) {\n throw cacheError;\n }\n\n // block the reload if it occurred inside a hidden iframe\n BrowserUtils.blockReloadInHiddenIframes();\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_NETWORK_START, InteractionType.Silent, silentRequest);\n\n return this.acquireTokenByRefreshToken(silentRequest, requestWithCLP).catch((refreshTokenError: AuthError) => {\n const isServerError = refreshTokenError instanceof ServerError;\n const isInteractionRequiredError = refreshTokenError instanceof InteractionRequiredAuthError;\n const isInvalidGrantError = (refreshTokenError.errorCode === BrowserConstants.INVALID_GRANT_ERROR);\n\n if ((!isServerError ||\n !isInvalidGrantError ||\n isInteractionRequiredError ||\n requestWithCLP.cacheLookupPolicy === CacheLookupPolicy.AccessTokenAndRefreshToken ||\n requestWithCLP.cacheLookupPolicy === CacheLookupPolicy.RefreshToken)\n && (requestWithCLP.cacheLookupPolicy !== CacheLookupPolicy.Skip)\n ) {\n throw refreshTokenError;\n }\n \n this.logger.verbose(\"Refresh token expired/invalid or CacheLookupPolicy is set to Skip, attempting acquire token by iframe.\", request.correlationId);\n return this.acquireTokenBySilentIframe(silentRequest);\n });\n });\n }\n\n return result.then((response) => {\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Silent, response);\n astsAsyncMeasurement.endMeasurement({\n success: true,\n fromCache: response.fromCache,\n isNativeBroker: response.fromNativeBroker,\n requestId: response.requestId\n });\n return response;\n }).catch((tokenRenewalError: AuthError) => {\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Silent, null, tokenRenewalError);\n astsAsyncMeasurement.endMeasurement({\n errorCode: tokenRenewalError.errorCode,\n subErrorCode: tokenRenewalError.subError,\n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AE,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;4BAC/F,oBAAoB,CAAC,cAAc,CAAC;gCAChC,OAAO,EAAE,IAAI;gCACb,SAAS,EAAE,QAAQ,CAAC,SAAS;gCAC7B,cAAc,EAAE,QAAQ,CAAC,gBAAgB;gCACzC,SAAS,EAAE,QAAQ,CAAC,SAAS;6BAChC,CAAC,CAAC;4BACH,OAAO,QAAQ,CAAC;yBACnB,CAAC,CAAC,KAAK,CAAC,UAAC,iBAA4B;4BAClC,KAAI,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,qBAAqB,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC;4BAC9G,oBAAoB,CAAC,cAAc,CAAC;gCAChC,SAAS,EAAE,iBAAiB,CAAC,SAAS;gCACtC,YAAY,EAAE,iBAAiB,CAAC,QAAQ;gCACxC,OAAO,EAAE,KAAK;6BACjB,CAAC,CAAC;4BACH,MAAM,iBAAiB,CAAC;yBAC3B,CAAC,EAAC;;;;KACN;IACL,8BAAC;AAAD,CA7OA,CAA6C,iBAAiB;;;;"}
@@ -3,6 +3,7 @@ import { NativeExtensionRequestBody } from "./NativeRequest";
3
3
  import { BrowserConfiguration } from "../../config/Configuration";
4
4
  export declare class NativeMessageHandler {
5
5
  private extensionId;
6
+ private extensionVersion;
6
7
  private logger;
7
8
  private handshakeTimeoutMs;
8
9
  private responseId;
@@ -37,6 +38,16 @@ export declare class NativeMessageHandler {
37
38
  * @param event
38
39
  */
39
40
  private onChannelMessage;
41
+ /**
42
+ * Returns the Id for the browser extension this handler is communicating with
43
+ * @returns
44
+ */
45
+ getExtensionId(): string | undefined;
46
+ /**
47
+ * Returns the version for the browser extension this handler is communicating with
48
+ * @returns
49
+ */
50
+ getExtensionVersion(): string | undefined;
40
51
  /**
41
52
  * Returns boolean indicating whether or not the request should attempt to use native broker
42
53
  * @param logger
@@ -1 +1 @@
1
- {"version":3,"file":"NativeMessageHandler.d.ts","sourceRoot":"","sources":["../../../src/broker/nativeBroker/NativeMessageHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAa,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAA0B,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAGrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAOlE,qBAAa,oBAAoB;IAC7B,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,SAAS,CAAyC;IAC1D,OAAO,CAAC,kBAAkB,CAAuC;IACjE,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,cAAc,CAAgC;gBAE1C,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAW5E;;;OAGG;IACG,WAAW,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBpE;;;;OAIG;WACU,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IActG;;OAEG;YACW,oBAAoB;IAqClC;;;OAGG;IACH,OAAO,CAAC,eAAe;IA+BvB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAuDxB;;;;;;OAMG;IACH,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,CAAC,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,EAAE,oBAAoB,GAAG,OAAO;CA4B/K"}
1
+ {"version":3,"file":"NativeMessageHandler.d.ts","sourceRoot":"","sources":["../../../src/broker/nativeBroker/NativeMessageHandler.ts"],"names":[],"mappings":"AAMA,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0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator } from '../../_virtual/_tslib.js';
4
4
  import { NativeConstants, NativeExtensionMethod } from '../../utils/BrowserConstants.js';
@@ -189,6 +189,7 @@ var NativeMessageHandler = /** @class */ (function () {
189
189
  clearTimeout(this.timeoutId); // Clear setTimeout
190
190
  window.removeEventListener("message", this.windowListener, false); // Remove 'No extension' listener
191
191
  this.extensionId = request.extensionId;
192
+ this.extensionVersion = request.body.version;
192
193
  this.logger.verbose("NativeMessageHandler - Received HandshakeResponse from extension: " + this.extensionId);
193
194
  handshakeResolver.resolve();
194
195
  this.handshakeResolvers.delete(request.responseId);
@@ -207,6 +208,20 @@ var NativeMessageHandler = /** @class */ (function () {
207
208
  }
208
209
  }
209
210
  };
211
+ /**
212
+ * Returns the Id for the browser extension this handler is communicating with
213
+ * @returns
214
+ */
215
+ NativeMessageHandler.prototype.getExtensionId = function () {
216
+ return this.extensionId;
217
+ };
218
+ /**
219
+ * Returns the version for the browser extension this handler is communicating with
220
+ * @returns
221
+ */
222
+ NativeMessageHandler.prototype.getExtensionVersion = function () {
223
+ return this.extensionVersion;
224
+ };
210
225
  /**
211
226
  * Returns boolean indicating whether or not the request should attempt to use native broker
212
227
  * @param logger
@@ -1 +1 @@
1
- {"version":3,"file":"NativeMessageHandler.js","sources":["../../../src/broker/nativeBroker/NativeMessageHandler.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NativeConstants, NativeExtensionMethod } from \"../../utils/BrowserConstants\";\nimport { Logger, AuthError, AuthenticationScheme } from \"@azure/msal-common\";\nimport { NativeExtensionRequest, NativeExtensionRequestBody } from \"./NativeRequest\";\nimport { NativeAuthError } from \"../../error/NativeAuthError\";\nimport { BrowserAuthError } from \"../../error/BrowserAuthError\";\nimport { BrowserConfiguration } from \"../../config/Configuration\";\n\ntype ResponseResolvers<T> = {\n resolve: (value:T|PromiseLike<T>) => void;\n reject: (value:AuthError|Error|PromiseLike<Error>|PromiseLike<AuthError>) => void;\n};\n\nexport class NativeMessageHandler {\n private extensionId: string | undefined;\n private logger: Logger;\n private handshakeTimeoutMs: number;\n private responseId: number;\n private timeoutId: number | undefined;\n private resolvers: Map<number, ResponseResolvers<object>>;\n private handshakeResolvers: Map<number, ResponseResolvers<void>>;\n private messageChannel: MessageChannel;\n private windowListener: (event: MessageEvent) => void;\n\n constructor(logger: Logger, handshakeTimeoutMs: number, extensionId?: string) {\n this.logger = logger;\n this.handshakeTimeoutMs = handshakeTimeoutMs;\n this.extensionId = extensionId;\n this.resolvers = new Map(); // Used for non-handshake messages\n this.handshakeResolvers = new Map(); // Used for handshake messages\n this.responseId = 0;\n this.messageChannel = new MessageChannel();\n this.windowListener = this.onWindowMessage.bind(this); // Window event callback doesn't have access to 'this' unless it's bound\n }\n\n /**\n * Sends a given message to the extension and resolves with the extension response\n * @param body \n */\n async sendMessage(body: NativeExtensionRequestBody): Promise<object> {\n this.logger.trace(\"NativeMessageHandler - sendMessage called.\");\n const req: NativeExtensionRequest = {\n channel: NativeConstants.CHANNEL_ID,\n extensionId: this.extensionId,\n responseId: this.responseId++,\n body: body\n };\n\n this.logger.trace(\"NativeMessageHandler - Sending request to browser extension\");\n this.logger.tracePii(`NativeMessageHandler - Sending request to browser extension: ${JSON.stringify(req)}`);\n this.messageChannel.port1.postMessage(req);\n\n return new Promise((resolve, reject) => {\n this.resolvers.set(req.responseId, {resolve, reject});\n });\n }\n\n /**\n * Returns an instance of the MessageHandler that has successfully established a connection with an extension\n * @param logger \n * @param handshakeTimeoutMs\n */\n static async createProvider(logger: Logger, handshakeTimeoutMs: number): Promise<NativeMessageHandler> {\n logger.trace(\"NativeMessageHandler - createProvider called.\");\n try {\n const preferredProvider = new NativeMessageHandler(logger, handshakeTimeoutMs, NativeConstants.PREFERRED_EXTENSION_ID);\n await preferredProvider.sendHandshakeRequest();\n return preferredProvider;\n } catch (e) {\n // If preferred extension fails for whatever reason, fallback to using any installed extension\n const backupProvider = new NativeMessageHandler(logger, handshakeTimeoutMs);\n await backupProvider.sendHandshakeRequest();\n return backupProvider;\n }\n }\n\n /**\n * Send handshake request helper.\n */\n private async sendHandshakeRequest(): Promise<void> {\n this.logger.trace(\"NativeMessageHandler - sendHandshakeRequest called.\");\n // Register this event listener before sending handshake\n window.addEventListener(\"message\", this.windowListener, false); // false is important, because content script message processing should work first\n\n const req: NativeExtensionRequest = {\n channel: NativeConstants.CHANNEL_ID,\n extensionId: this.extensionId,\n responseId: this.responseId++,\n\n body: {\n method: NativeExtensionMethod.HandshakeRequest\n }\n };\n\n this.messageChannel.port1.onmessage = (event) => {\n this.onChannelMessage(event);\n };\n\n window.postMessage(req, window.origin, [this.messageChannel.port2]);\n\n return new Promise((resolve, reject) => {\n this.handshakeResolvers.set(req.responseId, {resolve, reject});\n this.timeoutId = window.setTimeout(() => {\n /*\n * Throw an error if neither HandshakeResponse nor original Handshake request are received in a reasonable timeframe.\n * This typically suggests an event handler stopped propagation of the Handshake request but did not respond to it on the MessageChannel port\n */\n window.removeEventListener(\"message\", this.windowListener, false);\n this.messageChannel.port1.close();\n this.messageChannel.port2.close();\n reject(BrowserAuthError.createNativeHandshakeTimeoutError());\n this.handshakeResolvers.delete(req.responseId);\n }, this.handshakeTimeoutMs); // Use a reasonable timeout in milliseconds here\n });\n }\n\n /**\n * Invoked when a message is posted to the window. If a handshake request is received it means the extension is not installed.\n * @param event \n */\n private onWindowMessage(event: MessageEvent): void {\n this.logger.trace(\"NativeMessageHandler - onWindowMessage called\");\n // We only accept messages from ourselves\n if (event.source !== window) {\n return;\n }\n\n const request = event.data;\n\n if (!request.channel || request.channel !== NativeConstants.CHANNEL_ID) {\n return;\n }\n\n if (request.extensionId && request.extensionId !== this.extensionId) {\n return;\n }\n\n if (request.body.method === NativeExtensionMethod.HandshakeRequest) {\n // If we receive this message back it means no extension intercepted the request, meaning no extension supporting handshake protocol is installed\n this.logger.verbose(request.extensionId ? `Extension with id: ${request.extensionId} not installed` : \"No extension installed\");\n clearTimeout(this.timeoutId);\n this.messageChannel.port1.close();\n this.messageChannel.port2.close();\n window.removeEventListener(\"message\", this.windowListener, false);\n const handshakeResolver = this.handshakeResolvers.get(request.responseId);\n if (handshakeResolver) {\n handshakeResolver.reject(BrowserAuthError.createNativeExtensionNotInstalledError());\n }\n }\n }\n\n /**\n * Invoked when a message is received from the extension on the MessageChannel port\n * @param event \n */\n private onChannelMessage(event: MessageEvent): void {\n this.logger.trace(\"NativeMessageHandler - onChannelMessage called.\");\n const request = event.data;\n \n const resolver = this.resolvers.get(request.responseId);\n const handshakeResolver = this.handshakeResolvers.get(request.responseId);\n\n try {\n const method = request.body.method;\n \n if (method === NativeExtensionMethod.Response) {\n if (!resolver) {\n return;\n }\n const response = request.body.response;\n this.logger.trace(\"NativeMessageHandler - Received response from browser extension\");\n this.logger.tracePii(`NativeMessageHandler - Received response from browser extension: ${JSON.stringify(response)}`);\n if (response.status !== \"Success\") {\n resolver.reject(NativeAuthError.createError(response.code, response.description, response.ext));\n } else if (response.result) {\n if (response.result[\"code\"] && response.result[\"description\"]) {\n resolver.reject(NativeAuthError.createError(response.result[\"code\"], response.result[\"description\"], response.result[\"ext\"]));\n } else {\n resolver.resolve(response.result);\n }\n } else {\n throw AuthError.createUnexpectedError(\"Event does not contain result.\");\n }\n this.resolvers.delete(request.responseId);\n } else if (method === NativeExtensionMethod.HandshakeResponse) {\n if (!handshakeResolver) {\n return;\n }\n clearTimeout(this.timeoutId); // Clear setTimeout\n window.removeEventListener(\"message\", this.windowListener, false); // Remove 'No extension' listener\n this.extensionId = request.extensionId;\n this.logger.verbose(`NativeMessageHandler - Received HandshakeResponse from extension: ${this.extensionId}`);\n\n handshakeResolver.resolve();\n this.handshakeResolvers.delete(request.responseId);\n } \n // Do nothing if method is not Response or HandshakeResponse\n } catch (err) {\n this.logger.error(\"Error parsing response from WAM Extension\");\n this.logger.errorPii(`Error parsing response from WAM Extension: ${err.toString()}`);\n this.logger.errorPii(`Unable to parse ${event}`);\n\n if (resolver) {\n resolver.reject(err as AuthError);\n } else if (handshakeResolver) {\n handshakeResolver.reject(err as AuthError);\n }\n }\n }\n \n /**\n * Returns boolean indicating whether or not the request should attempt to use native broker\n * @param logger\n * @param config\n * @param nativeExtensionProvider\n * @param authenticationScheme \n */\n static isNativeAvailable(config: BrowserConfiguration, logger: Logger, nativeExtensionProvider?: NativeMessageHandler, authenticationScheme?: AuthenticationScheme): boolean {\n logger.trace(\"isNativeAvailable called\");\n if (!config.system.allowNativeBroker) {\n logger.trace(\"isNativeAvailable: allowNativeBroker is not enabled, returning false\");\n // Developer disabled WAM\n return false;\n }\n\n if (!nativeExtensionProvider) {\n logger.trace(\"isNativeAvailable: WAM extension provider is not initialized, returning false\");\n // Extension is not available\n return false;\n }\n\n if (authenticationScheme) {\n switch(authenticationScheme) {\n case AuthenticationScheme.BEARER:\n case AuthenticationScheme.POP:\n logger.trace(\"isNativeAvailable: authenticationScheme is supported, returning true\");\n return true;\n default:\n logger.trace(\"isNativeAvailable: authenticationScheme is not supported, returning false\");\n return false;\n }\n }\n\n return true;\n }\n} \n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;IA4BI,8BAAY,MAAc,EAAE,kBAA0B,EAAE,WAAoB;QACxE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;QAC3C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CA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;;;;;;;;IASM,sCAAiB,GAAxB,UAAyB,MAA4B,EAAE,MAAc,EAAE,uBAA8C,EAAE,oBAA2C;QAC9J,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;YAClC,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;;YAErF,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,CAAC,uBAAuB,EAAE;YAC1B,MAAM,CAAC,KAAK,CAAC,+EAA+E,CAAC,CAAC;;YAE9F,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,oBAAoB,EAAE;YACtB,QAAO,oBAAoB;gBACvB,KAAK,oBAAoB,CAAC,MAAM,CAAC;gBACjC,KAAK,oBAAoB,CAAC,GAAG;oBACzB,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;oBACrF,OAAO,IAAI,CAAC;gBAChB;oBACI,MAAM,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;oBAC1F,OAAO,KAAK,CAAC;aACpB;SACJ;QAED,OAAO,IAAI,CAAC;KACf;IACL,2BAAC;AAAD,CAAC;;;;"}
1
+ {"version":3,"file":"NativeMessageHandler.js","sources":["../../../src/broker/nativeBroker/NativeMessageHandler.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NativeConstants, NativeExtensionMethod } from \"../../utils/BrowserConstants\";\nimport { Logger, AuthError, AuthenticationScheme } from \"@azure/msal-common\";\nimport { NativeExtensionRequest, NativeExtensionRequestBody } from \"./NativeRequest\";\nimport { NativeAuthError } from \"../../error/NativeAuthError\";\nimport { BrowserAuthError } from \"../../error/BrowserAuthError\";\nimport { BrowserConfiguration } from \"../../config/Configuration\";\n\ntype ResponseResolvers<T> = {\n resolve: (value:T|PromiseLike<T>) => void;\n reject: (value:AuthError|Error|PromiseLike<Error>|PromiseLike<AuthError>) => void;\n};\n\nexport class NativeMessageHandler {\n private extensionId: string | undefined;\n private extensionVersion: string | undefined;\n private logger: Logger;\n private handshakeTimeoutMs: number;\n private responseId: number;\n private timeoutId: number | undefined;\n private resolvers: Map<number, ResponseResolvers<object>>;\n private handshakeResolvers: Map<number, ResponseResolvers<void>>;\n private messageChannel: MessageChannel;\n private windowListener: (event: MessageEvent) => void;\n\n constructor(logger: Logger, handshakeTimeoutMs: number, extensionId?: string) {\n this.logger = logger;\n this.handshakeTimeoutMs = handshakeTimeoutMs;\n this.extensionId = extensionId;\n this.resolvers = new Map(); // Used for non-handshake messages\n this.handshakeResolvers = new Map(); // Used for handshake messages\n this.responseId = 0;\n this.messageChannel = new MessageChannel();\n this.windowListener = this.onWindowMessage.bind(this); // Window event callback doesn't have access to 'this' unless it's bound\n }\n\n /**\n * Sends a given message to the extension and resolves with the extension response\n * @param body \n */\n async sendMessage(body: NativeExtensionRequestBody): Promise<object> {\n this.logger.trace(\"NativeMessageHandler - sendMessage called.\");\n const req: NativeExtensionRequest = {\n channel: NativeConstants.CHANNEL_ID,\n extensionId: this.extensionId,\n responseId: this.responseId++,\n body: body\n };\n\n this.logger.trace(\"NativeMessageHandler - Sending request to browser extension\");\n this.logger.tracePii(`NativeMessageHandler - Sending request to browser extension: ${JSON.stringify(req)}`);\n this.messageChannel.port1.postMessage(req);\n\n return new Promise((resolve, reject) => {\n this.resolvers.set(req.responseId, {resolve, reject});\n });\n }\n\n /**\n * Returns an instance of the MessageHandler that has successfully established a connection with an extension\n * @param logger \n * @param handshakeTimeoutMs\n */\n static async createProvider(logger: Logger, handshakeTimeoutMs: number): Promise<NativeMessageHandler> {\n logger.trace(\"NativeMessageHandler - createProvider called.\");\n try {\n const preferredProvider = new NativeMessageHandler(logger, handshakeTimeoutMs, NativeConstants.PREFERRED_EXTENSION_ID);\n await preferredProvider.sendHandshakeRequest();\n return preferredProvider;\n } catch (e) {\n // If preferred extension fails for whatever reason, fallback to using any installed extension\n const backupProvider = new NativeMessageHandler(logger, handshakeTimeoutMs);\n await backupProvider.sendHandshakeRequest();\n return backupProvider;\n }\n }\n\n /**\n * Send handshake request helper.\n */\n private async sendHandshakeRequest(): Promise<void> {\n this.logger.trace(\"NativeMessageHandler - sendHandshakeRequest called.\");\n // Register this event listener before sending handshake\n window.addEventListener(\"message\", this.windowListener, false); // false is important, because content script message processing should work first\n\n const req: NativeExtensionRequest = {\n channel: NativeConstants.CHANNEL_ID,\n extensionId: this.extensionId,\n responseId: this.responseId++,\n\n body: {\n method: NativeExtensionMethod.HandshakeRequest\n }\n };\n\n this.messageChannel.port1.onmessage = (event) => {\n this.onChannelMessage(event);\n };\n\n window.postMessage(req, window.origin, [this.messageChannel.port2]);\n\n return new Promise((resolve, reject) => {\n this.handshakeResolvers.set(req.responseId, {resolve, reject});\n this.timeoutId = window.setTimeout(() => {\n /*\n * Throw an error if neither HandshakeResponse nor original Handshake request are received in a reasonable timeframe.\n * This typically suggests an event handler stopped propagation of the Handshake request but did not respond to it on the MessageChannel port\n */\n window.removeEventListener(\"message\", this.windowListener, false);\n this.messageChannel.port1.close();\n this.messageChannel.port2.close();\n reject(BrowserAuthError.createNativeHandshakeTimeoutError());\n this.handshakeResolvers.delete(req.responseId);\n }, this.handshakeTimeoutMs); // Use a reasonable timeout in milliseconds here\n });\n }\n\n /**\n * Invoked when a message is posted to the window. If a handshake request is received it means the extension is not installed.\n * @param event \n */\n private onWindowMessage(event: MessageEvent): void {\n this.logger.trace(\"NativeMessageHandler - onWindowMessage called\");\n // We only accept messages from ourselves\n if (event.source !== window) {\n return;\n }\n\n const request = event.data;\n\n if (!request.channel || request.channel !== NativeConstants.CHANNEL_ID) {\n return;\n }\n\n if (request.extensionId && request.extensionId !== this.extensionId) {\n return;\n }\n\n if (request.body.method === NativeExtensionMethod.HandshakeRequest) {\n // If we receive this message back it means no extension intercepted the request, meaning no extension supporting handshake protocol is installed\n this.logger.verbose(request.extensionId ? `Extension with id: ${request.extensionId} not installed` : \"No extension installed\");\n clearTimeout(this.timeoutId);\n this.messageChannel.port1.close();\n this.messageChannel.port2.close();\n window.removeEventListener(\"message\", this.windowListener, false);\n const handshakeResolver = this.handshakeResolvers.get(request.responseId);\n if (handshakeResolver) {\n handshakeResolver.reject(BrowserAuthError.createNativeExtensionNotInstalledError());\n }\n }\n }\n\n /**\n * Invoked when a message is received from the extension on the MessageChannel port\n * @param event \n */\n private onChannelMessage(event: MessageEvent): void {\n this.logger.trace(\"NativeMessageHandler - onChannelMessage called.\");\n const request = event.data;\n \n const resolver = this.resolvers.get(request.responseId);\n const handshakeResolver = this.handshakeResolvers.get(request.responseId);\n\n try {\n const method = request.body.method;\n \n if (method === NativeExtensionMethod.Response) {\n if (!resolver) {\n return;\n }\n const response = request.body.response;\n this.logger.trace(\"NativeMessageHandler - Received response from browser extension\");\n this.logger.tracePii(`NativeMessageHandler - Received response from browser extension: ${JSON.stringify(response)}`);\n if (response.status !== \"Success\") {\n resolver.reject(NativeAuthError.createError(response.code, response.description, response.ext));\n } else if (response.result) {\n if (response.result[\"code\"] && response.result[\"description\"]) {\n resolver.reject(NativeAuthError.createError(response.result[\"code\"], response.result[\"description\"], response.result[\"ext\"]));\n } else {\n resolver.resolve(response.result);\n }\n } else {\n throw AuthError.createUnexpectedError(\"Event does not contain result.\");\n }\n this.resolvers.delete(request.responseId);\n } else if (method === NativeExtensionMethod.HandshakeResponse) {\n if (!handshakeResolver) {\n return;\n }\n clearTimeout(this.timeoutId); // Clear setTimeout\n window.removeEventListener(\"message\", this.windowListener, false); // Remove 'No extension' listener\n this.extensionId = request.extensionId;\n this.extensionVersion = request.body.version;\n this.logger.verbose(`NativeMessageHandler - Received HandshakeResponse from extension: ${this.extensionId}`);\n\n handshakeResolver.resolve();\n this.handshakeResolvers.delete(request.responseId);\n } \n // Do nothing if method is not Response or HandshakeResponse\n } catch (err) {\n this.logger.error(\"Error parsing response from WAM Extension\");\n this.logger.errorPii(`Error parsing response from WAM Extension: ${err.toString()}`);\n this.logger.errorPii(`Unable to parse ${event}`);\n\n if (resolver) {\n resolver.reject(err as AuthError);\n } else if (handshakeResolver) {\n handshakeResolver.reject(err as AuthError);\n }\n }\n }\n\n /**\n * Returns the Id for the browser extension this handler is communicating with\n * @returns \n */\n getExtensionId(): string | undefined {\n return this.extensionId;\n }\n\n /**\n * Returns the version for the browser extension this handler is communicating with\n * @returns \n */\n getExtensionVersion(): string | undefined {\n return this.extensionVersion;\n }\n \n /**\n * Returns boolean indicating whether or not the request should attempt to use native broker\n * @param logger\n * @param config\n * @param nativeExtensionProvider\n * @param authenticationScheme \n */\n static isNativeAvailable(config: BrowserConfiguration, logger: Logger, nativeExtensionProvider?: NativeMessageHandler, authenticationScheme?: AuthenticationScheme): boolean {\n logger.trace(\"isNativeAvailable called\");\n if (!config.system.allowNativeBroker) {\n logger.trace(\"isNativeAvailable: allowNativeBroker is not enabled, returning false\");\n // Developer disabled WAM\n return false;\n }\n\n if (!nativeExtensionProvider) {\n logger.trace(\"isNativeAvailable: WAM extension provider is not initialized, returning false\");\n // Extension is not available\n return false;\n }\n\n if (authenticationScheme) {\n switch(authenticationScheme) {\n case AuthenticationScheme.BEARER:\n case AuthenticationScheme.POP:\n logger.trace(\"isNativeAvailable: authenticationScheme is supported, returning true\");\n return true;\n default:\n logger.trace(\"isNativeAvailable: authenticationScheme is not supported, returning false\");\n return false;\n }\n }\n\n return true;\n }\n} \n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;IA6BI,8BAAY,MAAc,EAAE,kBAA0B,EAAE,WAAoB;QACxE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACpB,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CAAC,CAAC;YAEjD,IAAI,QAAQ,EAAE;gBACV,QAAQ,CAAC,MAAM,CAAC,GAAgB,CAAC,CAAC;aACrC;iBAAM,IAAI,iBAAiB,EAAE;gBAC1B,iBAAiB,CAAC,MAAM,CAAC,GAAgB,CAAC,CAAC;aAC9C;SACJ;KACJ;;;;;IAMD,6CAAc,GAAd;QACI,OAAO,IAAI,CAAC,WAAW,CAAC;KAC3B;;;;;IAMD,kDAAmB,GAAnB;QACI,OAAO,IAAI,CAAC,gBAAgB,CAAC;KAChC;;;;;;;;IASM,sCAAiB,GAAxB,UAAyB,MAA4B,EAAE,MAAc,EAAE,uBAA8C,EAAE,oBAA2C;QAC9J,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;YAClC,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;;YAErF,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,CAAC,uBAAuB,EAAE;YAC1B,MAAM,CAAC,KAAK,CAAC,+EAA+E,CAAC,CAAC;;YAE9F,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,oBAAoB,EAAE;YACtB,QAAO,oBAAoB;gBACvB,KAAK,oBAAoB,CAAC,MAAM,CAAC;gBACjC,KAAK,oBAAoB,CAAC,GAAG;oBACzB,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;oBACrF,OAAO,IAAI,CAAC;gBAChB;oBACI,MAAM,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;oBAC1F,OAAO,KAAK,CAAC;aACpB;SACJ;QAED,OAAO,IAAI,CAAC;KACf;IACL,2BAAC;AAAD,CAAC;;;;"}
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.29.0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { BrowserAuthError, BrowserAuthErrorMessage } from '../error/BrowserAuthError.js';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.29.0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  import { __extends, __spread, __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, Constants, PersistentCacheKeys, ClientAuthError, ThrottlingEntity, StringUtils, ProtocolUtils, CcsCredentialType, IdToken, DEFAULT_CRYPTO_IMPLEMENTATION } from '@azure/msal-common';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.29.0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  import { BrowserConfigurationAuthError } from '../error/BrowserConfigurationAuthError.js';
4
4
  import { BrowserCacheLocation } from '../utils/BrowserConstants.js';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.29.0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { AsyncMemoryStorage } from './AsyncMemoryStorage.js';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.29.0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { BrowserAuthError } from '../error/BrowserAuthError.js';
@@ -1,8 +1,11 @@
1
- import { ExternalTokenResponse } from "@azure/msal-common";
1
+ import { ExternalTokenResponse, AuthenticationResult } from "@azure/msal-common";
2
2
  import { SilentRequest } from "../request/SilentRequest";
3
3
  import { LoadTokenOptions } from "./TokenCache";
4
4
  export interface ITokenCache {
5
- /** API to side-load tokens to MSAL cache */
6
- loadExternalTokens(request: SilentRequest, response: ExternalTokenResponse, options: LoadTokenOptions): void;
5
+ /**
6
+ * API to side-load tokens to MSAL cache
7
+ * @returns `AuthenticationResult` for the response that was loaded.
8
+ */
9
+ loadExternalTokens(request: SilentRequest, response: ExternalTokenResponse, options: LoadTokenOptions): AuthenticationResult;
7
10
  }
8
11
  //# sourceMappingURL=ITokenCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ITokenCache.d.ts","sourceRoot":"","sources":["../../src/cache/ITokenCache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,WAAW;IAExB,4CAA4C;IAC5C,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChH"}
1
+ {"version":3,"file":"ITokenCache.d.ts","sourceRoot":"","sources":["../../src/cache/ITokenCache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,WAAW;IAExB;;;OAGG;IACH,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,gBAAgB,GAAG,oBAAoB,CAAC;CAEhI"}
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.29.0 2022-10-03 */
1
+ /*! @azure/msal-browser v2.31.0 2022-11-07 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1,4 +1,4 @@
1
- import { ICrypto, Logger, ExternalTokenResponse } from "@azure/msal-common";
1
+ import { ICrypto, Logger, ExternalTokenResponse, AuthenticationResult } from "@azure/msal-common";
2
2
  import { BrowserConfiguration } from "../config/Configuration";
3
3
  import { SilentRequest } from "../request/SilentRequest";
4
4
  import { BrowserCacheManager } from "./BrowserCacheManager";
@@ -23,27 +23,55 @@ export declare class TokenCache implements ITokenCache {
23
23
  * @param request
24
24
  * @param response
25
25
  * @param options
26
+ * @returns `AuthenticationResult` for the response that was loaded.
26
27
  */
27
- loadExternalTokens(request: SilentRequest, response: ExternalTokenResponse, options: LoadTokenOptions): void;
28
+ loadExternalTokens(request: SilentRequest, response: ExternalTokenResponse, options: LoadTokenOptions): AuthenticationResult;
29
+ /**
30
+ * Helper function to load account to msal-browser cache
31
+ * @param idToken
32
+ * @param environment
33
+ * @param clientInfo
34
+ * @param authorityType
35
+ * @param requestHomeAccountId
36
+ * @returns `AccountEntity`
37
+ */
38
+ private loadAccount;
28
39
  /**
29
40
  * Helper function to load id tokens to msal-browser cache
30
41
  * @param idToken
31
42
  * @param homeAccountId
32
43
  * @param environment
33
44
  * @param tenantId
34
- * @param options
45
+ * @returns `IdTokenEntity`
35
46
  */
36
47
  private loadIdToken;
37
48
  /**
38
49
  * Helper function to load access tokens to msal-browser cache
39
50
  * @param request
40
51
  * @param response
41
- * @param options
42
52
  * @param homeAccountId
43
53
  * @param environment
44
54
  * @param tenantId
45
- * @returns
55
+ * @returns `AccessTokenEntity`
46
56
  */
47
57
  private loadAccessToken;
58
+ /**
59
+ * Helper function to load refresh tokens to msal-browser cache
60
+ * @param request
61
+ * @param response
62
+ * @param homeAccountId
63
+ * @param environment
64
+ * @returns `RefreshTokenEntity`
65
+ */
66
+ private loadRefreshToken;
67
+ /**
68
+ * Helper function to generate an `AuthenticationResult` for the result.
69
+ * @param request
70
+ * @param idTokenObj
71
+ * @param cacheRecord
72
+ * @param authority
73
+ * @returns `AuthenticationResult`
74
+ */
75
+ private generateAuthenticationResult;
48
76
  }
49
77
  //# sourceMappingURL=TokenCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TokenCache.d.ts","sourceRoot":"","sources":["../../src/cache/TokenCache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAqB,OAAO,EAAiB,MAAM,EAAyC,qBAAqB,EAA4B,MAAM,oBAAoB,CAAC;AAC/K,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,oBAAY,gBAAgB,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAC;AAEF;;GAEG;AACH,qBAAa,UAAW,YAAW,WAAW;IAEnC,oBAAoB,EAAE,OAAO,CAAC;IAErC,SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAEvC,OAAO,CAAC,OAAO,CAAsB;IAErC,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,SAAS,CAAU;gBAEf,aAAa,EAAE,oBAAoB,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IAUjH;;;;;OAKG;IACH,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAuC5G;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;IAiBnB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;CA4B1B"}
1
+ {"version":3,"file":"TokenCache.d.ts","sourceRoot":"","sources":["../../src/cache/TokenCache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAqB,OAAO,EAAiB,MA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ity, AuthToken, AccountEntity, ScopeSet, AccessTokenEntity } from '@azure/msal-common';
3
+ import { AuthToken, CacheRecord, Authority, AccountEntity, IdTokenEntity, ScopeSet, AccessTokenEntity, RefreshTokenEntity, Constants } from '@azure/msal-common';
4
4
  import { BrowserAuthError } from '../error/BrowserAuthError.js';
5
5
 
6
6
  /*
@@ -24,15 +24,19 @@ var TokenCache = /** @class */ (function () {
24
24
  * @param request
25
25
  * @param response
26
26
  * @param options
27
+ * @returns `AuthenticationResult` for the response that was loaded.
27
28
  */
28
29
  TokenCache.prototype.loadExternalTokens = function (request, response, options) {
29
30
  this.logger.info("TokenCache - loadExternalTokens called");
30
31
  if (!response.id_token) {
31
32
  throw BrowserAuthError.createUnableToLoadTokenError("Please ensure server response includes id token.");
32
33
  }
34
+ var idToken = new AuthToken(response.id_token, this.cryptoObj);
35
+ var cacheRecord;
36
+ var authority;
33
37
  if (request.account) {
34
- this.loadIdToken(response.id_token, request.account.homeAccountId, request.account.environment, request.account.tenantId, options);
35
- this.loadAccessToken(request, response, request.account.homeAccountId, request.account.environment, request.account.tenantId, options);
38
+ var cacheRecordAccount = this.loadAccount(idToken, request.account.environment, undefined, undefined, request.account.homeAccountId);
39
+ cacheRecord = new CacheRecord(cacheRecordAccount, this.loadIdToken(idToken, cacheRecordAccount.homeAccountId, request.account.environment, request.account.tenantId), this.loadAccessToken(request, response, cacheRecordAccount.homeAccountId, request.account.environment, request.account.tenantId, options), this.loadRefreshToken(request, response, cacheRecordAccount.homeAccountId, request.account.environment));
36
40
  }
37
41
  else if (request.authority) {
38
42
  var authorityUrl = Authority.generateAuthority(request.authority, request.azureCloudOptions);
@@ -43,17 +47,17 @@ var TokenCache = /** @class */ (function () {
43
47
  authorityMetadata: this.config.auth.authorityMetadata,
44
48
  skipAuthorityMetadataCache: this.config.auth.skipAuthorityMetadataCache,
45
49
  };
46
- var authority = new Authority(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
50
+ authority = new Authority(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
47
51
  // "clientInfo" from options takes precedence over "clientInfo" in response
48
52
  if (options.clientInfo) {
49
53
  this.logger.trace("TokenCache - homeAccountId from options");
50
- this.loadIdToken(response.id_token, options.clientInfo, authority.hostnameAndPort, authority.tenant, options);
51
- this.loadAccessToken(request, response, options.clientInfo, authority.hostnameAndPort, authority.tenant, options);
54
+ var cacheRecordAccount = this.loadAccount(idToken, authority.hostnameAndPort, options.clientInfo, authority.authorityType);
55
+ cacheRecord = new CacheRecord(cacheRecordAccount, this.loadIdToken(idToken, cacheRecordAccount.homeAccountId, authority.hostnameAndPort, authority.tenant), this.loadAccessToken(request, response, cacheRecordAccount.homeAccountId, authority.hostnameAndPort, authority.tenant, options), this.loadRefreshToken(request, response, cacheRecordAccount.homeAccountId, authority.hostnameAndPort));
52
56
  }
53
57
  else if (response.client_info) {
54
58
  this.logger.trace("TokenCache - homeAccountId from response");
55
- this.loadIdToken(response.id_token, response.client_info, authority.hostnameAndPort, authority.tenant, options);
56
- this.loadAccessToken(request, response, response.client_info, authority.hostnameAndPort, authority.tenant, options);
59
+ var cacheRecordAccount = this.loadAccount(idToken, authority.hostnameAndPort, response.client_info, authority.authorityType);
60
+ cacheRecord = new CacheRecord(cacheRecordAccount, this.loadIdToken(idToken, cacheRecordAccount.homeAccountId, authority.hostnameAndPort, authority.tenant), this.loadAccessToken(request, response, cacheRecordAccount.homeAccountId, authority.hostnameAndPort, authority.tenant, options), this.loadRefreshToken(request, response, cacheRecordAccount.homeAccountId, authority.hostnameAndPort));
57
61
  }
58
62
  else {
59
63
  throw BrowserAuthError.createUnableToLoadTokenError("Please provide clientInfo in the response or options.");
@@ -62,6 +66,39 @@ var TokenCache = /** @class */ (function () {
62
66
  else {
63
67
  throw BrowserAuthError.createUnableToLoadTokenError("Please provide a request with an account or a request with authority.");
64
68
  }
69
+ return this.generateAuthenticationResult(request, idToken, cacheRecord, authority);
70
+ };
71
+ /**
72
+ * Helper function to load account to msal-browser cache
73
+ * @param idToken
74
+ * @param environment
75
+ * @param clientInfo
76
+ * @param authorityType
77
+ * @param requestHomeAccountId
78
+ * @returns `AccountEntity`
79
+ */
80
+ TokenCache.prototype.loadAccount = function (idToken, environment, clientInfo, authorityType, requestHomeAccountId) {
81
+ var homeAccountId;
82
+ if (requestHomeAccountId) {
83
+ homeAccountId = requestHomeAccountId;
84
+ }
85
+ else if (authorityType !== undefined && clientInfo) {
86
+ homeAccountId = AccountEntity.generateHomeAccountId(clientInfo, authorityType, this.logger, this.cryptoObj, idToken);
87
+ }
88
+ if (!homeAccountId) {
89
+ throw BrowserAuthError.createUnableToLoadTokenError("Unexpected missing homeAccountId");
90
+ }
91
+ var accountEntity = clientInfo ?
92
+ AccountEntity.createAccount(clientInfo, homeAccountId, idToken, undefined, undefined, undefined, environment) :
93
+ AccountEntity.createGenericAccount(homeAccountId, idToken, undefined, undefined, undefined, environment);
94
+ if (this.isBrowserEnvironment) {
95
+ this.logger.verbose("TokenCache - loading account");
96
+ this.storage.setAccount(accountEntity);
97
+ return accountEntity;
98
+ }
99
+ else {
100
+ throw BrowserAuthError.createUnableToLoadTokenError("loadExternalTokens is designed to work in browser environments only.");
101
+ }
65
102
  };
66
103
  /**
67
104
  * Helper function to load id tokens to msal-browser cache
@@ -69,18 +106,14 @@ var TokenCache = /** @class */ (function () {
69
106
  * @param homeAccountId
70
107
  * @param environment
71
108
  * @param tenantId
72
- * @param options
109
+ * @returns `IdTokenEntity`
73
110
  */
74
- TokenCache.prototype.loadIdToken = function (idToken, homeAccountId, environment, tenantId, options) {
75
- var idTokenEntity = IdTokenEntity.createIdTokenEntity(homeAccountId, environment, idToken, this.config.auth.clientId, tenantId);
76
- var idAuthToken = new AuthToken(idToken, this.cryptoObj);
77
- var accountEntity = options.clientInfo ?
78
- AccountEntity.createAccount(options.clientInfo, homeAccountId, idAuthToken, undefined, undefined, undefined, environment) :
79
- AccountEntity.createGenericAccount(homeAccountId, idAuthToken, undefined, undefined, undefined, environment);
111
+ TokenCache.prototype.loadIdToken = function (idToken, homeAccountId, environment, tenantId) {
112
+ var idTokenEntity = IdTokenEntity.createIdTokenEntity(homeAccountId, environment, idToken.rawToken, this.config.auth.clientId, tenantId);
80
113
  if (this.isBrowserEnvironment) {
81
114
  this.logger.verbose("TokenCache - loading id token");
82
- this.storage.setAccount(accountEntity);
83
115
  this.storage.setIdTokenCredential(idTokenEntity);
116
+ return idTokenEntity;
84
117
  }
85
118
  else {
86
119
  throw BrowserAuthError.createUnableToLoadTokenError("loadExternalTokens is designed to work in browser environments only.");
@@ -90,16 +123,15 @@ var TokenCache = /** @class */ (function () {
90
123
  * Helper function to load access tokens to msal-browser cache
91
124
  * @param request
92
125
  * @param response
93
- * @param options
94
126
  * @param homeAccountId
95
127
  * @param environment
96
128
  * @param tenantId
97
- * @returns
129
+ * @returns `AccessTokenEntity`
98
130
  */
99
131
  TokenCache.prototype.loadAccessToken = function (request, response, homeAccountId, environment, tenantId, options) {
100
132
  if (!response.access_token) {
101
133
  this.logger.verbose("TokenCache - No access token provided for caching");
102
- return;
134
+ return null;
103
135
  }
104
136
  if (!response.expires_in) {
105
137
  throw BrowserAuthError.createUnableToLoadTokenError("Please ensure server response includes expires_in value.");
@@ -114,11 +146,80 @@ var TokenCache = /** @class */ (function () {
114
146
  if (this.isBrowserEnvironment) {
115
147
  this.logger.verbose("TokenCache - loading access token");
116
148
  this.storage.setAccessTokenCredential(accessTokenEntity);
149
+ return accessTokenEntity;
117
150
  }
118
151
  else {
119
152
  throw BrowserAuthError.createUnableToLoadTokenError("loadExternalTokens is designed to work in browser environments only.");
120
153
  }
121
154
  };
155
+ /**
156
+ * Helper function to load refresh tokens to msal-browser cache
157
+ * @param request
158
+ * @param response
159
+ * @param homeAccountId
160
+ * @param environment
161
+ * @returns `RefreshTokenEntity`
162
+ */
163
+ TokenCache.prototype.loadRefreshToken = function (request, response, homeAccountId, environment) {
164
+ if (!response.refresh_token) {
165
+ this.logger.verbose("TokenCache - No refresh token provided for caching");
166
+ return null;
167
+ }
168
+ var refreshTokenEntity = RefreshTokenEntity.createRefreshTokenEntity(homeAccountId, environment, response.refresh_token, this.config.auth.clientId);
169
+ if (this.isBrowserEnvironment) {
170
+ this.logger.verbose("TokenCache - loading refresh token");
171
+ this.storage.setRefreshTokenCredential(refreshTokenEntity);
172
+ return refreshTokenEntity;
173
+ }
174
+ else {
175
+ throw BrowserAuthError.createUnableToLoadTokenError("loadExternalTokens is designed to work in browser environments only.");
176
+ }
177
+ };
178
+ /**
179
+ * Helper function to generate an `AuthenticationResult` for the result.
180
+ * @param request
181
+ * @param idTokenObj
182
+ * @param cacheRecord
183
+ * @param authority
184
+ * @returns `AuthenticationResult`
185
+ */
186
+ TokenCache.prototype.generateAuthenticationResult = function (request, idTokenObj, cacheRecord, authority) {
187
+ var _a, _b, _c;
188
+ var accessToken = Constants.EMPTY_STRING;
189
+ var responseScopes = [];
190
+ var expiresOn = null;
191
+ var extExpiresOn;
192
+ if (cacheRecord === null || cacheRecord === void 0 ? void 0 : cacheRecord.accessToken) {
193
+ accessToken = cacheRecord.accessToken.secret;
194
+ responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();
195
+ expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);
196
+ extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);
197
+ }
198
+ var uid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.oid) || (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.sub) || Constants.EMPTY_STRING;
199
+ var tid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.tid) || Constants.EMPTY_STRING;
200
+ return {
201
+ authority: authority ? authority.canonicalAuthority : Constants.EMPTY_STRING,
202
+ uniqueId: uid,
203
+ tenantId: tid,
204
+ scopes: responseScopes,
205
+ account: (cacheRecord === null || cacheRecord === void 0 ? void 0 : cacheRecord.account) ? cacheRecord.account.getAccountInfo() : null,
206
+ idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,
207
+ idTokenClaims: idTokenObj ? idTokenObj.claims : {},
208
+ accessToken: accessToken,
209
+ fromCache: true,
210
+ expiresOn: expiresOn,
211
+ correlationId: request.correlationId || Constants.EMPTY_STRING,
212
+ requestId: Constants.EMPTY_STRING,
213
+ extExpiresOn: extExpiresOn,
214
+ familyId: Constants.EMPTY_STRING,
215
+ tokenType: ((_a = cacheRecord === null || cacheRecord === void 0 ? void 0 : cacheRecord.accessToken) === null || _a === void 0 ? void 0 : _a.tokenType) || Constants.EMPTY_STRING,
216
+ state: Constants.EMPTY_STRING,
217
+ cloudGraphHostName: ((_b = cacheRecord === null || cacheRecord === void 0 ? void 0 : cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
218
+ msGraphHost: ((_c = cacheRecord === null || cacheRecord === void 0 ? void 0 : cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING,
219
+ code: undefined,
220
+ fromNativeBroker: false
221
+ };
222
+ };
122
223
  return TokenCache;
123
224
  }());
124
225