@azure/msal-browser 3.3.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 (121) 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.map +1 -1
  6. package/dist/app/PublicClientNext.mjs +4 -6
  7. package/dist/app/PublicClientNext.mjs.map +1 -1
  8. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  9. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  10. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  11. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  12. package/dist/cache/BrowserCacheManager.mjs +20 -20
  13. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  14. package/dist/cache/BrowserStorage.mjs +1 -1
  15. package/dist/cache/CryptoKeyStore.mjs +1 -1
  16. package/dist/cache/DatabaseStorage.mjs +1 -1
  17. package/dist/cache/MemoryStorage.mjs +1 -1
  18. package/dist/cache/TokenCache.d.ts.map +1 -1
  19. package/dist/cache/TokenCache.mjs +5 -5
  20. package/dist/cache/TokenCache.mjs.map +1 -1
  21. package/dist/config/Configuration.mjs +1 -1
  22. package/dist/controllers/ControllerFactory.d.ts +2 -8
  23. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  24. package/dist/controllers/ControllerFactory.mjs +21 -38
  25. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  26. package/dist/controllers/IController.d.ts +1 -2
  27. package/dist/controllers/IController.d.ts.map +1 -1
  28. package/dist/controllers/NestedAppAuthController.mjs +1 -1
  29. package/dist/controllers/StandardController.d.ts +4 -4
  30. package/dist/controllers/StandardController.d.ts.map +1 -1
  31. package/dist/controllers/StandardController.mjs +29 -31
  32. package/dist/controllers/StandardController.mjs.map +1 -1
  33. package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
  34. package/dist/crypto/BrowserCrypto.mjs +1 -1
  35. package/dist/crypto/CryptoOps.mjs +1 -1
  36. package/dist/crypto/PkceGenerator.mjs +1 -1
  37. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  38. package/dist/encode/Base64Decode.mjs +1 -1
  39. package/dist/encode/Base64Encode.mjs +1 -1
  40. package/dist/error/BrowserAuthError.mjs +1 -1
  41. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  42. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  43. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  44. package/dist/error/NativeAuthError.mjs +1 -1
  45. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  46. package/dist/error/NestedAppAuthError.mjs +1 -1
  47. package/dist/event/EventHandler.mjs +1 -1
  48. package/dist/event/EventMessage.mjs +1 -1
  49. package/dist/event/EventType.mjs +1 -1
  50. package/dist/index.mjs +1 -1
  51. package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
  52. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  53. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  54. package/dist/interaction_client/NativeInteractionClient.mjs +4 -4
  55. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  56. package/dist/interaction_client/PopupClient.d.ts +1 -2
  57. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  58. package/dist/interaction_client/PopupClient.mjs +9 -22
  59. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  60. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  61. package/dist/interaction_client/RedirectClient.mjs +11 -19
  62. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  63. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  64. package/dist/interaction_client/SilentAuthCodeClient.mjs +3 -5
  65. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  66. package/dist/interaction_client/SilentCacheClient.mjs +1 -1
  67. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  68. package/dist/interaction_client/SilentIframeClient.mjs +4 -9
  69. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  70. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  71. package/dist/interaction_client/SilentRefreshClient.mjs +2 -12
  72. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  73. package/dist/interaction_client/StandardInteractionClient.mjs +1 -1
  74. package/dist/interaction_handler/InteractionHandler.d.ts +6 -13
  75. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  76. package/dist/interaction_handler/InteractionHandler.mjs +29 -56
  77. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  78. package/dist/interaction_handler/RedirectHandler.d.ts +14 -7
  79. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  80. package/dist/interaction_handler/RedirectHandler.mjs +28 -9
  81. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  82. package/dist/interaction_handler/SilentHandler.mjs +1 -1
  83. package/dist/naa/BridgeError.mjs +1 -1
  84. package/dist/naa/BridgeProxy.mjs +1 -1
  85. package/dist/naa/BridgeStatusCode.mjs +1 -1
  86. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +1 -1
  87. package/dist/navigation/NavigationClient.mjs +1 -1
  88. package/dist/network/FetchClient.mjs +1 -1
  89. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  90. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  91. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  92. package/dist/operatingcontext/UnknownOperatingContext.mjs +1 -1
  93. package/dist/packageMetadata.d.ts +1 -1
  94. package/dist/packageMetadata.mjs +2 -2
  95. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  96. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  97. package/dist/utils/BrowserConstants.mjs +1 -1
  98. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  99. package/dist/utils/BrowserUtils.mjs +1 -1
  100. package/lib/msal-browser.cjs +18564 -61
  101. package/lib/msal-browser.cjs.map +1 -1
  102. package/lib/msal-browser.js +2828 -3394
  103. package/lib/msal-browser.js.map +1 -1
  104. package/lib/msal-browser.min.js +67 -66
  105. package/package.json +2 -2
  106. package/src/app/PublicClientApplication.ts +4 -3
  107. package/src/app/PublicClientNext.ts +7 -5
  108. package/src/cache/BrowserCacheManager.ts +22 -40
  109. package/src/cache/TokenCache.ts +5 -4
  110. package/src/controllers/ControllerFactory.ts +30 -49
  111. package/src/controllers/IController.ts +0 -6
  112. package/src/controllers/StandardController.ts +42 -46
  113. package/src/interaction_client/NativeInteractionClient.ts +4 -3
  114. package/src/interaction_client/PopupClient.ts +39 -60
  115. package/src/interaction_client/RedirectClient.ts +41 -46
  116. package/src/interaction_client/SilentAuthCodeClient.ts +1 -12
  117. package/src/interaction_client/SilentIframeClient.ts +2 -18
  118. package/src/interaction_client/SilentRefreshClient.ts +5 -19
  119. package/src/interaction_handler/InteractionHandler.ts +34 -104
  120. package/src/interaction_handler/RedirectHandler.ts +48 -22
  121. package/src/packageMetadata.ts +1 -1
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
12
12
  },
13
- "version": "3.3.0",
13
+ "version": "3.4.0",
14
14
  "description": "Microsoft Authentication Library for js",
15
15
  "keywords": [
16
16
  "implicit",
@@ -100,6 +100,6 @@
100
100
  "typescript": "^4.9.5"
101
101
  },
102
102
  "dependencies": {
103
- "@azure/msal-common": "14.2.0"
103
+ "@azure/msal-common": "14.3.0"
104
104
  }
105
105
  }
@@ -20,7 +20,7 @@ import {
20
20
  } from "@azure/msal-common";
21
21
  import { EndSessionRequest } from "../request/EndSessionRequest";
22
22
  import { SsoSilentRequest } from "../request/SsoSilentRequest";
23
- import { ControllerFactory } from "../controllers/ControllerFactory";
23
+ import * as ControllerFactory from "../controllers/ControllerFactory";
24
24
  import { StandardController } from "../controllers/StandardController";
25
25
  import { BrowserConfiguration, Configuration } from "../config/Configuration";
26
26
  import { StandardOperatingContext } from "../operatingcontext/StandardOperatingContext";
@@ -38,8 +38,9 @@ export class PublicClientApplication implements IPublicClientApplication {
38
38
  public static async createPublicClientApplication(
39
39
  configuration: Configuration
40
40
  ): Promise<IPublicClientApplication> {
41
- const factory = new ControllerFactory(configuration);
42
- const controller = await factory.createV3Controller();
41
+ const controller = await ControllerFactory.createV3Controller(
42
+ configuration
43
+ );
43
44
  const pca = new PublicClientApplication(configuration, controller);
44
45
 
45
46
  return pca;
@@ -20,7 +20,7 @@ import {
20
20
  } from "@azure/msal-common";
21
21
  import { EndSessionRequest } from "../request/EndSessionRequest";
22
22
  import { SsoSilentRequest } from "../request/SsoSilentRequest";
23
- import { ControllerFactory } from "../controllers/ControllerFactory";
23
+ import * as ControllerFactory from "../controllers/ControllerFactory";
24
24
  import { BrowserConfiguration, Configuration } from "../config/Configuration";
25
25
  import { EventCallbackFunction } from "../event/EventMessage";
26
26
  import { ClearCacheRequest } from "../request/ClearCacheRequest";
@@ -47,8 +47,9 @@ export class PublicClientNext implements IPublicClientApplication {
47
47
  public static async createPublicClientApplication(
48
48
  configuration: Configuration
49
49
  ): Promise<IPublicClientApplication> {
50
- const factory = new ControllerFactory(configuration);
51
- const controller = await factory.createController();
50
+ const controller = await ControllerFactory.createController(
51
+ configuration
52
+ );
52
53
  let pca;
53
54
  if (controller !== null) {
54
55
  pca = new PublicClientNext(configuration, controller);
@@ -100,8 +101,9 @@ export class PublicClientNext implements IPublicClientApplication {
100
101
  */
101
102
  async initialize(): Promise<void> {
102
103
  if (this.controller instanceof UnknownOperatingContextController) {
103
- const factory = new ControllerFactory(this.configuration);
104
- const result = await factory.createController();
104
+ const result = await ControllerFactory.createController(
105
+ this.configuration
106
+ );
105
107
  if (result !== null) {
106
108
  this.controller = result;
107
109
  }
@@ -36,6 +36,7 @@ import {
36
36
  PerformanceEvents,
37
37
  IPerformanceClient,
38
38
  StaticAuthorityOptions,
39
+ CacheHelpers,
39
40
  } from "@azure/msal-common";
40
41
  import { CacheOptions } from "../config/Configuration";
41
42
  import {
@@ -234,17 +235,15 @@ export class BrowserCacheManager extends CacheManager {
234
235
  if (credObj && credObj.hasOwnProperty("credentialType")) {
235
236
  switch (credObj["credentialType"]) {
236
237
  case CredentialType.ID_TOKEN:
237
- if (IdTokenEntity.isIdTokenEntity(credObj)) {
238
+ if (CacheHelpers.isIdTokenEntity(credObj)) {
238
239
  this.logger.trace(
239
240
  "BrowserCacheManager:createKeyMaps - idToken found, saving key to token key map"
240
241
  );
241
242
  this.logger.tracePii(
242
243
  `BrowserCacheManager:createKeyMaps - idToken with key: ${key} found, saving key to token key map`
243
244
  );
244
- const idTokenEntity = CacheManager.toObject(
245
- new IdTokenEntity(),
246
- credObj
247
- );
245
+ const idTokenEntity =
246
+ credObj as IdTokenEntity;
248
247
  const newKey =
249
248
  this.updateCredentialCacheKey(
250
249
  key,
@@ -266,11 +265,7 @@ export class BrowserCacheManager extends CacheManager {
266
265
  break;
267
266
  case CredentialType.ACCESS_TOKEN:
268
267
  case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
269
- if (
270
- AccessTokenEntity.isAccessTokenEntity(
271
- credObj
272
- )
273
- ) {
268
+ if (CacheHelpers.isAccessTokenEntity(credObj)) {
274
269
  this.logger.trace(
275
270
  "BrowserCacheManager:createKeyMaps - accessToken found, saving key to token key map"
276
271
  );
@@ -278,10 +273,7 @@ export class BrowserCacheManager extends CacheManager {
278
273
  `BrowserCacheManager:createKeyMaps - accessToken with key: ${key} found, saving key to token key map`
279
274
  );
280
275
  const accessTokenEntity =
281
- CacheManager.toObject(
282
- new AccessTokenEntity(),
283
- credObj
284
- );
276
+ credObj as AccessTokenEntity;
285
277
  const newKey =
286
278
  this.updateCredentialCacheKey(
287
279
  key,
@@ -303,9 +295,7 @@ export class BrowserCacheManager extends CacheManager {
303
295
  break;
304
296
  case CredentialType.REFRESH_TOKEN:
305
297
  if (
306
- RefreshTokenEntity.isRefreshTokenEntity(
307
- credObj
308
- )
298
+ CacheHelpers.isRefreshTokenEntity(credObj)
309
299
  ) {
310
300
  this.logger.trace(
311
301
  "BrowserCacheManager:createKeyMaps - refreshToken found, saving key to token key map"
@@ -314,10 +304,7 @@ export class BrowserCacheManager extends CacheManager {
314
304
  `BrowserCacheManager:createKeyMaps - refreshToken with key: ${key} found, saving key to token key map`
315
305
  );
316
306
  const refreshTokenEntity =
317
- CacheManager.toObject(
318
- new RefreshTokenEntity(),
319
- credObj
320
- );
307
+ credObj as RefreshTokenEntity;
321
308
  const newKey =
322
309
  this.updateCredentialCacheKey(
323
310
  key,
@@ -718,7 +705,7 @@ export class BrowserCacheManager extends CacheManager {
718
705
  }
719
706
 
720
707
  const parsedIdToken = this.validateAndParseJson(value);
721
- if (!parsedIdToken || !IdTokenEntity.isIdTokenEntity(parsedIdToken)) {
708
+ if (!parsedIdToken || !CacheHelpers.isIdTokenEntity(parsedIdToken)) {
722
709
  this.logger.trace(
723
710
  "BrowserCacheManager.getIdTokenCredential: called, no cache hit"
724
711
  );
@@ -729,7 +716,7 @@ export class BrowserCacheManager extends CacheManager {
729
716
  this.logger.trace(
730
717
  "BrowserCacheManager.getIdTokenCredential: cache hit"
731
718
  );
732
- return CacheManager.toObject(new IdTokenEntity(), parsedIdToken);
719
+ return parsedIdToken as IdTokenEntity;
733
720
  }
734
721
 
735
722
  /**
@@ -738,7 +725,7 @@ export class BrowserCacheManager extends CacheManager {
738
725
  */
739
726
  setIdTokenCredential(idToken: IdTokenEntity): void {
740
727
  this.logger.trace("BrowserCacheManager.setIdTokenCredential called");
741
- const idTokenKey = idToken.generateCredentialKey();
728
+ const idTokenKey = CacheHelpers.generateCredentialKey(idToken);
742
729
 
743
730
  this.setItem(idTokenKey, JSON.stringify(idToken));
744
731
 
@@ -761,7 +748,7 @@ export class BrowserCacheManager extends CacheManager {
761
748
  const parsedAccessToken = this.validateAndParseJson(value);
762
749
  if (
763
750
  !parsedAccessToken ||
764
- !AccessTokenEntity.isAccessTokenEntity(parsedAccessToken)
751
+ !CacheHelpers.isAccessTokenEntity(parsedAccessToken)
765
752
  ) {
766
753
  this.logger.trace(
767
754
  "BrowserCacheManager.getAccessTokenCredential: called, no cache hit"
@@ -773,10 +760,7 @@ export class BrowserCacheManager extends CacheManager {
773
760
  this.logger.trace(
774
761
  "BrowserCacheManager.getAccessTokenCredential: cache hit"
775
762
  );
776
- return CacheManager.toObject(
777
- new AccessTokenEntity(),
778
- parsedAccessToken
779
- );
763
+ return parsedAccessToken as AccessTokenEntity;
780
764
  }
781
765
 
782
766
  /**
@@ -787,7 +771,7 @@ export class BrowserCacheManager extends CacheManager {
787
771
  this.logger.trace(
788
772
  "BrowserCacheManager.setAccessTokenCredential called"
789
773
  );
790
- const accessTokenKey = accessToken.generateCredentialKey();
774
+ const accessTokenKey = CacheHelpers.generateCredentialKey(accessToken);
791
775
  this.setItem(accessTokenKey, JSON.stringify(accessToken));
792
776
 
793
777
  this.addTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
@@ -811,7 +795,7 @@ export class BrowserCacheManager extends CacheManager {
811
795
  const parsedRefreshToken = this.validateAndParseJson(value);
812
796
  if (
813
797
  !parsedRefreshToken ||
814
- !RefreshTokenEntity.isRefreshTokenEntity(parsedRefreshToken)
798
+ !CacheHelpers.isRefreshTokenEntity(parsedRefreshToken)
815
799
  ) {
816
800
  this.logger.trace(
817
801
  "BrowserCacheManager.getRefreshTokenCredential: called, no cache hit"
@@ -823,10 +807,7 @@ export class BrowserCacheManager extends CacheManager {
823
807
  this.logger.trace(
824
808
  "BrowserCacheManager.getRefreshTokenCredential: cache hit"
825
809
  );
826
- return CacheManager.toObject(
827
- new RefreshTokenEntity(),
828
- parsedRefreshToken
829
- );
810
+ return parsedRefreshToken as RefreshTokenEntity;
830
811
  }
831
812
 
832
813
  /**
@@ -837,7 +818,8 @@ export class BrowserCacheManager extends CacheManager {
837
818
  this.logger.trace(
838
819
  "BrowserCacheManager.setRefreshTokenCredential called"
839
820
  );
840
- const refreshTokenKey = refreshToken.generateCredentialKey();
821
+ const refreshTokenKey =
822
+ CacheHelpers.generateCredentialKey(refreshToken);
841
823
  this.setItem(refreshTokenKey, JSON.stringify(refreshToken));
842
824
 
843
825
  this.addTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
@@ -1804,7 +1786,7 @@ export class BrowserCacheManager extends CacheManager {
1804
1786
  currentCacheKey: string,
1805
1787
  credential: ValidCredentialType
1806
1788
  ): string {
1807
- const updatedCacheKey = credential.generateCredentialKey();
1789
+ const updatedCacheKey = CacheHelpers.generateCredentialKey(credential);
1808
1790
 
1809
1791
  if (currentCacheKey !== updatedCacheKey) {
1810
1792
  const cacheItem = this.getItem(currentCacheKey);
@@ -1860,7 +1842,7 @@ export class BrowserCacheManager extends CacheManager {
1860
1842
  | RedirectRequest
1861
1843
  | PopupRequest
1862
1844
  ): Promise<void> {
1863
- const idTokenEntity = IdTokenEntity.createIdTokenEntity(
1845
+ const idTokenEntity = CacheHelpers.createIdTokenEntity(
1864
1846
  result.account?.homeAccountId,
1865
1847
  result.account?.environment,
1866
1848
  result.idToken,
@@ -1872,7 +1854,7 @@ export class BrowserCacheManager extends CacheManager {
1872
1854
  if (request.claims) {
1873
1855
  claimsHash = await this.cryptoImpl.hashString(request.claims);
1874
1856
  }
1875
- const accessTokenEntity = AccessTokenEntity.createAccessTokenEntity(
1857
+ const accessTokenEntity = CacheHelpers.createAccessTokenEntity(
1876
1858
  result.account?.homeAccountId,
1877
1859
  result.account.environment,
1878
1860
  result.accessToken,
@@ -1881,7 +1863,7 @@ export class BrowserCacheManager extends CacheManager {
1881
1863
  result.scopes.join(" "),
1882
1864
  result.expiresOn?.getTime() || 0,
1883
1865
  result.extExpiresOn?.getTime() || 0,
1884
- this.cryptoImpl,
1866
+ base64Decode,
1885
1867
  undefined, // refreshOn
1886
1868
  result.tokenType as AuthenticationScheme,
1887
1869
  undefined, // userAssertionHash
@@ -18,6 +18,7 @@ import {
18
18
  Constants,
19
19
  CacheRecord,
20
20
  TokenClaims,
21
+ CacheHelpers,
21
22
  } from "@azure/msal-common";
22
23
  import { BrowserConfiguration } from "../config/Configuration";
23
24
  import { SilentRequest } from "../request/SilentRequest";
@@ -294,7 +295,7 @@ export class TokenCache implements ITokenCache {
294
295
  environment: string,
295
296
  tenantId: string
296
297
  ): IdTokenEntity {
297
- const idTokenEntity = IdTokenEntity.createIdTokenEntity(
298
+ const idTokenEntity = CacheHelpers.createIdTokenEntity(
298
299
  homeAccountId,
299
300
  environment,
300
301
  idToken,
@@ -355,7 +356,7 @@ export class TokenCache implements ITokenCache {
355
356
  response.expires_in + new Date().getTime() / 1000;
356
357
  const extendedExpiresOn = options.extendedExpiresOn;
357
358
 
358
- const accessTokenEntity = AccessTokenEntity.createAccessTokenEntity(
359
+ const accessTokenEntity = CacheHelpers.createAccessTokenEntity(
359
360
  homeAccountId,
360
361
  environment,
361
362
  response.access_token,
@@ -364,7 +365,7 @@ export class TokenCache implements ITokenCache {
364
365
  scopes,
365
366
  expiresOn,
366
367
  extendedExpiresOn,
367
- this.cryptoObj
368
+ base64Decode
368
369
  );
369
370
 
370
371
  if (this.isBrowserEnvironment) {
@@ -399,7 +400,7 @@ export class TokenCache implements ITokenCache {
399
400
  return null;
400
401
  }
401
402
 
402
- const refreshTokenEntity = RefreshTokenEntity.createRefreshTokenEntity(
403
+ const refreshTokenEntity = CacheHelpers.createRefreshTokenEntity(
403
404
  homeAccountId,
404
405
  environment,
405
406
  response.refresh_token,
@@ -6,61 +6,42 @@
6
6
  import { TeamsAppOperatingContext } from "../operatingcontext/TeamsAppOperatingContext";
7
7
  import { StandardOperatingContext } from "../operatingcontext/StandardOperatingContext";
8
8
  import { IController } from "./IController";
9
- import { Logger } from "@azure/msal-common";
10
9
  import { Configuration } from "../config/Configuration";
11
- import { version, name } from "../packageMetadata";
12
10
 
13
- export class ControllerFactory {
14
- protected config: Configuration;
15
- protected logger: Logger;
11
+ export async function createV3Controller(
12
+ config: Configuration
13
+ ): Promise<IController> {
14
+ const standard = new StandardOperatingContext(config);
16
15
 
17
- constructor(config: Configuration) {
18
- this.config = config;
19
- const loggerOptions = {
20
- loggerCallback: undefined,
21
- piiLoggingEnabled: false,
22
- logLevel: undefined,
23
- correlationId: undefined,
24
- };
25
- this.logger = new Logger(loggerOptions, name, version);
26
- }
27
-
28
- async createV3Controller(): Promise<IController> {
29
- const standard = new StandardOperatingContext(this.config);
16
+ await standard.initialize();
30
17
 
31
- await standard.initialize();
18
+ const controller = await import("./StandardController");
19
+ return await controller.StandardController.createController(standard);
20
+ }
32
21
 
22
+ export async function createController(
23
+ config: Configuration
24
+ ): Promise<IController | null> {
25
+ const standard = new StandardOperatingContext(config);
26
+ const teamsApp = new TeamsAppOperatingContext(config);
27
+
28
+ const operatingContexts = [standard.initialize(), teamsApp.initialize()];
29
+
30
+ await Promise.all(operatingContexts);
31
+
32
+ if (
33
+ teamsApp.isAvailable() &&
34
+ teamsApp.getConfig().auth.supportsNestedAppAuth
35
+ ) {
36
+ const controller = await import("./NestedAppAuthController");
37
+ return await controller.NestedAppAuthController.createController(
38
+ teamsApp
39
+ );
40
+ } else if (standard.isAvailable()) {
33
41
  const controller = await import("./StandardController");
34
42
  return await controller.StandardController.createController(standard);
35
- }
36
-
37
- async createController(): Promise<IController | null> {
38
- const standard = new StandardOperatingContext(this.config);
39
- const teamsApp = new TeamsAppOperatingContext(this.config);
40
-
41
- const operatingContexts = [
42
- standard.initialize(),
43
- teamsApp.initialize(),
44
- ];
45
-
46
- await Promise.all(operatingContexts);
47
-
48
- if (
49
- teamsApp.isAvailable() &&
50
- teamsApp.getConfig().auth.supportsNestedAppAuth
51
- ) {
52
- const controller = await import("./NestedAppAuthController");
53
- return await controller.NestedAppAuthController.createController(
54
- teamsApp
55
- );
56
- } else if (standard.isAvailable()) {
57
- const controller = await import("./StandardController");
58
- return await controller.StandardController.createController(
59
- standard
60
- );
61
- } else {
62
- // Since neither of the actual operating contexts are available keep the UnknownOperatingContextController
63
- return null;
64
- }
43
+ } else {
44
+ // Since neither of the actual operating contexts are available keep the UnknownOperatingContextController
45
+ return null;
65
46
  }
66
47
  }
@@ -8,7 +8,6 @@ import {
8
8
  Logger,
9
9
  PerformanceCallbackFunction,
10
10
  IPerformanceClient,
11
- CommonSilentFlowRequest,
12
11
  AccountFilter,
13
12
  } from "@azure/msal-common";
14
13
  import { RedirectRequest } from "../request/RedirectRequest";
@@ -48,11 +47,6 @@ export interface IController {
48
47
  accountId?: string
49
48
  ): Promise<AuthenticationResult>;
50
49
 
51
- acquireTokenByRefreshToken(
52
- commonRequest: CommonSilentFlowRequest,
53
- silentRequest: SilentRequest
54
- ): Promise<AuthenticationResult>;
55
-
56
50
  addEventCallback(callback: EventCallbackFunction): string | null;
57
51
 
58
52
  removeEventCallback(callbackId: string): void;
@@ -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,
@@ -30,6 +29,7 @@ import {
30
29
  ClientAuthErrorCodes,
31
30
  AccountFilter,
32
31
  buildStaticAuthorityOptions,
32
+ InteractionRequiredAuthErrorCodes,
33
33
  } from "@azure/msal-common";
34
34
  import {
35
35
  BrowserCacheManager,
@@ -1047,13 +1047,13 @@ export class StandardController implements IController {
1047
1047
  protected async acquireTokenFromCache(
1048
1048
  silentCacheClient: SilentCacheClient,
1049
1049
  commonRequest: CommonSilentFlowRequest,
1050
- silentRequest: SilentRequest
1050
+ cacheLookupPolicy: CacheLookupPolicy
1051
1051
  ): Promise<AuthenticationResult> {
1052
1052
  this.performanceClient.addQueueMeasurement(
1053
1053
  PerformanceEvents.AcquireTokenFromCache,
1054
1054
  commonRequest.correlationId
1055
1055
  );
1056
- switch (silentRequest.cacheLookupPolicy) {
1056
+ switch (cacheLookupPolicy) {
1057
1057
  case CacheLookupPolicy.Default:
1058
1058
  case CacheLookupPolicy.AccessToken:
1059
1059
  case CacheLookupPolicy.AccessTokenAndRefreshToken:
@@ -1074,18 +1074,18 @@ export class StandardController implements IController {
1074
1074
  /**
1075
1075
  * Attempt to acquire an access token via a refresh token
1076
1076
  * @param commonRequest CommonSilentFlowRequest
1077
- * @param silentRequest SilentRequest
1077
+ * @param cacheLookupPolicy CacheLookupPolicy
1078
1078
  * @returns A promise that, when resolved, returns the access token
1079
1079
  */
1080
1080
  public async acquireTokenByRefreshToken(
1081
1081
  commonRequest: CommonSilentFlowRequest,
1082
- silentRequest: SilentRequest
1082
+ cacheLookupPolicy: CacheLookupPolicy
1083
1083
  ): Promise<AuthenticationResult> {
1084
1084
  this.performanceClient.addQueueMeasurement(
1085
1085
  PerformanceEvents.AcquireTokenByRefreshToken,
1086
1086
  commonRequest.correlationId
1087
1087
  );
1088
- switch (silentRequest.cacheLookupPolicy) {
1088
+ switch (cacheLookupPolicy) {
1089
1089
  case CacheLookupPolicy.Default:
1090
1090
  case CacheLookupPolicy.AccessTokenAndRefreshToken:
1091
1091
  case CacheLookupPolicy.RefreshToken:
@@ -2055,12 +2055,8 @@ export class StandardController implements IController {
2055
2055
  request.correlationId
2056
2056
  )(request, account);
2057
2057
 
2058
- const requestWithCLP = {
2059
- ...request,
2060
- // set the request's CacheLookupPolicy to Default if it was not optionally passed in
2061
- cacheLookupPolicy:
2062
- request.cacheLookupPolicy || CacheLookupPolicy.Default,
2063
- };
2058
+ const cacheLookupPolicy =
2059
+ request.cacheLookupPolicy || CacheLookupPolicy.Default;
2064
2060
 
2065
2061
  result = invokeAsync(
2066
2062
  this.acquireTokenFromCache.bind(this),
@@ -2068,10 +2064,10 @@ export class StandardController implements IController {
2068
2064
  this.logger,
2069
2065
  this.performanceClient,
2070
2066
  silentRequest.correlationId
2071
- )(silentCacheClient, silentRequest, requestWithCLP).catch(
2067
+ )(silentCacheClient, silentRequest, cacheLookupPolicy).catch(
2072
2068
  (cacheError: AuthError) => {
2073
2069
  if (
2074
- requestWithCLP.cacheLookupPolicy ===
2070
+ request.cacheLookupPolicy ===
2075
2071
  CacheLookupPolicy.AccessToken
2076
2072
  ) {
2077
2073
  throw cacheError;
@@ -2091,42 +2087,42 @@ export class StandardController implements IController {
2091
2087
  this.logger,
2092
2088
  this.performanceClient,
2093
2089
  silentRequest.correlationId
2094
- )(silentRequest, requestWithCLP).catch(
2090
+ )(silentRequest, cacheLookupPolicy).catch(
2095
2091
  (refreshTokenError: AuthError) => {
2096
- const isServerError =
2097
- refreshTokenError instanceof ServerError;
2098
- const isInteractionRequiredError =
2099
- refreshTokenError instanceof
2100
- InteractionRequiredAuthError;
2101
- 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)) ||
2102
2101
  refreshTokenError.errorCode ===
2103
- BrowserConstants.INVALID_GRANT_ERROR;
2104
-
2105
- if (
2106
- (!isServerError ||
2107
- !isInvalidGrantError ||
2108
- isInteractionRequiredError ||
2109
- requestWithCLP.cacheLookupPolicy ===
2110
- CacheLookupPolicy.AccessTokenAndRefreshToken ||
2111
- requestWithCLP.cacheLookupPolicy ===
2112
- CacheLookupPolicy.RefreshToken) &&
2113
- requestWithCLP.cacheLookupPolicy !==
2114
- CacheLookupPolicy.Skip
2115
- ) {
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 {
2116
2124
  throw refreshTokenError;
2117
2125
  }
2118
-
2119
- this.logger.verbose(
2120
- "Refresh token expired/invalid or CacheLookupPolicy is set to Skip, attempting acquire token by iframe.",
2121
- request.correlationId
2122
- );
2123
- return invokeAsync(
2124
- this.acquireTokenBySilentIframe.bind(this),
2125
- PerformanceEvents.AcquireTokenBySilentIframe,
2126
- this.logger,
2127
- this.performanceClient,
2128
- silentRequest.correlationId
2129
- )(silentRequest);
2130
2126
  }
2131
2127
  );
2132
2128
  }
@@ -33,6 +33,7 @@ import {
33
33
  invokeAsync,
34
34
  createAuthError,
35
35
  AuthErrorCodes,
36
+ CacheHelpers,
36
37
  } from "@azure/msal-common";
37
38
  import { BaseInteractionClient } from "./BaseInteractionClient";
38
39
  import { BrowserConfiguration } from "../config/Configuration";
@@ -656,7 +657,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
656
657
  reqTimestamp: number
657
658
  ): void {
658
659
  const cachedIdToken: IdTokenEntity | null =
659
- IdTokenEntity.createIdTokenEntity(
660
+ CacheHelpers.createIdTokenEntity(
660
661
  homeAccountIdentifier,
661
662
  request.authority,
662
663
  response.id_token || "",
@@ -675,7 +676,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
675
676
  const responseScopes = this.generateScopes(response, request);
676
677
 
677
678
  const cachedAccessToken: AccessTokenEntity | null =
678
- AccessTokenEntity.createAccessTokenEntity(
679
+ CacheHelpers.createAccessTokenEntity(
679
680
  homeAccountIdentifier,
680
681
  request.authority,
681
682
  responseAccessToken,
@@ -684,7 +685,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
684
685
  responseScopes.printScopes(),
685
686
  tokenExpirationSeconds,
686
687
  0,
687
- this.browserCrypto
688
+ base64Decode
688
689
  );
689
690
 
690
691
  const nativeCacheRecord = new CacheRecord(