@azure/msal-browser 3.2.0 → 3.4.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 (224) hide show
  1. package/dist/app/IPublicClientApplication.mjs +1 -1
  2. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  3. package/dist/app/PublicClientApplication.mjs +3 -4
  4. package/dist/app/PublicClientApplication.mjs.map +1 -1
  5. package/dist/app/PublicClientNext.d.ts +274 -0
  6. package/dist/app/PublicClientNext.d.ts.map +1 -0
  7. package/dist/app/PublicClientNext.mjs +360 -0
  8. package/dist/app/PublicClientNext.mjs.map +1 -0
  9. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  10. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  11. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  12. package/dist/cache/BrowserCacheManager.d.ts +2 -13
  13. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  14. package/dist/cache/BrowserCacheManager.mjs +26 -83
  15. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  16. package/dist/cache/BrowserStorage.mjs +1 -1
  17. package/dist/cache/CryptoKeyStore.mjs +1 -1
  18. package/dist/cache/DatabaseStorage.mjs +1 -1
  19. package/dist/cache/MemoryStorage.mjs +1 -1
  20. package/dist/cache/TokenCache.d.ts.map +1 -1
  21. package/dist/cache/TokenCache.mjs +5 -5
  22. package/dist/cache/TokenCache.mjs.map +1 -1
  23. package/dist/config/Configuration.d.ts +4 -0
  24. package/dist/config/Configuration.d.ts.map +1 -1
  25. package/dist/config/Configuration.mjs +2 -1
  26. package/dist/config/Configuration.mjs.map +1 -1
  27. package/dist/controllers/ControllerFactory.d.ts +2 -7
  28. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  29. package/dist/controllers/ControllerFactory.mjs +24 -34
  30. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  31. package/dist/controllers/IController.d.ts +1 -2
  32. package/dist/controllers/IController.d.ts.map +1 -1
  33. package/dist/controllers/NestedAppAuthController.d.ts +96 -0
  34. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
  35. package/dist/controllers/NestedAppAuthController.mjs +345 -0
  36. package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
  37. package/dist/controllers/StandardController.d.ts +4 -4
  38. package/dist/controllers/StandardController.d.ts.map +1 -1
  39. package/dist/controllers/StandardController.mjs +43 -42
  40. package/dist/controllers/StandardController.mjs.map +1 -1
  41. package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
  42. package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
  43. package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
  44. package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
  45. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  46. package/dist/crypto/BrowserCrypto.mjs +3 -3
  47. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  48. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  49. package/dist/crypto/CryptoOps.mjs +8 -5
  50. package/dist/crypto/CryptoOps.mjs.map +1 -1
  51. package/dist/crypto/PkceGenerator.mjs +1 -1
  52. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  53. package/dist/encode/Base64Decode.mjs +1 -1
  54. package/dist/encode/Base64Encode.mjs +1 -1
  55. package/dist/error/BrowserAuthError.mjs +1 -1
  56. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  57. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  58. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  59. package/dist/error/NativeAuthError.mjs +1 -1
  60. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  61. package/dist/error/NestedAppAuthError.d.ts +15 -0
  62. package/dist/error/NestedAppAuthError.d.ts.map +1 -0
  63. package/dist/error/NestedAppAuthError.mjs +30 -0
  64. package/dist/error/NestedAppAuthError.mjs.map +1 -0
  65. package/dist/event/EventHandler.mjs +1 -1
  66. package/dist/event/EventMessage.mjs +1 -1
  67. package/dist/event/EventType.mjs +1 -1
  68. package/dist/index.d.ts +3 -5
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.mjs +4 -2
  71. package/dist/index.mjs.map +1 -1
  72. package/dist/interaction_client/BaseInteractionClient.mjs +4 -4
  73. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  74. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  75. package/dist/interaction_client/NativeInteractionClient.mjs +18 -7
  76. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  77. package/dist/interaction_client/PopupClient.d.ts +1 -2
  78. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  79. package/dist/interaction_client/PopupClient.mjs +13 -25
  80. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  81. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  82. package/dist/interaction_client/RedirectClient.mjs +17 -25
  83. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  84. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  85. package/dist/interaction_client/SilentAuthCodeClient.mjs +6 -8
  86. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  87. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  88. package/dist/interaction_client/SilentCacheClient.mjs +4 -3
  89. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  90. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  91. package/dist/interaction_client/SilentIframeClient.mjs +28 -19
  92. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  93. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  94. package/dist/interaction_client/SilentRefreshClient.mjs +2 -12
  95. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  96. package/dist/interaction_client/StandardInteractionClient.mjs +5 -5
  97. package/dist/interaction_handler/InteractionHandler.d.ts +6 -13
  98. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  99. package/dist/interaction_handler/InteractionHandler.mjs +29 -56
  100. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  101. package/dist/interaction_handler/RedirectHandler.d.ts +14 -7
  102. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  103. package/dist/interaction_handler/RedirectHandler.mjs +28 -9
  104. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  105. package/dist/interaction_handler/SilentHandler.d.ts +13 -47
  106. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  107. package/dist/interaction_handler/SilentHandler.mjs +120 -155
  108. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  109. package/dist/naa/AccountInfo.d.ts +13 -0
  110. package/dist/naa/AccountInfo.d.ts.map +1 -0
  111. package/dist/naa/AccountRequests.d.ts +10 -0
  112. package/dist/naa/AccountRequests.d.ts.map +1 -0
  113. package/dist/naa/AuthBridge.d.ts +6 -0
  114. package/dist/naa/AuthBridge.d.ts.map +1 -0
  115. package/dist/naa/BridgeCapabilities.d.ts +4 -0
  116. package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
  117. package/dist/naa/BridgeError.d.ts +10 -0
  118. package/dist/naa/BridgeError.d.ts.map +1 -0
  119. package/dist/naa/BridgeError.mjs +12 -0
  120. package/dist/naa/BridgeError.mjs.map +1 -0
  121. package/dist/naa/BridgeProxy.d.ts +72 -0
  122. package/dist/naa/BridgeProxy.d.ts.map +1 -0
  123. package/dist/naa/BridgeProxy.mjs +154 -0
  124. package/dist/naa/BridgeProxy.mjs.map +1 -0
  125. package/dist/naa/BridgeRequest.d.ts +7 -0
  126. package/dist/naa/BridgeRequest.d.ts.map +1 -0
  127. package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
  128. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
  129. package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
  130. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
  131. package/dist/naa/BridgeStatusCode.d.ts +11 -0
  132. package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
  133. package/dist/naa/BridgeStatusCode.mjs +20 -0
  134. package/dist/naa/BridgeStatusCode.mjs.map +1 -0
  135. package/dist/naa/IBridgeProxy.d.ts +11 -0
  136. package/dist/naa/IBridgeProxy.d.ts.map +1 -0
  137. package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
  138. package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
  139. package/dist/naa/TokenRequest.d.ts +22 -0
  140. package/dist/naa/TokenRequest.d.ts.map +1 -0
  141. package/dist/naa/TokenResponse.d.ts +17 -0
  142. package/dist/naa/TokenResponse.d.ts.map +1 -0
  143. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
  144. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
  145. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
  146. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
  147. package/dist/navigation/NavigationClient.mjs +1 -1
  148. package/dist/network/FetchClient.mjs +1 -1
  149. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  150. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  151. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
  152. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
  153. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
  154. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  155. package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
  156. package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
  157. package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
  158. package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
  159. package/dist/packageMetadata.d.ts +1 -1
  160. package/dist/packageMetadata.mjs +2 -2
  161. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  162. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  163. package/dist/utils/BrowserConstants.mjs +1 -1
  164. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  165. package/dist/utils/BrowserUtils.d.ts +54 -53
  166. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  167. package/dist/utils/BrowserUtils.mjs +114 -102
  168. package/dist/utils/BrowserUtils.mjs.map +1 -1
  169. package/lib/msal-browser.cjs +13221 -12385
  170. package/lib/msal-browser.cjs.map +1 -1
  171. package/lib/msal-browser.js +13221 -12385
  172. package/lib/msal-browser.js.map +1 -1
  173. package/lib/msal-browser.min.js +67 -68
  174. package/package.json +2 -2
  175. package/src/app/PublicClientApplication.ts +4 -3
  176. package/src/app/PublicClientNext.ts +444 -0
  177. package/src/cache/BrowserCacheManager.ts +33 -140
  178. package/src/cache/TokenCache.ts +5 -4
  179. package/src/config/Configuration.ts +5 -0
  180. package/src/controllers/ControllerFactory.ts +35 -43
  181. package/src/controllers/IController.ts +0 -6
  182. package/src/controllers/NestedAppAuthController.ts +525 -0
  183. package/src/controllers/StandardController.ts +50 -52
  184. package/src/controllers/UnknownOperatingContextController.ts +383 -0
  185. package/src/crypto/BrowserCrypto.ts +2 -2
  186. package/src/crypto/CryptoOps.ts +8 -5
  187. package/src/error/NestedAppAuthError.ts +32 -0
  188. package/src/index.ts +3 -10
  189. package/src/interaction_client/BaseInteractionClient.ts +1 -1
  190. package/src/interaction_client/NativeInteractionClient.ts +23 -6
  191. package/src/interaction_client/PopupClient.ts +41 -61
  192. package/src/interaction_client/RedirectClient.ts +42 -47
  193. package/src/interaction_client/SilentAuthCodeClient.ts +6 -16
  194. package/src/interaction_client/SilentCacheClient.ts +11 -3
  195. package/src/interaction_client/SilentIframeClient.ts +54 -34
  196. package/src/interaction_client/SilentRefreshClient.ts +5 -19
  197. package/src/interaction_client/StandardInteractionClient.ts +1 -1
  198. package/src/interaction_handler/InteractionHandler.ts +34 -104
  199. package/src/interaction_handler/RedirectHandler.ts +48 -22
  200. package/src/interaction_handler/SilentHandler.ts +177 -233
  201. package/src/naa/AccountInfo.ts +17 -0
  202. package/src/naa/AccountRequests.ts +16 -0
  203. package/src/naa/AuthBridge.ts +16 -0
  204. package/src/naa/BridgeCapabilities.ts +8 -0
  205. package/src/naa/BridgeError.ts +18 -0
  206. package/src/naa/BridgeProxy.ts +230 -0
  207. package/src/naa/BridgeRequest.ts +12 -0
  208. package/src/naa/BridgeRequestEnvelope.ts +46 -0
  209. package/src/naa/BridgeResponseEnvelope.ts +21 -0
  210. package/src/naa/BridgeStatusCode.ts +15 -0
  211. package/src/naa/IBridgeProxy.ts +25 -0
  212. package/src/naa/InitializeBridgeResponse.ts +12 -0
  213. package/src/naa/TokenRequest.ts +26 -0
  214. package/src/naa/TokenResponse.ts +61 -0
  215. package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
  216. package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
  217. package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
  218. package/src/packageMetadata.ts +1 -1
  219. package/src/utils/BrowserUtils.ts +133 -125
  220. package/dist/utils/BrowserStringUtils.d.ts +0 -22
  221. package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
  222. package/dist/utils/BrowserStringUtils.mjs +0 -144
  223. package/dist/utils/BrowserStringUtils.mjs.map +0 -1
  224. package/src/utils/BrowserStringUtils.ts +0 -143
@@ -21,7 +21,6 @@ import {
21
21
  PromptValue,
22
22
  InProgressPerformanceEvent,
23
23
  RequestThumbprint,
24
- ServerError,
25
24
  AccountEntity,
26
25
  ServerResponseType,
27
26
  UrlString,
@@ -29,6 +28,8 @@ import {
29
28
  createClientAuthError,
30
29
  ClientAuthErrorCodes,
31
30
  AccountFilter,
31
+ buildStaticAuthorityOptions,
32
+ InteractionRequiredAuthErrorCodes,
32
33
  } from "@azure/msal-common";
33
34
  import {
34
35
  BrowserCacheManager,
@@ -45,7 +46,7 @@ import {
45
46
  DEFAULT_REQUEST,
46
47
  BrowserConstants,
47
48
  } from "../utils/BrowserConstants";
48
- import { BrowserUtils } from "../utils/BrowserUtils";
49
+ import * as BrowserUtils from "../utils/BrowserUtils";
49
50
  import { RedirectRequest } from "../request/RedirectRequest";
50
51
  import { PopupRequest } from "../request/PopupRequest";
51
52
  import { SsoSilentRequest } from "../request/SsoSilentRequest";
@@ -207,7 +208,8 @@ export class StandardController implements IController {
207
208
  this.config.auth.clientId,
208
209
  this.config.cache,
209
210
  this.browserCrypto,
210
- this.logger
211
+ this.logger,
212
+ buildStaticAuthorityOptions(this.config.auth)
211
213
  )
212
214
  : DEFAULT_BROWSER_CACHE_MANAGER(
213
215
  this.config.auth.clientId,
@@ -1045,13 +1047,13 @@ export class StandardController implements IController {
1045
1047
  protected async acquireTokenFromCache(
1046
1048
  silentCacheClient: SilentCacheClient,
1047
1049
  commonRequest: CommonSilentFlowRequest,
1048
- silentRequest: SilentRequest
1050
+ cacheLookupPolicy: CacheLookupPolicy
1049
1051
  ): Promise<AuthenticationResult> {
1050
1052
  this.performanceClient.addQueueMeasurement(
1051
1053
  PerformanceEvents.AcquireTokenFromCache,
1052
1054
  commonRequest.correlationId
1053
1055
  );
1054
- switch (silentRequest.cacheLookupPolicy) {
1056
+ switch (cacheLookupPolicy) {
1055
1057
  case CacheLookupPolicy.Default:
1056
1058
  case CacheLookupPolicy.AccessToken:
1057
1059
  case CacheLookupPolicy.AccessTokenAndRefreshToken:
@@ -1072,18 +1074,18 @@ export class StandardController implements IController {
1072
1074
  /**
1073
1075
  * Attempt to acquire an access token via a refresh token
1074
1076
  * @param commonRequest CommonSilentFlowRequest
1075
- * @param silentRequest SilentRequest
1077
+ * @param cacheLookupPolicy CacheLookupPolicy
1076
1078
  * @returns A promise that, when resolved, returns the access token
1077
1079
  */
1078
1080
  public async acquireTokenByRefreshToken(
1079
1081
  commonRequest: CommonSilentFlowRequest,
1080
- silentRequest: SilentRequest
1082
+ cacheLookupPolicy: CacheLookupPolicy
1081
1083
  ): Promise<AuthenticationResult> {
1082
1084
  this.performanceClient.addQueueMeasurement(
1083
1085
  PerformanceEvents.AcquireTokenByRefreshToken,
1084
1086
  commonRequest.correlationId
1085
1087
  );
1086
- switch (silentRequest.cacheLookupPolicy) {
1088
+ switch (cacheLookupPolicy) {
1087
1089
  case CacheLookupPolicy.Default:
1088
1090
  case CacheLookupPolicy.AccessTokenAndRefreshToken:
1089
1091
  case CacheLookupPolicy.RefreshToken:
@@ -1559,10 +1561,10 @@ export class StandardController implements IController {
1559
1561
  ): string {
1560
1562
  const account =
1561
1563
  request.account ||
1562
- this.browserStorage.getAccountInfoByHints(
1563
- request.loginHint,
1564
- request.sid
1565
- ) ||
1564
+ this.browserStorage.getAccountInfoFilteredBy({
1565
+ loginHint: request.loginHint,
1566
+ sid: request.sid,
1567
+ }) ||
1566
1568
  this.getActiveAccount();
1567
1569
 
1568
1570
  return (account && account.nativeAccountId) || "";
@@ -2053,12 +2055,8 @@ export class StandardController implements IController {
2053
2055
  request.correlationId
2054
2056
  )(request, account);
2055
2057
 
2056
- const requestWithCLP = {
2057
- ...request,
2058
- // set the request's CacheLookupPolicy to Default if it was not optionally passed in
2059
- cacheLookupPolicy:
2060
- request.cacheLookupPolicy || CacheLookupPolicy.Default,
2061
- };
2058
+ const cacheLookupPolicy =
2059
+ request.cacheLookupPolicy || CacheLookupPolicy.Default;
2062
2060
 
2063
2061
  result = invokeAsync(
2064
2062
  this.acquireTokenFromCache.bind(this),
@@ -2066,10 +2064,10 @@ export class StandardController implements IController {
2066
2064
  this.logger,
2067
2065
  this.performanceClient,
2068
2066
  silentRequest.correlationId
2069
- )(silentCacheClient, silentRequest, requestWithCLP).catch(
2067
+ )(silentCacheClient, silentRequest, cacheLookupPolicy).catch(
2070
2068
  (cacheError: AuthError) => {
2071
2069
  if (
2072
- requestWithCLP.cacheLookupPolicy ===
2070
+ request.cacheLookupPolicy ===
2073
2071
  CacheLookupPolicy.AccessToken
2074
2072
  ) {
2075
2073
  throw cacheError;
@@ -2089,42 +2087,42 @@ export class StandardController implements IController {
2089
2087
  this.logger,
2090
2088
  this.performanceClient,
2091
2089
  silentRequest.correlationId
2092
- )(silentRequest, requestWithCLP).catch(
2090
+ )(silentRequest, cacheLookupPolicy).catch(
2093
2091
  (refreshTokenError: AuthError) => {
2094
- const isServerError =
2095
- refreshTokenError instanceof ServerError;
2096
- const isInteractionRequiredError =
2097
- refreshTokenError instanceof
2098
- InteractionRequiredAuthError;
2099
- const isInvalidGrantError =
2092
+ const isSilentlyResolvable =
2093
+ (!(
2094
+ refreshTokenError instanceof
2095
+ InteractionRequiredAuthError
2096
+ ) &&
2097
+ (refreshTokenError.errorCode ===
2098
+ BrowserConstants.INVALID_GRANT_ERROR ||
2099
+ refreshTokenError.errorCode ===
2100
+ ClientAuthErrorCodes.tokenRefreshRequired)) ||
2100
2101
  refreshTokenError.errorCode ===
2101
- BrowserConstants.INVALID_GRANT_ERROR;
2102
-
2103
- if (
2104
- (!isServerError ||
2105
- !isInvalidGrantError ||
2106
- isInteractionRequiredError ||
2107
- requestWithCLP.cacheLookupPolicy ===
2108
- CacheLookupPolicy.AccessTokenAndRefreshToken ||
2109
- requestWithCLP.cacheLookupPolicy ===
2110
- CacheLookupPolicy.RefreshToken) &&
2111
- requestWithCLP.cacheLookupPolicy !==
2112
- CacheLookupPolicy.Skip
2113
- ) {
2102
+ InteractionRequiredAuthErrorCodes.noTokensFound;
2103
+
2104
+ const tryIframeRenewal =
2105
+ cacheLookupPolicy ===
2106
+ CacheLookupPolicy.Default ||
2107
+ cacheLookupPolicy === CacheLookupPolicy.Skip ||
2108
+ cacheLookupPolicy ===
2109
+ CacheLookupPolicy.RefreshTokenAndNetwork;
2110
+
2111
+ if (isSilentlyResolvable && tryIframeRenewal) {
2112
+ this.logger.verbose(
2113
+ "Refresh token expired/invalid or CacheLookupPolicy is set to Skip, attempting acquire token by iframe.",
2114
+ request.correlationId
2115
+ );
2116
+ return invokeAsync(
2117
+ this.acquireTokenBySilentIframe.bind(this),
2118
+ PerformanceEvents.AcquireTokenBySilentIframe,
2119
+ this.logger,
2120
+ this.performanceClient,
2121
+ silentRequest.correlationId
2122
+ )(silentRequest);
2123
+ } else {
2114
2124
  throw refreshTokenError;
2115
2125
  }
2116
-
2117
- this.logger.verbose(
2118
- "Refresh token expired/invalid or CacheLookupPolicy is set to Skip, attempting acquire token by iframe.",
2119
- request.correlationId
2120
- );
2121
- return invokeAsync(
2122
- this.acquireTokenBySilentIframe.bind(this),
2123
- PerformanceEvents.AcquireTokenBySilentIframe,
2124
- this.logger,
2125
- this.performanceClient,
2126
- silentRequest.correlationId
2127
- )(silentRequest);
2128
2126
  }
2129
2127
  );
2130
2128
  }
@@ -0,0 +1,383 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ CommonAuthorizationUrlRequest,
8
+ CommonSilentFlowRequest,
9
+ PerformanceCallbackFunction,
10
+ AccountInfo,
11
+ Logger,
12
+ ICrypto,
13
+ IPerformanceClient,
14
+ DEFAULT_CRYPTO_IMPLEMENTATION,
15
+ AccountFilter,
16
+ } from "@azure/msal-common";
17
+ import { ITokenCache } from "../cache/ITokenCache";
18
+ import { BrowserConfiguration } from "../config/Configuration";
19
+ import {
20
+ BrowserCacheManager,
21
+ DEFAULT_BROWSER_CACHE_MANAGER,
22
+ } from "../cache/BrowserCacheManager";
23
+ import { INavigationClient } from "../navigation/INavigationClient";
24
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
25
+ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
26
+ import { EndSessionRequest } from "../request/EndSessionRequest";
27
+ import { PopupRequest } from "../request/PopupRequest";
28
+ import { RedirectRequest } from "../request/RedirectRequest";
29
+ import { SilentRequest } from "../request/SilentRequest";
30
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
31
+ import { AuthenticationResult } from "../response/AuthenticationResult";
32
+ import { ApiId, WrapperSKU, InteractionType } from "../utils/BrowserConstants";
33
+ import { IController } from "./IController";
34
+ import { UnknownOperatingContext } from "../operatingcontext/UnknownOperatingContext";
35
+ import { CryptoOps } from "../crypto/CryptoOps";
36
+ import {
37
+ blockAPICallsBeforeInitialize,
38
+ blockNonBrowserEnvironment,
39
+ } from "../utils/BrowserUtils";
40
+ import { EventHandler } from "../event/EventHandler";
41
+ import { EventCallbackFunction } from "../event/EventMessage";
42
+ import { ClearCacheRequest } from "../request/ClearCacheRequest";
43
+
44
+ /**
45
+ * UnknownOperatingContextController class
46
+ *
47
+ * - Until initialize method is called, this controller is the default
48
+ * - AFter initialize method is called, this controller will be swapped out for the appropriate controller
49
+ * if the operating context can be determined; otherwise this controller will continued be used
50
+ *
51
+ * - Why do we have this? We don't want to dynamically import (download) all of the code in StandardController if we don't need to.
52
+ *
53
+ * - Only includes implementation for getAccounts and handleRedirectPromise
54
+ * - All other methods are will throw initialization error (because either initialize method or the factory method were not used)
55
+ * - This controller is necessary for React Native wrapper, server side rendering and any other scenario where we don't have a DOM
56
+ *
57
+ */
58
+ export class UnknownOperatingContextController implements IController {
59
+ // OperatingContext
60
+ protected readonly operatingContext: UnknownOperatingContext;
61
+
62
+ // Logger
63
+ protected logger: Logger;
64
+
65
+ // Storage interface implementation
66
+ protected readonly browserStorage: BrowserCacheManager;
67
+
68
+ // Input configuration by developer/user
69
+ protected readonly config: BrowserConfiguration;
70
+
71
+ // Performance telemetry client
72
+ protected readonly performanceClient: IPerformanceClient;
73
+
74
+ // Crypto interface implementation
75
+ protected readonly browserCrypto: ICrypto;
76
+
77
+ // Flag to indicate if in browser environment
78
+ protected isBrowserEnvironment: boolean;
79
+
80
+ // Flag representing whether or not the initialize API has been called and completed
81
+ protected initialized: boolean = false;
82
+
83
+ protected readonly eventHandler: EventHandler;
84
+
85
+ constructor(operatingContext: UnknownOperatingContext) {
86
+ this.operatingContext = operatingContext;
87
+
88
+ this.isBrowserEnvironment =
89
+ this.operatingContext.isBrowserEnvironment();
90
+
91
+ this.config = operatingContext.getConfig();
92
+
93
+ this.logger = operatingContext.getLogger();
94
+
95
+ // Initialize performance client
96
+ this.performanceClient = this.config.telemetry.client;
97
+
98
+ // Initialize the crypto class.
99
+ this.browserCrypto = this.isBrowserEnvironment
100
+ ? new CryptoOps(this.logger, this.performanceClient)
101
+ : DEFAULT_CRYPTO_IMPLEMENTATION;
102
+
103
+ // Initialize the browser storage class.
104
+ this.browserStorage = this.isBrowserEnvironment
105
+ ? new BrowserCacheManager(
106
+ this.config.auth.clientId,
107
+ this.config.cache,
108
+ this.browserCrypto,
109
+ this.logger
110
+ )
111
+ : DEFAULT_BROWSER_CACHE_MANAGER(
112
+ this.config.auth.clientId,
113
+ this.logger
114
+ );
115
+
116
+ this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
117
+ }
118
+ getBrowserStorage(): BrowserCacheManager {
119
+ return this.browserStorage;
120
+ }
121
+
122
+ getEventHandler(): EventHandler {
123
+ return this.eventHandler;
124
+ }
125
+
126
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
+ getAccount(accountFilter: AccountFilter): AccountInfo | null {
128
+ return null;
129
+ }
130
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
131
+ getAccountByHomeId(homeAccountId: string): AccountInfo | null {
132
+ return null;
133
+ }
134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
135
+ getAccountByLocalId(localAccountId: string): AccountInfo | null {
136
+ return null;
137
+ }
138
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
+ getAccountByUsername(username: string): AccountInfo | null {
140
+ return null;
141
+ }
142
+ getAllAccounts(): AccountInfo[] {
143
+ return [];
144
+ }
145
+ initialize(): Promise<void> {
146
+ this.initialized = true;
147
+ return Promise.resolve();
148
+ }
149
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
150
+ acquireTokenPopup(request: PopupRequest): Promise<AuthenticationResult> {
151
+ blockAPICallsBeforeInitialize(this.initialized);
152
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
153
+ return {} as Promise<AuthenticationResult>;
154
+ }
155
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
156
+ acquireTokenRedirect(request: RedirectRequest): Promise<void> {
157
+ blockAPICallsBeforeInitialize(this.initialized);
158
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
159
+ return Promise.resolve();
160
+ }
161
+ acquireTokenSilent(
162
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
163
+ silentRequest: SilentRequest
164
+ ): Promise<AuthenticationResult> {
165
+ blockAPICallsBeforeInitialize(this.initialized);
166
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
167
+ return {} as Promise<AuthenticationResult>;
168
+ }
169
+ acquireTokenByCode(
170
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
171
+ request: AuthorizationCodeRequest
172
+ ): Promise<AuthenticationResult> {
173
+ blockAPICallsBeforeInitialize(this.initialized);
174
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
175
+ return {} as Promise<AuthenticationResult>;
176
+ }
177
+ acquireTokenNative(
178
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
179
+ request:
180
+ | PopupRequest
181
+ | SilentRequest
182
+ | Partial<
183
+ Omit<
184
+ CommonAuthorizationUrlRequest,
185
+ | "responseMode"
186
+ | "codeChallenge"
187
+ | "codeChallengeMethod"
188
+ | "requestedClaimsHash"
189
+ | "nativeBroker"
190
+ >
191
+ >,
192
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
193
+ apiId: ApiId,
194
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
195
+ accountId?: string | undefined
196
+ ): Promise<AuthenticationResult> {
197
+ blockAPICallsBeforeInitialize(this.initialized);
198
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
199
+ return {} as Promise<AuthenticationResult>;
200
+ }
201
+ acquireTokenByRefreshToken(
202
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
203
+ commonRequest: CommonSilentFlowRequest,
204
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
205
+ silentRequest: SilentRequest
206
+ ): Promise<AuthenticationResult> {
207
+ blockAPICallsBeforeInitialize(this.initialized);
208
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
209
+ return {} as Promise<AuthenticationResult>;
210
+ }
211
+ addEventCallback(callback: EventCallbackFunction): string | null {
212
+ return this.eventHandler.addEventCallback(callback);
213
+ }
214
+ removeEventCallback(callbackId: string): void {
215
+ this.eventHandler.removeEventCallback(callbackId);
216
+ }
217
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
218
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string {
219
+ blockAPICallsBeforeInitialize(this.initialized);
220
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
221
+ return "";
222
+ }
223
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
224
+ removePerformanceCallback(callbackId: string): boolean {
225
+ blockAPICallsBeforeInitialize(this.initialized);
226
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
227
+ return true;
228
+ }
229
+ enableAccountStorageEvents(): void {
230
+ blockAPICallsBeforeInitialize(this.initialized);
231
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
232
+ }
233
+ disableAccountStorageEvents(): void {
234
+ blockAPICallsBeforeInitialize(this.initialized);
235
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
236
+ }
237
+
238
+ handleRedirectPromise(
239
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
240
+ hash?: string | undefined
241
+ ): Promise<AuthenticationResult | null> {
242
+ blockAPICallsBeforeInitialize(this.initialized);
243
+ return Promise.resolve(null);
244
+ }
245
+ loginPopup(
246
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
247
+ request?: PopupRequest | undefined
248
+ ): Promise<AuthenticationResult> {
249
+ blockAPICallsBeforeInitialize(this.initialized);
250
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
251
+ return {} as Promise<AuthenticationResult>;
252
+ }
253
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
254
+ loginRedirect(request?: RedirectRequest | undefined): Promise<void> {
255
+ blockAPICallsBeforeInitialize(this.initialized);
256
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
257
+ return {} as Promise<void>;
258
+ }
259
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
260
+ logout(logoutRequest?: EndSessionRequest | undefined): Promise<void> {
261
+ blockAPICallsBeforeInitialize(this.initialized);
262
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
263
+ return {} as Promise<void>;
264
+ }
265
+ logoutRedirect(
266
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
267
+ logoutRequest?: EndSessionRequest | undefined
268
+ ): Promise<void> {
269
+ blockAPICallsBeforeInitialize(this.initialized);
270
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
271
+ return {} as Promise<void>;
272
+ }
273
+ logoutPopup(
274
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
275
+ logoutRequest?: EndSessionPopupRequest | undefined
276
+ ): Promise<void> {
277
+ blockAPICallsBeforeInitialize(this.initialized);
278
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
279
+ return {} as Promise<void>;
280
+ }
281
+ ssoSilent(
282
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
283
+ request: Partial<
284
+ Omit<
285
+ CommonAuthorizationUrlRequest,
286
+ | "responseMode"
287
+ | "codeChallenge"
288
+ | "codeChallengeMethod"
289
+ | "requestedClaimsHash"
290
+ | "nativeBroker"
291
+ >
292
+ >
293
+ ): Promise<AuthenticationResult> {
294
+ blockAPICallsBeforeInitialize(this.initialized);
295
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
296
+ return {} as Promise<AuthenticationResult>;
297
+ }
298
+ getTokenCache(): ITokenCache {
299
+ blockAPICallsBeforeInitialize(this.initialized);
300
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
301
+ return {} as ITokenCache;
302
+ }
303
+ getLogger(): Logger {
304
+ return this.logger;
305
+ }
306
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
307
+ setLogger(logger: Logger): void {
308
+ blockAPICallsBeforeInitialize(this.initialized);
309
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
310
+ }
311
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
312
+ setActiveAccount(account: AccountInfo | null): void {
313
+ blockAPICallsBeforeInitialize(this.initialized);
314
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
315
+ }
316
+ getActiveAccount(): AccountInfo | null {
317
+ blockAPICallsBeforeInitialize(this.initialized);
318
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
319
+ return null;
320
+ }
321
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
322
+ initializeWrapperLibrary(sku: WrapperSKU, version: string): void {
323
+ this.browserStorage.setWrapperMetadata(sku, version);
324
+ }
325
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
326
+ setNavigationClient(navigationClient: INavigationClient): void {
327
+ blockAPICallsBeforeInitialize(this.initialized);
328
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
329
+ }
330
+ getConfiguration(): BrowserConfiguration {
331
+ return this.config;
332
+ }
333
+ isBrowserEnv(): boolean {
334
+ blockAPICallsBeforeInitialize(this.initialized);
335
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
336
+ return true;
337
+ }
338
+ getBrowserCrypto(): ICrypto {
339
+ blockAPICallsBeforeInitialize(this.initialized);
340
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
341
+ return {} as ICrypto;
342
+ }
343
+ getPerformanceClient(): IPerformanceClient {
344
+ blockAPICallsBeforeInitialize(this.initialized);
345
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
346
+ return {} as IPerformanceClient;
347
+ }
348
+ getRedirectResponse(): Map<string, Promise<AuthenticationResult | null>> {
349
+ blockAPICallsBeforeInitialize(this.initialized);
350
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
351
+ return {} as Map<string, Promise<AuthenticationResult | null>>;
352
+ }
353
+ preflightBrowserEnvironmentCheck(
354
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
355
+ interactionType: InteractionType,
356
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
357
+ isAppEmbedded?: boolean | undefined
358
+ ): void {
359
+ blockAPICallsBeforeInitialize(this.initialized);
360
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
361
+ }
362
+
363
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
364
+ async clearCache(logoutRequest?: ClearCacheRequest): Promise<void> {
365
+ blockAPICallsBeforeInitialize(this.initialized);
366
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
367
+ }
368
+
369
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
370
+ async hydrateCache(
371
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
372
+ result: AuthenticationResult,
373
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
374
+ request:
375
+ | SilentRequest
376
+ | SsoSilentRequest
377
+ | RedirectRequest
378
+ | PopupRequest
379
+ ): Promise<void> {
380
+ blockAPICallsBeforeInitialize(this.initialized);
381
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
382
+ }
383
+ }
@@ -3,7 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { BrowserStringUtils } from "../utils/BrowserStringUtils";
7
6
  import {
8
7
  createBrowserAuthError,
9
8
  BrowserAuthErrorCodes,
@@ -64,7 +63,8 @@ export async function sha256Digest(
64
63
  PerformanceEvents.Sha256Digest,
65
64
  correlationId
66
65
  );
67
- const data = BrowserStringUtils.stringToUtf8Arr(dataString);
66
+ const encoder = new TextEncoder();
67
+ const data = encoder.encode(dataString);
68
68
  return window.crypto.subtle.digest(
69
69
  S256_HASH_ALG,
70
70
  data
@@ -15,7 +15,6 @@ import {
15
15
  import { base64Encode, urlEncode, urlEncodeArr } from "../encode/Base64Encode";
16
16
  import { base64Decode } from "../encode/Base64Decode";
17
17
  import * as BrowserCrypto from "./BrowserCrypto";
18
- import { BrowserStringUtils } from "../utils/BrowserStringUtils";
19
18
  import {
20
19
  createBrowserAuthError,
21
20
  BrowserAuthErrorCodes,
@@ -109,7 +108,7 @@ export class CryptoOps implements ICrypto {
109
108
  };
110
109
 
111
110
  const publicJwkString: string =
112
- BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);
111
+ getSortedObjectString(pubKeyThumprintObj);
113
112
  const publicJwkHash = await this.hashString(publicJwkString);
114
113
 
115
114
  // Generate Thumbprint for Private Key
@@ -180,8 +179,7 @@ export class CryptoOps implements ICrypto {
180
179
  const publicKeyJwk = await BrowserCrypto.exportJwk(
181
180
  cachedKeyPair.publicKey
182
181
  );
183
- const publicKeyJwkString =
184
- BrowserStringUtils.getSortedObjectString(publicKeyJwk);
182
+ const publicKeyJwkString = getSortedObjectString(publicKeyJwk);
185
183
 
186
184
  // Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
187
185
  const encodedKeyIdThumbprint = urlEncode(JSON.stringify({ kid: kid }));
@@ -203,7 +201,8 @@ export class CryptoOps implements ICrypto {
203
201
  const tokenString = `${encodedShrHeader}.${encodedPayload}`;
204
202
 
205
203
  // Sign token
206
- const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
204
+ const encoder = new TextEncoder();
205
+ const tokenBuffer = encoder.encode(tokenString);
207
206
  const signatureBuffer = await BrowserCrypto.sign(
208
207
  cachedKeyPair.privateKey,
209
208
  tokenBuffer
@@ -233,3 +232,7 @@ export class CryptoOps implements ICrypto {
233
232
  return urlEncodeArr(hashBytes);
234
233
  }
235
234
  }
235
+
236
+ function getSortedObjectString(obj: object): string {
237
+ return JSON.stringify(obj, Object.keys(obj).sort());
238
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AuthError } from "@azure/msal-common";
7
+
8
+ /**
9
+ * NestedAppAuthErrorMessage class containing string constants used by error codes and messages.
10
+ */
11
+ export const NestedAppAuthErrorMessage = {
12
+ unsupportedMethod: {
13
+ code: "unsupported_method",
14
+ desc: "The PKCE code challenge and verifier could not be generated.",
15
+ },
16
+ };
17
+
18
+ export class NestedAppAuthError extends AuthError {
19
+ constructor(errorCode: string, errorMessage?: string) {
20
+ super(errorCode, errorMessage);
21
+
22
+ Object.setPrototypeOf(this, NestedAppAuthError.prototype);
23
+ this.name = "NestedAppAuthError";
24
+ }
25
+
26
+ public static createUnsupportedError(): NestedAppAuthError {
27
+ return new NestedAppAuthError(
28
+ NestedAppAuthErrorMessage.unsupportedMethod.code,
29
+ NestedAppAuthErrorMessage.unsupportedMethod.desc
30
+ );
31
+ }
32
+ }