@azure/msal-browser 3.0.0-beta.0 → 3.0.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 (160) hide show
  1. package/README.md +0 -21
  2. package/dist/app/IPublicClientApplication.d.ts +3 -1
  3. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  4. package/dist/app/IPublicClientApplication.js +4 -1
  5. package/dist/app/IPublicClientApplication.js.map +1 -1
  6. package/dist/app/PublicClientApplication.d.ts +9 -1
  7. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  8. package/dist/app/PublicClientApplication.js +10 -1
  9. package/dist/app/PublicClientApplication.js.map +1 -1
  10. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  11. package/dist/broker/nativeBroker/NativeMessageHandler.js +5 -5
  12. package/dist/broker/nativeBroker/NativeMessageHandler.js.map +1 -1
  13. package/dist/broker/nativeBroker/NativeRequest.d.ts +2 -1
  14. package/dist/broker/nativeBroker/NativeRequest.d.ts.map +1 -1
  15. package/dist/cache/AsyncMemoryStorage.js +1 -1
  16. package/dist/cache/BrowserCacheManager.d.ts +8 -0
  17. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  18. package/dist/cache/BrowserCacheManager.js +20 -2
  19. package/dist/cache/BrowserCacheManager.js.map +1 -1
  20. package/dist/cache/BrowserStorage.js +1 -1
  21. package/dist/cache/CryptoKeyStore.d.ts +1 -1
  22. package/dist/cache/CryptoKeyStore.d.ts.map +1 -1
  23. package/dist/cache/CryptoKeyStore.js +1 -1
  24. package/dist/cache/CryptoKeyStore.js.map +1 -1
  25. package/dist/cache/DatabaseStorage.js +1 -1
  26. package/dist/cache/ITokenCache.d.ts +2 -1
  27. package/dist/cache/ITokenCache.d.ts.map +1 -1
  28. package/dist/cache/MemoryStorage.js +1 -1
  29. package/dist/cache/TokenCache.d.ts +2 -1
  30. package/dist/cache/TokenCache.d.ts.map +1 -1
  31. package/dist/cache/TokenCache.js +20 -19
  32. package/dist/cache/TokenCache.js.map +1 -1
  33. package/dist/cache/entities/CacheRecord.d.ts +6 -0
  34. package/dist/cache/entities/CacheRecord.d.ts.map +1 -0
  35. package/dist/config/Configuration.d.ts +14 -2
  36. package/dist/config/Configuration.d.ts.map +1 -1
  37. package/dist/config/Configuration.js +39 -5
  38. package/dist/config/Configuration.js.map +1 -1
  39. package/dist/controllers/ControllerFactory.js +1 -1
  40. package/dist/controllers/IController.d.ts +3 -1
  41. package/dist/controllers/IController.d.ts.map +1 -1
  42. package/dist/controllers/StandardController.d.ts +9 -1
  43. package/dist/controllers/StandardController.d.ts.map +1 -1
  44. package/dist/controllers/StandardController.js +59 -41
  45. package/dist/controllers/StandardController.js.map +1 -1
  46. package/dist/crypto/BrowserCrypto.js +1 -1
  47. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  48. package/dist/crypto/CryptoOps.js +4 -4
  49. package/dist/crypto/CryptoOps.js.map +1 -1
  50. package/dist/crypto/GuidGenerator.js +1 -1
  51. package/dist/crypto/ModernBrowserCrypto.js +1 -1
  52. package/dist/crypto/PkceGenerator.js +1 -1
  53. package/dist/crypto/SignedHttpRequest.js +1 -1
  54. package/dist/encode/Base64Decode.js +1 -1
  55. package/dist/encode/Base64Encode.js +1 -1
  56. package/dist/error/BrowserAuthError.d.ts +2 -2
  57. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  58. package/dist/error/BrowserAuthError.js +6 -6
  59. package/dist/error/BrowserAuthError.js.map +1 -1
  60. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  61. package/dist/error/NativeAuthError.d.ts +1 -1
  62. package/dist/error/NativeAuthError.d.ts.map +1 -1
  63. package/dist/error/NativeAuthError.js +1 -1
  64. package/dist/error/NativeAuthError.js.map +1 -1
  65. package/dist/event/EventHandler.js +1 -1
  66. package/dist/event/EventMessage.d.ts +2 -2
  67. package/dist/event/EventMessage.d.ts.map +1 -1
  68. package/dist/event/EventMessage.js +1 -1
  69. package/dist/event/EventMessage.js.map +1 -1
  70. package/dist/event/EventType.d.ts +1 -1
  71. package/dist/event/EventType.d.ts.map +1 -1
  72. package/dist/event/EventType.js +2 -2
  73. package/dist/index.d.ts +4 -1
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +4 -2
  76. package/dist/index.js.map +1 -1
  77. package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
  78. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  79. package/dist/interaction_client/BaseInteractionClient.js +7 -3
  80. package/dist/interaction_client/BaseInteractionClient.js.map +1 -1
  81. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
  82. package/dist/interaction_client/NativeInteractionClient.d.ts +3 -11
  83. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  84. package/dist/interaction_client/NativeInteractionClient.js +21 -25
  85. package/dist/interaction_client/NativeInteractionClient.js.map +1 -1
  86. package/dist/interaction_client/PopupClient.d.ts +6 -1
  87. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  88. package/dist/interaction_client/PopupClient.js +48 -9
  89. package/dist/interaction_client/PopupClient.js.map +1 -1
  90. package/dist/interaction_client/RedirectClient.d.ts +2 -1
  91. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  92. package/dist/interaction_client/RedirectClient.js +14 -2
  93. package/dist/interaction_client/RedirectClient.js.map +1 -1
  94. package/dist/interaction_client/SilentAuthCodeClient.d.ts +2 -1
  95. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  96. package/dist/interaction_client/SilentAuthCodeClient.js +1 -1
  97. package/dist/interaction_client/SilentCacheClient.d.ts +2 -1
  98. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  99. package/dist/interaction_client/SilentCacheClient.js +5 -5
  100. package/dist/interaction_client/SilentCacheClient.js.map +1 -1
  101. package/dist/interaction_client/SilentIframeClient.d.ts +2 -1
  102. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  103. package/dist/interaction_client/SilentIframeClient.js +4 -4
  104. package/dist/interaction_client/SilentIframeClient.js.map +1 -1
  105. package/dist/interaction_client/SilentRefreshClient.d.ts +2 -1
  106. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  107. package/dist/interaction_client/SilentRefreshClient.js +5 -4
  108. package/dist/interaction_client/SilentRefreshClient.js.map +1 -1
  109. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  110. package/dist/interaction_client/StandardInteractionClient.js +10 -5
  111. package/dist/interaction_client/StandardInteractionClient.js.map +1 -1
  112. package/dist/interaction_handler/InteractionHandler.d.ts +2 -1
  113. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  114. package/dist/interaction_handler/InteractionHandler.js +2 -2
  115. package/dist/interaction_handler/InteractionHandler.js.map +1 -1
  116. package/dist/interaction_handler/RedirectHandler.d.ts +2 -1
  117. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  118. package/dist/interaction_handler/RedirectHandler.js +2 -2
  119. package/dist/interaction_handler/RedirectHandler.js.map +1 -1
  120. package/dist/interaction_handler/SilentHandler.js +1 -1
  121. package/dist/internals.d.ts +1 -2
  122. package/dist/internals.d.ts.map +1 -1
  123. package/dist/internals.js +7 -3
  124. package/dist/internals.js.map +1 -1
  125. package/dist/navigation/NavigationClient.js +1 -1
  126. package/dist/network/FetchClient.js +1 -1
  127. package/dist/network/XhrClient.js +1 -1
  128. package/dist/operatingcontext/BaseOperatingContext.js +1 -1
  129. package/dist/operatingcontext/StandardOperatingContext.js +1 -1
  130. package/dist/operatingcontext/TeamsAppOperatingContext.js +1 -1
  131. package/dist/packageMetadata.d.ts +1 -1
  132. package/dist/packageMetadata.d.ts.map +1 -1
  133. package/dist/packageMetadata.js +2 -2
  134. package/dist/response/AuthenticationResult.d.ts +5 -0
  135. package/dist/response/AuthenticationResult.d.ts.map +1 -0
  136. package/dist/telemetry/BrowserPerformanceClient.d.ts +3 -2
  137. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  138. package/dist/telemetry/BrowserPerformanceClient.js +12 -8
  139. package/dist/telemetry/BrowserPerformanceClient.js.map +1 -1
  140. package/dist/telemetry/BrowserPerformanceMeasurement.js +1 -1
  141. package/dist/utils/BrowserConstants.d.ts +10 -10
  142. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  143. package/dist/utils/BrowserConstants.js +1 -1
  144. package/dist/utils/BrowserConstants.js.map +1 -1
  145. package/dist/utils/BrowserProtocolUtils.js +1 -1
  146. package/dist/utils/BrowserStringUtils.d.ts +0 -5
  147. package/dist/utils/BrowserStringUtils.d.ts.map +1 -1
  148. package/dist/utils/BrowserStringUtils.js +1 -13
  149. package/dist/utils/BrowserStringUtils.js.map +1 -1
  150. package/dist/utils/BrowserUtils.d.ts +2 -3
  151. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  152. package/dist/utils/BrowserUtils.js +5 -6
  153. package/dist/utils/BrowserUtils.js.map +1 -1
  154. package/dist/utils/MathUtils.js +1 -1
  155. package/lib/msal-browser.cjs.js +971 -687
  156. package/lib/msal-browser.cjs.js.map +1 -1
  157. package/lib/msal-browser.js +971 -687
  158. package/lib/msal-browser.js.map +1 -1
  159. package/lib/msal-browser.min.js +62 -62
  160. package/package.json +20 -18
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v3.0.0-beta.0 2023-06-19 */
1
+ /*! @azure/msal-browser v3.0.0 2023-08-08 */
2
2
  'use strict';
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -6,7 +6,7 @@
6
6
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.msal = {}));
7
7
  })(this, (function (exports) { 'use strict';
8
8
 
9
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
9
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
10
10
  /*
11
11
  * Copyright (c) Microsoft Corporation. All rights reserved.
12
12
  * Licensed under the MIT License.
@@ -203,11 +203,17 @@
203
203
  S256: "S256",
204
204
  };
205
205
  /**
206
- * allowed values for response_mode
206
+ * allowed values for server response type
207
207
  */
208
- const ResponseMode = {
208
+ const ServerResponseType = {
209
209
  QUERY: "query",
210
210
  FRAGMENT: "fragment",
211
+ };
212
+ /**
213
+ * allowed values for response_mode
214
+ */
215
+ const ResponseMode = {
216
+ ...ServerResponseType,
211
217
  FORM_POST: "form_post",
212
218
  };
213
219
  /**
@@ -360,7 +366,7 @@
360
366
  Pop: "pop",
361
367
  };
362
368
 
363
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
369
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
364
370
 
365
371
  /*
366
372
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -414,7 +420,7 @@
414
420
  }
415
421
  }
416
422
 
417
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
423
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
418
424
 
419
425
  /*
420
426
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -459,7 +465,7 @@
459
465
  },
460
466
  };
461
467
 
462
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
468
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
463
469
 
464
470
  /*
465
471
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -981,7 +987,7 @@
981
987
  }
982
988
  }
983
989
 
984
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
990
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
985
991
 
986
992
  /*
987
993
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1108,7 +1114,7 @@
1108
1114
  }
1109
1115
  }
1110
1116
 
1111
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1117
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1112
1118
 
1113
1119
  /*
1114
1120
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1308,12 +1314,12 @@
1308
1314
  }
1309
1315
  }
1310
1316
 
1311
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1317
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1312
1318
  /* eslint-disable header/header */
1313
1319
  const name$1 = "@azure/msal-common";
1314
- const version$1 = "14.0.0-beta.0";
1320
+ const version$1 = "14.0.0";
1315
1321
 
1316
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1322
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1317
1323
  /*
1318
1324
  * Copyright (c) Microsoft Corporation. All rights reserved.
1319
1325
  * Licensed under the MIT License.
@@ -1325,15 +1331,15 @@
1325
1331
  AzurePublic: "https://login.microsoftonline.com",
1326
1332
  // Microsoft PPE
1327
1333
  AzurePpe: "https://login.windows-ppe.net",
1328
- // Microsoft Chinese national cloud
1334
+ // Microsoft Chinese national/regional cloud
1329
1335
  AzureChina: "https://login.chinacloudapi.cn",
1330
- // Microsoft German national cloud ("Black Forest")
1336
+ // Microsoft German national/regional cloud ("Black Forest")
1331
1337
  AzureGermany: "https://login.microsoftonline.de",
1332
1338
  // US Government cloud
1333
1339
  AzureUsGovernment: "https://login.microsoftonline.us",
1334
1340
  };
1335
1341
 
1336
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1342
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1337
1343
 
1338
1344
  /*
1339
1345
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1433,12 +1439,20 @@
1433
1439
  },
1434
1440
  invalidAuthenticationHeader: {
1435
1441
  code: "invalid_authentication_header",
1436
- desc: "Invalid authentication header provided"
1442
+ desc: "Invalid authentication header provided",
1443
+ },
1444
+ cannotSetOIDCOptions: {
1445
+ code: "cannot_set_OIDCOptions",
1446
+ desc: "Cannot set OIDCOptions parameter. Please change the protocol mode to OIDC or use a non-Microsoft authority.",
1447
+ },
1448
+ cannotAllowNativeBroker: {
1449
+ code: "cannot_allow_native_broker",
1450
+ desc: "Cannot set allowNativeBroker parameter to true when not in AAD protocol mode.",
1437
1451
  },
1438
1452
  authorityMismatch: {
1439
1453
  code: "authority_mismatch",
1440
- desc: "Authority mismatch error. Authority provided in login request or PublicClientApplication config does not match the environment of the provided account. Please use a matching account or make an interactive request to login to this authority."
1441
- }
1454
+ desc: "Authority mismatch error. Authority provided in login request or PublicClientApplication config does not match the environment of the provided account. Please use a matching account or make an interactive request to login to this authority.",
1455
+ },
1442
1456
  };
1443
1457
  /**
1444
1458
  * Error thrown when there is an error in configuration of the MSAL.js library.
@@ -1587,6 +1601,18 @@
1587
1601
  static createInvalidAuthenticationHeaderError(invalidHeaderName, details) {
1588
1602
  return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthenticationHeader.code, `${ClientConfigurationErrorMessage.invalidAuthenticationHeader.desc}. Invalid header: ${invalidHeaderName}. Details: ${details}`);
1589
1603
  }
1604
+ /**
1605
+ * Throws error when provided non-default OIDCOptions when not in OIDC protocol mode
1606
+ */
1607
+ static createCannotSetOIDCOptionsError() {
1608
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.cannotSetOIDCOptions.code, ClientConfigurationErrorMessage.cannotSetOIDCOptions.desc);
1609
+ }
1610
+ /**
1611
+ * Throws error when allowNativeBroker is set to true when not in AAD protocol mode
1612
+ */
1613
+ static createCannotAllowNativeBrokerError() {
1614
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.cannotAllowNativeBroker.code, ClientConfigurationErrorMessage.cannotAllowNativeBroker.desc);
1615
+ }
1590
1616
  /**
1591
1617
  * Create an error when the authority provided in request does not match authority provided in account or MSAL.js configuration.
1592
1618
  */
@@ -1595,7 +1621,7 @@
1595
1621
  }
1596
1622
  }
1597
1623
 
1598
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1624
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1599
1625
 
1600
1626
  /*
1601
1627
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1795,7 +1821,7 @@
1795
1821
  }
1796
1822
  }
1797
1823
 
1798
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1824
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1799
1825
 
1800
1826
  /*
1801
1827
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1835,7 +1861,7 @@
1835
1861
  };
1836
1862
  }
1837
1863
 
1838
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1864
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1839
1865
  /*
1840
1866
  * Copyright (c) Microsoft Corporation. All rights reserved.
1841
1867
  * Licensed under the MIT License.
@@ -1847,10 +1873,23 @@
1847
1873
  Default: 0,
1848
1874
  Adfs: 1,
1849
1875
  Dsts: 2,
1850
- Ciam: 3
1876
+ Ciam: 3,
1877
+ };
1878
+
1879
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1880
+ /*
1881
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1882
+ * Licensed under the MIT License.
1883
+ */
1884
+ /**
1885
+ * Protocol modes supported by MSAL.
1886
+ */
1887
+ const ProtocolMode = {
1888
+ AAD: "AAD",
1889
+ OIDC: "OIDC",
1851
1890
  };
1852
1891
 
1853
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
1892
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
1854
1893
 
1855
1894
  /*
1856
1895
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1872,7 +1911,6 @@
1872
1911
  * username: primary username that represents the user, usually corresponds to preferred_username in the v2 endpt
1873
1912
  * authorityType: Accounts authority type as a string
1874
1913
  * name: Full name for the account, including given name and family name,
1875
- * clientInfo: Full base64 encoded client info received from ESTS
1876
1914
  * lastModificationTime: last time this entity was modified in the cache
1877
1915
  * lastModificationApp:
1878
1916
  * idTokenClaims: Object containing claims parsed from ID token
@@ -1899,24 +1937,6 @@
1899
1937
  localAccountId: this.localAccountId,
1900
1938
  });
1901
1939
  }
1902
- /**
1903
- * returns the type of the cache (in this case account)
1904
- */
1905
- generateType() {
1906
- switch (this.authorityType) {
1907
- case CacheAccountType.ADFS_ACCOUNT_TYPE:
1908
- return CacheType.ADFS;
1909
- case CacheAccountType.MSAV1_ACCOUNT_TYPE:
1910
- return CacheType.MSA;
1911
- case CacheAccountType.MSSTS_ACCOUNT_TYPE:
1912
- return CacheType.MSSTS;
1913
- case CacheAccountType.GENERIC_ACCOUNT_TYPE:
1914
- return CacheType.GENERIC;
1915
- default: {
1916
- throw ClientAuthError.createUnexpectedAccountTypeError();
1917
- }
1918
- }
1919
- }
1920
1940
  /**
1921
1941
  * Returns the AccountInfo interface for this account.
1922
1942
  */
@@ -1930,6 +1950,7 @@
1930
1950
  name: this.name,
1931
1951
  idTokenClaims: this.idTokenClaims,
1932
1952
  nativeAccountId: this.nativeAccountId,
1953
+ authorityType: this.authorityType,
1933
1954
  };
1934
1955
  }
1935
1956
  /**
@@ -1946,84 +1967,74 @@
1946
1967
  }
1947
1968
  /**
1948
1969
  * Build Account cache from IdToken, clientInfo and authority/policy. Associated with AAD.
1949
- * @param clientInfo
1950
- * @param authority
1951
- * @param idToken
1952
- * @param policy
1970
+ * @param accountDetails
1953
1971
  */
1954
- static createAccount(clientInfo, homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
1972
+ static createAccount(accountDetails, authority) {
1955
1973
  const account = new AccountEntity();
1956
- account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE;
1957
- account.clientInfo = clientInfo;
1958
- account.homeAccountId = homeAccountId;
1959
- account.nativeAccountId = nativeAccountId;
1960
- const env = environment || (authority && authority.getPreferredCache());
1974
+ if (authority.authorityType === AuthorityType.Adfs) {
1975
+ account.authorityType = CacheAccountType.ADFS_ACCOUNT_TYPE;
1976
+ }
1977
+ else if (authority.protocolMode === ProtocolMode.AAD) {
1978
+ account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE;
1979
+ }
1980
+ else {
1981
+ account.authorityType = CacheAccountType.GENERIC_ACCOUNT_TYPE;
1982
+ }
1983
+ account.clientInfo = accountDetails.clientInfo;
1984
+ account.homeAccountId = accountDetails.homeAccountId;
1985
+ account.nativeAccountId = accountDetails.nativeAccountId;
1986
+ const env = accountDetails.environment ||
1987
+ (authority && authority.getPreferredCache());
1961
1988
  if (!env) {
1962
1989
  throw ClientAuthError.createInvalidCacheEnvironmentError();
1963
1990
  }
1964
1991
  account.environment = env;
1965
1992
  // non AAD scenarios can have empty realm
1966
- account.realm = idToken?.claims?.tid || Constants.EMPTY_STRING;
1967
- if (idToken) {
1968
- account.idTokenClaims = idToken.claims;
1969
- // How do you account for MSA CID here?
1970
- account.localAccountId =
1971
- idToken?.claims?.oid ||
1972
- idToken?.claims?.sub ||
1973
- Constants.EMPTY_STRING;
1974
- /*
1975
- * In B2C scenarios the emails claim is used instead of preferred_username and it is an array.
1976
- * In most cases it will contain a single email. This field should not be relied upon if a custom
1977
- * policy is configured to return more than 1 email.
1978
- */
1979
- const preferredUsername = idToken?.claims?.preferred_username;
1980
- const email = idToken?.claims?.emails
1981
- ? idToken.claims.emails[0]
1982
- : null;
1983
- account.username =
1984
- preferredUsername || email || Constants.EMPTY_STRING;
1985
- account.name = idToken?.claims?.name;
1986
- }
1987
- account.cloudGraphHostName = cloudGraphHostName;
1988
- account.msGraphHost = msGraphHost;
1993
+ account.realm =
1994
+ accountDetails.idTokenClaims.tid || Constants.EMPTY_STRING;
1995
+ account.idTokenClaims = accountDetails.idTokenClaims;
1996
+ // How do you account for MSA CID here?
1997
+ account.localAccountId =
1998
+ accountDetails.idTokenClaims.oid ||
1999
+ accountDetails.idTokenClaims.sub ||
2000
+ Constants.EMPTY_STRING;
2001
+ /*
2002
+ * In B2C scenarios the emails claim is used instead of preferred_username and it is an array.
2003
+ * In most cases it will contain a single email. This field should not be relied upon if a custom
2004
+ * policy is configured to return more than 1 email.
2005
+ */
2006
+ const preferredUsername = accountDetails.idTokenClaims.preferred_username ||
2007
+ accountDetails.idTokenClaims.upn;
2008
+ const email = accountDetails.idTokenClaims.emails
2009
+ ? accountDetails.idTokenClaims.emails[0]
2010
+ : null;
2011
+ account.username = preferredUsername || email || Constants.EMPTY_STRING;
2012
+ account.name = accountDetails.idTokenClaims.name;
2013
+ account.cloudGraphHostName = accountDetails.cloudGraphHostName;
2014
+ account.msGraphHost = accountDetails.msGraphHost;
1989
2015
  return account;
1990
2016
  }
1991
2017
  /**
1992
- * Builds non-AAD/ADFS account.
1993
- * @param authority
1994
- * @param idToken
2018
+ * Creates an AccountEntity object from AccountInfo
2019
+ * @param accountInfo
2020
+ * @param cloudGraphHostName
2021
+ * @param msGraphHost
2022
+ * @returns
1995
2023
  */
1996
- static createGenericAccount(homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment) {
2024
+ static createFromAccountInfo(accountInfo, cloudGraphHostName, msGraphHost) {
1997
2025
  const account = new AccountEntity();
1998
2026
  account.authorityType =
1999
- authority && authority.authorityType === AuthorityType.Adfs
2000
- ? CacheAccountType.ADFS_ACCOUNT_TYPE
2001
- : CacheAccountType.GENERIC_ACCOUNT_TYPE;
2002
- account.homeAccountId = homeAccountId;
2003
- // non AAD scenarios can have empty realm
2004
- account.realm = Constants.EMPTY_STRING;
2005
- const env = environment || (authority && authority.getPreferredCache());
2006
- if (!env) {
2007
- throw ClientAuthError.createInvalidCacheEnvironmentError();
2008
- }
2009
- if (idToken) {
2010
- // How do you account for MSA CID here?
2011
- account.localAccountId =
2012
- idToken?.claims?.oid ||
2013
- idToken?.claims?.sub ||
2014
- Constants.EMPTY_STRING;
2015
- // upn claim for most ADFS scenarios
2016
- account.username = idToken?.claims?.upn || Constants.EMPTY_STRING;
2017
- account.name = idToken?.claims?.name || Constants.EMPTY_STRING;
2018
- account.idTokenClaims = idToken?.claims;
2019
- }
2020
- account.environment = env;
2027
+ accountInfo.authorityType || CacheAccountType.GENERIC_ACCOUNT_TYPE;
2028
+ account.homeAccountId = accountInfo.homeAccountId;
2029
+ account.localAccountId = accountInfo.localAccountId;
2030
+ account.nativeAccountId = accountInfo.nativeAccountId;
2031
+ account.realm = accountInfo.tenantId;
2032
+ account.environment = accountInfo.environment;
2033
+ account.username = accountInfo.username;
2034
+ account.name = accountInfo.name;
2035
+ account.idTokenClaims = accountInfo.idTokenClaims;
2021
2036
  account.cloudGraphHostName = cloudGraphHostName;
2022
2037
  account.msGraphHost = msGraphHost;
2023
- /*
2024
- * add uniqueName to claims
2025
- * account.name = idToken.claims.uniqueName;
2026
- */
2027
2038
  return account;
2028
2039
  }
2029
2040
  /**
@@ -2031,9 +2042,9 @@
2031
2042
  * @param serverClientInfo
2032
2043
  * @param authType
2033
2044
  */
2034
- static generateHomeAccountId(serverClientInfo, authType, logger, cryptoObj, idToken) {
2035
- const accountId = idToken?.claims?.sub
2036
- ? idToken.claims.sub
2045
+ static generateHomeAccountId(serverClientInfo, authType, logger, cryptoObj, idTokenClaims) {
2046
+ const accountId = idTokenClaims?.sub
2047
+ ? idTokenClaims.sub
2037
2048
  : Constants.EMPTY_STRING;
2038
2049
  // since ADFS does not have tid and does not set client_info
2039
2050
  if (authType === AuthorityType.Adfs ||
@@ -2101,7 +2112,7 @@
2101
2112
  }
2102
2113
  }
2103
2114
 
2104
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
2115
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
2105
2116
 
2106
2117
  /*
2107
2118
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2152,7 +2163,7 @@
2152
2163
  }
2153
2164
  }
2154
2165
 
2155
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
2166
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
2156
2167
 
2157
2168
  /*
2158
2169
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2218,20 +2229,21 @@
2218
2229
  * saves a cache record
2219
2230
  * @param cacheRecord
2220
2231
  */
2221
- async saveCacheRecord(cacheRecord) {
2232
+ async saveCacheRecord(cacheRecord, storeInCache) {
2222
2233
  if (!cacheRecord) {
2223
2234
  throw ClientAuthError.createNullOrUndefinedCacheRecord();
2224
2235
  }
2225
2236
  if (!!cacheRecord.account) {
2226
2237
  this.setAccount(cacheRecord.account);
2227
2238
  }
2228
- if (!!cacheRecord.idToken) {
2239
+ if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
2229
2240
  this.setIdTokenCredential(cacheRecord.idToken);
2230
2241
  }
2231
- if (!!cacheRecord.accessToken) {
2242
+ if (!!cacheRecord.accessToken && storeInCache?.accessToken !== false) {
2232
2243
  await this.saveAccessToken(cacheRecord.accessToken);
2233
2244
  }
2234
- if (!!cacheRecord.refreshToken) {
2245
+ if (!!cacheRecord.refreshToken &&
2246
+ storeInCache?.refreshToken !== false) {
2235
2247
  this.setRefreshTokenCredential(cacheRecord.refreshToken);
2236
2248
  }
2237
2249
  if (!!cacheRecord.appMetadata) {
@@ -3166,7 +3178,7 @@
3166
3178
  }
3167
3179
  }
3168
3180
 
3169
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3181
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3170
3182
 
3171
3183
  /*
3172
3184
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3186,6 +3198,9 @@
3186
3198
  logLevel: exports.LogLevel.Info,
3187
3199
  correlationId: Constants.EMPTY_STRING,
3188
3200
  };
3201
+ const DEFAULT_CACHE_OPTIONS = {
3202
+ claimsBasedCachingEnabled: false,
3203
+ };
3189
3204
  const DEFAULT_NETWORK_IMPLEMENTATION = {
3190
3205
  async sendGetRequestAsync() {
3191
3206
  const notImplErr = "Network interface - sendGetRequestAsync() has not been implemented";
@@ -3223,7 +3238,7 @@
3223
3238
  *
3224
3239
  * @returns Configuration
3225
3240
  */
3226
- function buildClientConfiguration({ authOptions: userAuthOptions, systemOptions: userSystemOptions, loggerOptions: userLoggerOption, storageInterface: storageImplementation, networkInterface: networkImplementation, cryptoInterface: cryptoImplementation, clientCredentials: clientCredentials, libraryInfo: libraryInfo, telemetry: telemetry, serverTelemetryManager: serverTelemetryManager, persistencePlugin: persistencePlugin, serializableCache: serializableCache, }) {
3241
+ function buildClientConfiguration({ authOptions: userAuthOptions, systemOptions: userSystemOptions, loggerOptions: userLoggerOption, cacheOptions: userCacheOptions, storageInterface: storageImplementation, networkInterface: networkImplementation, cryptoInterface: cryptoImplementation, clientCredentials: clientCredentials, libraryInfo: libraryInfo, telemetry: telemetry, serverTelemetryManager: serverTelemetryManager, persistencePlugin: persistencePlugin, serializableCache: serializableCache, }) {
3227
3242
  const loggerOptions = {
3228
3243
  ...DEFAULT_LOGGER_IMPLEMENTATION,
3229
3244
  ...userLoggerOption,
@@ -3232,6 +3247,7 @@
3232
3247
  authOptions: buildAuthOptions(userAuthOptions),
3233
3248
  systemOptions: { ...DEFAULT_SYSTEM_OPTIONS, ...userSystemOptions },
3234
3249
  loggerOptions: loggerOptions,
3250
+ cacheOptions: { ...DEFAULT_CACHE_OPTIONS, ...userCacheOptions },
3235
3251
  storageInterface: storageImplementation ||
3236
3252
  new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION, new Logger(loggerOptions)),
3237
3253
  networkInterface: networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,
@@ -3256,8 +3272,15 @@
3256
3272
  ...authOptions,
3257
3273
  };
3258
3274
  }
3275
+ /**
3276
+ * Returns true if config has protocolMode set to ProtocolMode.OIDC, false otherwise
3277
+ * @param ClientConfiguration
3278
+ */
3279
+ function isOidcProtocolMode(config) {
3280
+ return (config.authOptions.authority.options.protocolMode === ProtocolMode.OIDC);
3281
+ }
3259
3282
 
3260
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3283
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3261
3284
 
3262
3285
  /*
3263
3286
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3274,7 +3297,7 @@
3274
3297
  }
3275
3298
  }
3276
3299
 
3277
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3300
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3278
3301
 
3279
3302
  /*
3280
3303
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3371,7 +3394,7 @@
3371
3394
  }
3372
3395
  }
3373
3396
 
3374
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3397
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3375
3398
 
3376
3399
  /*
3377
3400
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3407,7 +3430,7 @@
3407
3430
  }
3408
3431
  }
3409
3432
 
3410
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3433
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3411
3434
  /*
3412
3435
  * Copyright (c) Microsoft Corporation. All rights reserved.
3413
3436
  * Licensed under the MIT License.
@@ -3417,7 +3440,7 @@
3417
3440
  UPN: "UPN",
3418
3441
  };
3419
3442
 
3420
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3443
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3421
3444
 
3422
3445
  /*
3423
3446
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3498,11 +3521,11 @@
3498
3521
  }
3499
3522
  });
3500
3523
  // remove empty string parameters
3501
- return Object.fromEntries(Object.entries(eQParams).filter(kv => kv[1] !== ""));
3524
+ return Object.fromEntries(Object.entries(eQParams).filter((kv) => kv[1] !== ""));
3502
3525
  }
3503
3526
  }
3504
3527
 
3505
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3528
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3506
3529
 
3507
3530
  /*
3508
3531
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3542,9 +3565,15 @@
3542
3565
  * @param scopeSet
3543
3566
  * @param addOidcScopes
3544
3567
  */
3545
- addScopes(scopes, addOidcScopes = true) {
3568
+ addScopes(scopes, addOidcScopes = true, defaultScopes = OIDC_DEFAULT_SCOPES) {
3569
+ // Always add openid to the scopes when adding OIDC scopes
3570
+ if (addOidcScopes &&
3571
+ !defaultScopes.includes("openid") &&
3572
+ !scopes.includes("openid")) {
3573
+ defaultScopes.push("openid");
3574
+ }
3546
3575
  const requestScopes = addOidcScopes
3547
- ? [...(scopes || []), ...OIDC_DEFAULT_SCOPES]
3576
+ ? [...(scopes || []), ...defaultScopes]
3548
3577
  : scopes || [];
3549
3578
  const scopeSet = new ScopeSet(requestScopes);
3550
3579
  this.parameters.set(AADServerParamKeys.SCOPE, encodeURIComponent(scopeSet.printScopes()));
@@ -3879,7 +3908,7 @@
3879
3908
  }
3880
3909
  }
3881
3910
 
3882
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
3911
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3883
3912
 
3884
3913
  /*
3885
3914
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3974,7 +4003,7 @@
3974
4003
  }
3975
4004
  }
3976
4005
 
3977
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4006
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3978
4007
 
3979
4008
  /*
3980
4009
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4113,7 +4142,7 @@
4113
4142
  }
4114
4143
  }
4115
4144
 
4116
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4145
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4117
4146
 
4118
4147
  /*
4119
4148
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4172,7 +4201,7 @@
4172
4201
  }
4173
4202
  }
4174
4203
 
4175
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4204
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4176
4205
  /*
4177
4206
  * Copyright (c) Microsoft Corporation. All rights reserved.
4178
4207
  * Licensed under the MIT License.
@@ -4219,7 +4248,7 @@
4219
4248
  }
4220
4249
  }
4221
4250
 
4222
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4251
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4223
4252
 
4224
4253
  /*
4225
4254
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4333,7 +4362,7 @@
4333
4362
  }
4334
4363
  }
4335
4364
 
4336
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4365
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4337
4366
 
4338
4367
  /*
4339
4368
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4395,7 +4424,7 @@
4395
4424
  }
4396
4425
  }
4397
4426
 
4398
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4427
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4399
4428
 
4400
4429
  /*
4401
4430
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4476,7 +4505,7 @@
4476
4505
  }
4477
4506
  }
4478
4507
 
4479
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4508
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4480
4509
  /*
4481
4510
  * Copyright (c) Microsoft Corporation. All rights reserved.
4482
4511
  * Licensed under the MIT License.
@@ -4491,7 +4520,7 @@
4491
4520
  }
4492
4521
  }
4493
4522
 
4494
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4523
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4495
4524
 
4496
4525
  /*
4497
4526
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4565,7 +4594,7 @@
4565
4594
  }
4566
4595
  }
4567
4596
 
4568
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4597
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4569
4598
 
4570
4599
  /*
4571
4600
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4749,6 +4778,30 @@
4749
4778
  }
4750
4779
  return Constants.EMPTY_STRING;
4751
4780
  }
4781
+ /**
4782
+ * Parses query server response string from given string.
4783
+ * Extract hash between '?code=' and '#' if trailing '# is present.
4784
+ * Returns empty string if no query symbol is found.
4785
+ * @param queryString
4786
+ */
4787
+ static parseQueryServerResponse(queryString) {
4788
+ const queryIndex1 = queryString.indexOf("?code");
4789
+ const queryIndex2 = queryString.indexOf("/?code");
4790
+ const hashIndex = queryString.indexOf("#");
4791
+ if (queryIndex2 > -1 && hashIndex > -1) {
4792
+ return queryString.substring(queryIndex2 + 2, hashIndex);
4793
+ }
4794
+ else if (queryIndex2 > -1) {
4795
+ return queryString.substring(queryIndex2 + 2);
4796
+ }
4797
+ else if (queryIndex1 > -1 && hashIndex > -1) {
4798
+ return queryString.substring(queryIndex1 + 1, hashIndex);
4799
+ }
4800
+ else if (queryIndex1 > -1) {
4801
+ return queryString.substring(queryIndex1 + 1);
4802
+ }
4803
+ return Constants.EMPTY_STRING;
4804
+ }
4752
4805
  static constructAuthorityUriFromObject(urlObject) {
4753
4806
  return new UrlString(urlObject.Protocol +
4754
4807
  "//" +
@@ -4794,6 +4847,21 @@
4794
4847
  }
4795
4848
  return deserializedQueryString;
4796
4849
  }
4850
+ /**
4851
+ * Returns either deserialized query string or deserialized hash, depending on the serverResponseType
4852
+ * as a server auth code response object.
4853
+ */
4854
+ static getDeserializedCodeResponse(serverResponseType, hashFragment) {
4855
+ const hashUrlString = new UrlString(hashFragment);
4856
+ let serverParams;
4857
+ if (serverResponseType === ServerResponseType.QUERY) {
4858
+ serverParams = UrlString.getDeserializedQueryString(hashFragment);
4859
+ }
4860
+ else {
4861
+ serverParams = UrlString.getDeserializedHash(hashUrlString.getHash());
4862
+ }
4863
+ return serverParams;
4864
+ }
4797
4865
  /**
4798
4866
  * Check if the hash of the URL string contains known properties
4799
4867
  */
@@ -4810,7 +4878,7 @@
4810
4878
  }
4811
4879
  }
4812
4880
 
4813
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
4881
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4814
4882
  /*
4815
4883
  * Copyright (c) Microsoft Corporation. All rights reserved.
4816
4884
  * Licensed under the MIT License.
@@ -5013,6 +5081,7 @@
5013
5081
  UpdateCloudDiscoveryMetadataMeasurement: "updateCloudDiscoveryMetadataMeasurement",
5014
5082
  UsernamePasswordClientAcquireToken: "usernamePasswordClientAcquireToken",
5015
5083
  NativeMessageHandlerHandshake: "nativeMessageHandlerHandshake",
5084
+ NativeGenerateAuthResult: "nativeGenerateAuthResult",
5016
5085
  };
5017
5086
  /**
5018
5087
  * State of the performance event.
@@ -5037,7 +5106,7 @@
5037
5106
  "status",
5038
5107
  ]);
5039
5108
 
5040
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
5109
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5041
5110
 
5042
5111
  /*
5043
5112
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5122,7 +5191,7 @@
5122
5191
  }
5123
5192
  }
5124
5193
 
5125
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
5194
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5126
5195
 
5127
5196
  /*
5128
5197
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5191,7 +5260,7 @@
5191
5260
  }
5192
5261
  }
5193
5262
 
5194
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
5263
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5195
5264
  /*
5196
5265
  * Copyright (c) Microsoft Corporation. All rights reserved.
5197
5266
  * Licensed under the MIT License.
@@ -5218,7 +5287,7 @@
5218
5287
  }
5219
5288
  }
5220
5289
 
5221
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
5290
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5222
5291
 
5223
5292
  /*
5224
5293
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5245,12 +5314,25 @@
5245
5314
  */
5246
5315
  validateServerAuthorizationCodeResponse(serverResponseHash, cachedState, cryptoObj) {
5247
5316
  if (!serverResponseHash.state || !cachedState) {
5248
- throw !serverResponseHash.state
5249
- ? ClientAuthError.createStateNotFoundError("Server State")
5250
- : ClientAuthError.createStateNotFoundError("Cached State");
5317
+ throw serverResponseHash.state
5318
+ ? ClientAuthError.createStateNotFoundError("Cached State")
5319
+ : ClientAuthError.createStateNotFoundError("Server State");
5320
+ }
5321
+ let decodedServerResponseHash;
5322
+ let decodedCachedState;
5323
+ try {
5324
+ decodedServerResponseHash = decodeURIComponent(serverResponseHash.state);
5325
+ }
5326
+ catch (e) {
5327
+ throw ClientAuthError.createInvalidStateError(serverResponseHash.state, `Server response hash URI could not be decoded`);
5328
+ }
5329
+ try {
5330
+ decodedCachedState = decodeURIComponent(cachedState);
5331
+ }
5332
+ catch (e) {
5333
+ throw ClientAuthError.createInvalidStateError(serverResponseHash.state, `Cached state URI could not be decoded`);
5251
5334
  }
5252
- if (decodeURIComponent(serverResponseHash.state) !==
5253
- decodeURIComponent(cachedState)) {
5335
+ if (decodedServerResponseHash !== decodedCachedState) {
5254
5336
  throw ClientAuthError.createStateMismatchError();
5255
5337
  }
5256
5338
  // Check for error
@@ -5310,7 +5392,7 @@
5310
5392
  }
5311
5393
  }
5312
5394
  // generate homeAccountId
5313
- this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);
5395
+ this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj?.claims);
5314
5396
  // save the response tokens
5315
5397
  let requestStateObj;
5316
5398
  if (!!authCodePayload && !!authCodePayload.state) {
@@ -5343,7 +5425,7 @@
5343
5425
  return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, undefined, serverRequestId);
5344
5426
  }
5345
5427
  }
5346
- await this.cacheStorage.saveCacheRecord(cacheRecord);
5428
+ await this.cacheStorage.saveCacheRecord(cacheRecord, request.storeInCache);
5347
5429
  }
5348
5430
  finally {
5349
5431
  if (this.persistencePlugin &&
@@ -5372,7 +5454,13 @@
5372
5454
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) &&
5373
5455
  !!idTokenObj) {
5374
5456
  cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
5375
- cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, authCodePayload);
5457
+ cachedAccount = AccountEntity.createAccount({
5458
+ homeAccountId: this.homeAccountIdentifier,
5459
+ idTokenClaims: idTokenObj.claims,
5460
+ clientInfo: serverTokenResponse.client_info,
5461
+ cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
5462
+ msGraphHost: authCodePayload?.msgraph_host,
5463
+ }, authority);
5376
5464
  }
5377
5465
  // AccessToken
5378
5466
  let cachedAccessToken = null;
@@ -5416,34 +5504,6 @@
5416
5504
  }
5417
5505
  return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);
5418
5506
  }
5419
- /**
5420
- * Generate Account
5421
- * @param serverTokenResponse
5422
- * @param idToken
5423
- * @param authority
5424
- */
5425
- generateAccountEntity(serverTokenResponse, idToken, authority, authCodePayload) {
5426
- const authorityType = authority.authorityType;
5427
- const cloudGraphHostName = authCodePayload
5428
- ? authCodePayload.cloud_graph_host_name
5429
- : Constants.EMPTY_STRING;
5430
- const msGraphhost = authCodePayload
5431
- ? authCodePayload.msgraph_host
5432
- : Constants.EMPTY_STRING;
5433
- // ADFS does not require client_info in the response
5434
- if (authorityType === AuthorityType.Adfs) {
5435
- this.logger.verbose("Authority type is ADFS, creating ADFS account");
5436
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
5437
- }
5438
- // This fallback applies to B2C as well as they fall under an AAD account type.
5439
- if (StringUtils.isEmpty(serverTokenResponse.client_info) &&
5440
- authority.protocolMode === "AAD") {
5441
- throw ClientAuthError.createClientInfoEmptyError();
5442
- }
5443
- return serverTokenResponse.client_info
5444
- ? AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost)
5445
- : AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
5446
- }
5447
5507
  /**
5448
5508
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
5449
5509
  *
@@ -5521,7 +5581,7 @@
5521
5581
  }
5522
5582
  }
5523
5583
 
5524
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
5584
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5525
5585
 
5526
5586
  /*
5527
5587
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5535,6 +5595,8 @@
5535
5595
  super(configuration, performanceClient);
5536
5596
  // Flag to indicate if client is for hybrid spa auth code redemption
5537
5597
  this.includeRedirectUri = true;
5598
+ this.oidcDefaultScopes =
5599
+ this.config.authOptions.authority.options.OIDCOptions?.defaultScopes;
5538
5600
  }
5539
5601
  /**
5540
5602
  * Creates the URL of the authorization request letting the user input credentials and consent to the
@@ -5573,7 +5635,7 @@
5573
5635
  const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
5574
5636
  const httpVerAuthority = response.headers?.[HeaderNames.X_MS_HTTP_VERSION];
5575
5637
  if (httpVerAuthority) {
5576
- atsMeasurement?.addStaticFields({
5638
+ atsMeasurement?.add({
5577
5639
  httpVerAuthority,
5578
5640
  });
5579
5641
  }
@@ -5584,14 +5646,14 @@
5584
5646
  return responseHandler
5585
5647
  .handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, authCodePayload, undefined, undefined, undefined, requestId)
5586
5648
  .then((result) => {
5587
- atsMeasurement?.endMeasurement({
5649
+ atsMeasurement?.end({
5588
5650
  success: true,
5589
5651
  });
5590
5652
  return result;
5591
5653
  })
5592
5654
  .catch((error) => {
5593
5655
  this.logger.verbose("Error in fetching token in ACC", request.correlationId);
5594
- atsMeasurement?.endMeasurement({
5656
+ atsMeasurement?.end({
5595
5657
  errorCode: error.errorCode,
5596
5658
  subErrorCode: error.subError,
5597
5659
  success: false,
@@ -5607,10 +5669,8 @@
5607
5669
  handleFragmentResponse(hashFragment, cachedState) {
5608
5670
  // Handle responses.
5609
5671
  const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, null, null);
5610
- // Deserialize hash fragment response parameters.
5611
- const hashUrlString = new UrlString(hashFragment);
5612
- // Deserialize hash fragment response parameters.
5613
- const serverParams = UrlString.getDeserializedHash(hashUrlString.getHash());
5672
+ const serverParams = UrlString.getDeserializedCodeResponse(this.config.authOptions.authority.options.OIDCOptions
5673
+ ?.serverResponseType, hashFragment);
5614
5674
  // Get code response
5615
5675
  responseHandler.validateServerAuthorizationCodeResponse(serverParams, cachedState, this.cryptoUtils);
5616
5676
  // throw when there is no auth code in the response
@@ -5696,14 +5756,14 @@
5696
5756
  parameterBuilder.addRedirectUri(request.redirectUri);
5697
5757
  }
5698
5758
  // Add scope array, parameter builder will add default scopes and dedupe
5699
- parameterBuilder.addScopes(request.scopes);
5759
+ parameterBuilder.addScopes(request.scopes, true, this.oidcDefaultScopes);
5700
5760
  // add code: user set, not validated
5701
5761
  parameterBuilder.addAuthorizationCode(request.code);
5702
5762
  // Add library metadata
5703
5763
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5704
5764
  parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5705
5765
  parameterBuilder.addThrottling();
5706
- if (this.serverTelemetryManager) {
5766
+ if (this.serverTelemetryManager && !isOidcProtocolMode(this.config)) {
5707
5767
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
5708
5768
  }
5709
5769
  // add code_verifier if passed
@@ -5802,7 +5862,7 @@
5802
5862
  ...(request.scopes || []),
5803
5863
  ...(request.extraScopesToConsent || []),
5804
5864
  ];
5805
- parameterBuilder.addScopes(requestScopes);
5865
+ parameterBuilder.addScopes(requestScopes, true, this.oidcDefaultScopes);
5806
5866
  // validate the redirectUri (to be a non null value)
5807
5867
  parameterBuilder.addRedirectUri(request.redirectUri);
5808
5868
  // generate the correlationId if not set by the user and add
@@ -5815,7 +5875,9 @@
5815
5875
  parameterBuilder.addResponseTypeCode();
5816
5876
  // add library info parameters
5817
5877
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5818
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5878
+ if (!isOidcProtocolMode(this.config)) {
5879
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5880
+ }
5819
5881
  // add client_info=1
5820
5882
  parameterBuilder.addClientInfo();
5821
5883
  if (request.codeChallenge && request.codeChallengeMethod) {
@@ -5957,7 +6019,7 @@
5957
6019
  }
5958
6020
  }
5959
6021
 
5960
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
6022
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5961
6023
 
5962
6024
  /*
5963
6025
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5978,11 +6040,11 @@
5978
6040
  this.performanceClient?.setPreQueueTime(PerformanceEvents.RefreshTokenClientExecuteTokenRequest, request.correlationId);
5979
6041
  const response = await this.executeTokenRequest(request, this.authority);
5980
6042
  const httpVerToken = response.headers?.[HeaderNames.X_MS_HTTP_VERSION];
5981
- atsMeasurement?.addStaticFields({
6043
+ atsMeasurement?.add({
5982
6044
  refreshTokenSize: response.body.refresh_token?.length || 0,
5983
6045
  });
5984
6046
  if (httpVerToken) {
5985
- atsMeasurement?.addStaticFields({
6047
+ atsMeasurement?.add({
5986
6048
  httpVerToken,
5987
6049
  });
5988
6050
  }
@@ -5994,14 +6056,14 @@
5994
6056
  return responseHandler
5995
6057
  .handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true, request.forceCache, requestId)
5996
6058
  .then((result) => {
5997
- atsMeasurement?.endMeasurement({
6059
+ atsMeasurement?.end({
5998
6060
  success: true,
5999
6061
  });
6000
6062
  return result;
6001
6063
  })
6002
6064
  .catch((error) => {
6003
6065
  this.logger.verbose("Error in fetching refresh token", request.correlationId);
6004
- atsMeasurement?.endMeasurement({
6066
+ atsMeasurement?.end({
6005
6067
  errorCode: error.errorCode,
6006
6068
  subErrorCode: error.subError,
6007
6069
  success: false,
@@ -6065,11 +6127,11 @@
6065
6127
  this.logger.verbose("RefreshTokenClientAcquireTokenWithCachedRefreshToken called", request.correlationId);
6066
6128
  const refreshToken = this.cacheManager.getRefreshToken(request.account, foci);
6067
6129
  if (!refreshToken) {
6068
- atsMeasurement?.discardMeasurement();
6130
+ atsMeasurement?.discard();
6069
6131
  throw InteractionRequiredAuthError.createNoTokensFoundError();
6070
6132
  }
6071
6133
  // attach cached RT size to the current measurement
6072
- atsMeasurement?.endMeasurement({
6134
+ atsMeasurement?.end({
6073
6135
  success: true,
6074
6136
  });
6075
6137
  const refreshTokenRequest = {
@@ -6110,13 +6172,13 @@
6110
6172
  };
6111
6173
  return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)
6112
6174
  .then((result) => {
6113
- acquireTokenMeasurement?.endMeasurement({
6175
+ acquireTokenMeasurement?.end({
6114
6176
  success: true,
6115
6177
  });
6116
6178
  return result;
6117
6179
  })
6118
6180
  .catch((error) => {
6119
- acquireTokenMeasurement?.endMeasurement({
6181
+ acquireTokenMeasurement?.end({
6120
6182
  success: false,
6121
6183
  });
6122
6184
  throw error;
@@ -6132,13 +6194,13 @@
6132
6194
  const acquireTokenMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.BaseClientCreateTokenRequestHeaders, correlationId);
6133
6195
  const parameterBuilder = new RequestParameterBuilder();
6134
6196
  parameterBuilder.addClientId(this.config.authOptions.clientId);
6135
- parameterBuilder.addScopes(request.scopes);
6197
+ parameterBuilder.addScopes(request.scopes, true, this.config.authOptions.authority.options.OIDCOptions?.defaultScopes);
6136
6198
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
6137
6199
  parameterBuilder.addClientInfo();
6138
6200
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6139
6201
  parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6140
6202
  parameterBuilder.addThrottling();
6141
- if (this.serverTelemetryManager) {
6203
+ if (this.serverTelemetryManager && !isOidcProtocolMode(this.config)) {
6142
6204
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
6143
6205
  }
6144
6206
  parameterBuilder.addCorrelationId(correlationId);
@@ -6163,7 +6225,7 @@
6163
6225
  parameterBuilder.addSshJwk(request.sshJwk);
6164
6226
  }
6165
6227
  else {
6166
- acquireTokenMeasurement?.endMeasurement({
6228
+ acquireTokenMeasurement?.end({
6167
6229
  success: false,
6168
6230
  });
6169
6231
  throw ClientConfigurationError.createMissingSshJwkError();
@@ -6192,14 +6254,14 @@
6192
6254
  break;
6193
6255
  }
6194
6256
  }
6195
- acquireTokenMeasurement?.endMeasurement({
6257
+ acquireTokenMeasurement?.end({
6196
6258
  success: true,
6197
6259
  });
6198
6260
  return parameterBuilder.createQueryString();
6199
6261
  }
6200
6262
  }
6201
6263
 
6202
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
6264
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
6203
6265
 
6204
6266
  /*
6205
6267
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6244,6 +6306,12 @@
6244
6306
  this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
6245
6307
  throw ClientAuthError.createRefreshRequiredError();
6246
6308
  }
6309
+ else if (!this.config.cacheOptions.claimsBasedCachingEnabled &&
6310
+ !StringUtils.isEmptyObj(request.claims)) {
6311
+ // Must refresh due to request parameters.
6312
+ this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because claims-based caching is disabled and claims were requested.");
6313
+ throw ClientAuthError.createRefreshRequiredError();
6314
+ }
6247
6315
  // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
6248
6316
  if (!request.account) {
6249
6317
  throw ClientAuthError.createNoAccountInSilentRequestError();
@@ -6296,7 +6364,7 @@
6296
6364
  }
6297
6365
  }
6298
6366
 
6299
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
6367
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
6300
6368
  /*
6301
6369
  * Copyright (c) Microsoft Corporation. All rights reserved.
6302
6370
  * Licensed under the MIT License.
@@ -6308,7 +6376,7 @@
6308
6376
  response.hasOwnProperty("jwks_uri"));
6309
6377
  }
6310
6378
 
6311
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
6379
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
6312
6380
  /*
6313
6381
  * Copyright (c) Microsoft Corporation. All rights reserved.
6314
6382
  * Licensed under the MIT License.
@@ -7185,21 +7253,16 @@
7185
7253
  };
7186
7254
  const EndpointMetadata = rawMetdataJSON.endpointMetadata;
7187
7255
  const InstanceDiscoveryMetadata = rawMetdataJSON.instanceDiscoveryMetadata;
7256
+ const InstanceDiscoveryMetadataAliases = new Set();
7257
+ for (const key in InstanceDiscoveryMetadata) {
7258
+ for (const metadata of InstanceDiscoveryMetadata[key].metadata) {
7259
+ for (const alias of metadata.aliases) {
7260
+ InstanceDiscoveryMetadataAliases.add(alias);
7261
+ }
7262
+ }
7263
+ }
7188
7264
 
7189
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
7190
- /*
7191
- * Copyright (c) Microsoft Corporation. All rights reserved.
7192
- * Licensed under the MIT License.
7193
- */
7194
- /**
7195
- * Protocol modes supported by MSAL.
7196
- */
7197
- const ProtocolMode = {
7198
- AAD: "AAD",
7199
- OIDC: "OIDC",
7200
- };
7201
-
7202
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
7265
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7203
7266
 
7204
7267
  /*
7205
7268
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7279,7 +7342,7 @@
7279
7342
  }
7280
7343
  }
7281
7344
 
7282
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
7345
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7283
7346
  /*
7284
7347
  * Copyright (c) Microsoft Corporation. All rights reserved.
7285
7348
  * Licensed under the MIT License.
@@ -7289,7 +7352,7 @@
7289
7352
  response.hasOwnProperty("metadata"));
7290
7353
  }
7291
7354
 
7292
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
7355
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7293
7356
  /*
7294
7357
  * Copyright (c) Microsoft Corporation. All rights reserved.
7295
7358
  * Licensed under the MIT License.
@@ -7299,7 +7362,7 @@
7299
7362
  response.hasOwnProperty("error_description"));
7300
7363
  }
7301
7364
 
7302
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
7365
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7303
7366
 
7304
7367
  /*
7305
7368
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7410,7 +7473,7 @@
7410
7473
  },
7411
7474
  };
7412
7475
 
7413
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
7476
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7414
7477
 
7415
7478
  /*
7416
7479
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7583,10 +7646,10 @@
7583
7646
  * @private
7584
7647
  */
7585
7648
  canReplaceTenant(authorityUri) {
7586
- return authorityUri.PathSegments.length === 1
7587
- && !Authority.reservedTenantDomains.has(authorityUri.PathSegments[0])
7588
- && this.getAuthorityType(authorityUri) === AuthorityType.Default
7589
- && this.protocolMode === ProtocolMode.AAD;
7649
+ return (authorityUri.PathSegments.length === 1 &&
7650
+ !Authority.reservedTenantDomains.has(authorityUri.PathSegments[0]) &&
7651
+ this.getAuthorityType(authorityUri) === AuthorityType.Default &&
7652
+ this.protocolMode === ProtocolMode.AAD);
7590
7653
  }
7591
7654
  /**
7592
7655
  * Replaces tenant in url path with current tenant. Defaults to common.
@@ -7607,8 +7670,9 @@
7607
7670
  const currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
7608
7671
  currentAuthorityParts.forEach((currentPart, index) => {
7609
7672
  let cachedPart = cachedAuthorityParts[index];
7610
- if (index === 0 && this.canReplaceTenant(cachedAuthorityUrlComponents)) {
7611
- const tenantId = (new UrlString(this.metadata.authorization_endpoint)).getUrlComponents().PathSegments[0];
7673
+ if (index === 0 &&
7674
+ this.canReplaceTenant(cachedAuthorityUrlComponents)) {
7675
+ const tenantId = new UrlString(this.metadata.authorization_endpoint).getUrlComponents().PathSegments[0];
7612
7676
  /**
7613
7677
  * Check if AAD canonical authority contains tenant domain name, for example "testdomain.onmicrosoft.com",
7614
7678
  * by comparing its first path segment to the corresponding authorization endpoint path segment, which is
@@ -7629,8 +7693,9 @@
7629
7693
  * The default open id configuration endpoint for any canonical authority.
7630
7694
  */
7631
7695
  get defaultOpenIdConfigurationEndpoint() {
7696
+ const canonicalAuthorityHost = this.hostnameAndPort;
7632
7697
  if (this.authorityType === AuthorityType.Adfs ||
7633
- this.protocolMode === ProtocolMode.OIDC) {
7698
+ !this.isAliasOfKnownMicrosoftAuthority(canonicalAuthorityHost)) {
7634
7699
  return `${this.canonicalAuthority}.well-known/openid-configuration`;
7635
7700
  }
7636
7701
  return `${this.canonicalAuthority}v2.0/.well-known/openid-configuration`;
@@ -7673,41 +7738,65 @@
7673
7738
  */
7674
7739
  async updateEndpointMetadata(metadataEntity) {
7675
7740
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
7741
+ this.logger.verbose("Attempting to get endpoint metadata from authority configuration");
7676
7742
  let metadata = this.getEndpointMetadataFromConfig();
7677
7743
  if (metadata) {
7744
+ this.logger.verbose("Found endpoint metadata in authority configuration");
7678
7745
  metadataEntity.updateEndpointMetadata(metadata, false);
7679
7746
  return AuthorityMetadataSource.CONFIG;
7680
7747
  }
7748
+ this.logger.verbose("Did not find endpoint metadata in the config... Attempting to get endpoint metadata from the hardcoded values.");
7749
+ // skipAuthorityMetadataCache is used to bypass hardcoded authority metadata and force a network metadata cache lookup and network metadata request if no cached response is available.
7750
+ if (this.authorityOptions.skipAuthorityMetadataCache) {
7751
+ this.logger.verbose("Skipping hardcoded metadata cache since skipAuthorityMetadataCache is set to true. Attempting to get endpoint metadata from the network metadata cache.");
7752
+ }
7753
+ else {
7754
+ let hardcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
7755
+ if (hardcodedMetadata) {
7756
+ this.logger.verbose("Found endpoint metadata from hardcoded values.");
7757
+ // If the user prefers to use an azure region replace the global endpoints with regional information.
7758
+ if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7759
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7760
+ this.logger.verbose("Found azure region configuration. Updating endpoints with regional information.");
7761
+ hardcodedMetadata =
7762
+ await this.updateMetadataWithRegionalInformation(hardcodedMetadata);
7763
+ }
7764
+ metadataEntity.updateEndpointMetadata(hardcodedMetadata, false);
7765
+ return AuthorityMetadataSource.HARDCODED_VALUES;
7766
+ }
7767
+ else {
7768
+ this.logger.verbose("Did not find endpoint metadata in hardcoded values... Attempting to get endpoint metadata from the network metadata cache.");
7769
+ }
7770
+ }
7771
+ // Check cached metadata entity expiration status
7772
+ const metadataEntityExpired = metadataEntity.isExpired();
7681
7773
  if (this.isAuthoritySameType(metadataEntity) &&
7682
7774
  metadataEntity.endpointsFromNetwork &&
7683
- !metadataEntity.isExpired()) {
7775
+ !metadataEntityExpired) {
7684
7776
  // No need to update
7777
+ this.logger.verbose("Found endpoint metadata in the cache.");
7685
7778
  return AuthorityMetadataSource.CACHE;
7686
7779
  }
7780
+ else if (metadataEntityExpired) {
7781
+ this.logger.verbose("The metadata entity is expired.");
7782
+ }
7783
+ this.logger.verbose("Did not find cached endpoint metadata... Attempting to get endpoint metadata from the network.");
7687
7784
  this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
7688
7785
  metadata = await this.getEndpointMetadataFromNetwork();
7689
7786
  if (metadata) {
7787
+ this.logger.verbose("Endpoint metadata was successfully returned from getEndpointMetadataFromNetwork()");
7690
7788
  // If the user prefers to use an azure region replace the global endpoints with regional information.
7691
7789
  if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7692
7790
  this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7791
+ this.logger.verbose("Found azure region configuration. Updating endpoints with regional information.");
7693
7792
  metadata = await this.updateMetadataWithRegionalInformation(metadata);
7694
7793
  }
7695
7794
  metadataEntity.updateEndpointMetadata(metadata, true);
7696
7795
  return AuthorityMetadataSource.NETWORK;
7697
7796
  }
7698
- let harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
7699
- if (harcodedMetadata &&
7700
- !this.authorityOptions.skipAuthorityMetadataCache) {
7701
- // If the user prefers to use an azure region replace the global endpoints with regional information.
7702
- if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7703
- this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7704
- harcodedMetadata =
7705
- await this.updateMetadataWithRegionalInformation(harcodedMetadata);
7706
- }
7707
- metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
7708
- return AuthorityMetadataSource.HARDCODED_VALUES;
7709
- }
7710
7797
  else {
7798
+ // Metadata could not be obtained from the config, cache, network or hardcoded values
7799
+ this.logger.error("Did not find endpoint metadata from network... Metadata could not be obtained from config, cache, network or hardcoded values. Throwing Untrusted Authority Error.");
7711
7800
  throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7712
7801
  }
7713
7802
  }
@@ -7756,17 +7845,23 @@
7756
7845
  const response = await this.networkInterface.sendGetRequestAsync(openIdConfigurationEndpoint, options);
7757
7846
  const isValidResponse = isOpenIdConfigResponse(response.body);
7758
7847
  if (isValidResponse) {
7759
- perfEvent?.endMeasurement({ success: true });
7848
+ perfEvent?.end({ success: true });
7760
7849
  return response.body;
7761
7850
  }
7762
7851
  else {
7763
- perfEvent?.endMeasurement({ success: false, errorCode: "invalid_response" });
7852
+ perfEvent?.end({
7853
+ success: false,
7854
+ errorCode: "invalid_response",
7855
+ });
7764
7856
  this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: could not parse response as OpenID configuration`);
7765
7857
  return null;
7766
7858
  }
7767
7859
  }
7768
7860
  catch (e) {
7769
- perfEvent?.endMeasurement({ success: false, errorCode: "request_failure" });
7861
+ perfEvent?.end({
7862
+ success: false,
7863
+ errorCode: "request_failure",
7864
+ });
7770
7865
  this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: ${e}`);
7771
7866
  return null;
7772
7867
  }
@@ -7782,37 +7877,32 @@
7782
7877
  }
7783
7878
  /**
7784
7879
  * Update the retrieved metadata with regional information.
7880
+ * User selected Azure region will be used if configured.
7785
7881
  */
7786
7882
  async updateMetadataWithRegionalInformation(metadata) {
7787
7883
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7788
- this.performanceClient?.setPreQueueTime(PerformanceEvents.RegionDiscoveryDetectRegion, this.correlationId);
7789
- const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration?.environmentRegion, this.regionDiscoveryMetadata);
7790
- const azureRegion = this.authorityOptions.azureRegionConfiguration?.azureRegion ===
7791
- Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
7792
- ? autodetectedRegionName
7793
- : this.authorityOptions.azureRegionConfiguration?.azureRegion;
7794
- if (this.authorityOptions.azureRegionConfiguration?.azureRegion ===
7795
- Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7796
- this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName
7797
- ? RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL
7798
- : RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7799
- }
7800
- else {
7801
- if (autodetectedRegionName) {
7884
+ const userConfiguredAzureRegion = this.authorityOptions.azureRegionConfiguration?.azureRegion;
7885
+ if (userConfiguredAzureRegion) {
7886
+ if (userConfiguredAzureRegion !==
7887
+ Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7802
7888
  this.regionDiscoveryMetadata.region_outcome =
7803
- this.authorityOptions.azureRegionConfiguration
7804
- ?.azureRegion === autodetectedRegionName
7805
- ? RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED
7806
- : RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
7889
+ RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7890
+ this.regionDiscoveryMetadata.region_used =
7891
+ userConfiguredAzureRegion;
7892
+ return Authority.replaceWithRegionalInformation(metadata, userConfiguredAzureRegion);
7807
7893
  }
7808
- else {
7894
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.RegionDiscoveryDetectRegion, this.correlationId);
7895
+ const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration
7896
+ ?.environmentRegion, this.regionDiscoveryMetadata);
7897
+ if (autodetectedRegionName) {
7809
7898
  this.regionDiscoveryMetadata.region_outcome =
7810
- RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7899
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL;
7900
+ this.regionDiscoveryMetadata.region_used =
7901
+ autodetectedRegionName;
7902
+ return Authority.replaceWithRegionalInformation(metadata, autodetectedRegionName);
7811
7903
  }
7812
- }
7813
- if (azureRegion) {
7814
- this.regionDiscoveryMetadata.region_used = azureRegion;
7815
- return Authority.replaceWithRegionalInformation(metadata, azureRegion);
7904
+ this.regionDiscoveryMetadata.region_outcome =
7905
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7816
7906
  }
7817
7907
  return metadata;
7818
7908
  }
@@ -7824,7 +7914,7 @@
7824
7914
  */
7825
7915
  async updateCloudDiscoveryMetadata(metadataEntity) {
7826
7916
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
7827
- this.logger.verbose("Attempting to get cloud discovery metadata in the config");
7917
+ this.logger.verbose("Attempting to get cloud discovery metadata from authority configuration");
7828
7918
  this.logger.verbosePii(`Known Authorities: ${this.authorityOptions.knownAuthorities ||
7829
7919
  Constants.NOT_APPLICABLE}`);
7830
7920
  this.logger.verbosePii(`Authority Metadata: ${this.authorityOptions.authorityMetadata ||
@@ -7832,17 +7922,29 @@
7832
7922
  this.logger.verbosePii(`Canonical Authority: ${metadataEntity.canonical_authority || Constants.NOT_APPLICABLE}`);
7833
7923
  let metadata = this.getCloudDiscoveryMetadataFromConfig();
7834
7924
  if (metadata) {
7835
- this.logger.verbose("Found cloud discovery metadata in the config.");
7925
+ this.logger.verbose("Found cloud discovery metadata in authority configuration");
7836
7926
  metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
7837
7927
  return AuthorityMetadataSource.CONFIG;
7838
7928
  }
7839
- // If the cached metadata came from config but that config was not passed to this instance, we must go to the network
7840
- this.logger.verbose("Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the cache.");
7929
+ // If the cached metadata came from config but that config was not passed to this instance, we must go to hardcoded values
7930
+ this.logger.verbose("Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the hardcoded values.");
7931
+ if (this.options.skipAuthorityMetadataCache) {
7932
+ this.logger.verbose("Skipping hardcoded cloud discovery metadata cache since skipAuthorityMetadataCache is set to true. Attempting to get cloud discovery metadata from the network metadata cache.");
7933
+ }
7934
+ else {
7935
+ const hardcodedMetadata = this.getCloudDiscoveryMetadataFromHardcodedValues();
7936
+ if (hardcodedMetadata) {
7937
+ this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
7938
+ metadataEntity.updateCloudDiscoveryMetadata(hardcodedMetadata, false);
7939
+ return AuthorityMetadataSource.HARDCODED_VALUES;
7940
+ }
7941
+ this.logger.verbose("Did not find cloud discovery metadata in hardcoded values... Attempting to get cloud discovery metadata from the network metadata cache.");
7942
+ }
7841
7943
  const metadataEntityExpired = metadataEntity.isExpired();
7842
7944
  if (this.isAuthoritySameType(metadataEntity) &&
7843
7945
  metadataEntity.aliasesFromNetwork &&
7844
7946
  !metadataEntityExpired) {
7845
- this.logger.verbose("Found metadata in the cache.");
7947
+ this.logger.verbose("Found cloud discovery metadata in the cache.");
7846
7948
  // No need to update
7847
7949
  return AuthorityMetadataSource.CACHE;
7848
7950
  }
@@ -7857,15 +7959,8 @@
7857
7959
  metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
7858
7960
  return AuthorityMetadataSource.NETWORK;
7859
7961
  }
7860
- this.logger.verbose("Did not find cloud discovery metadata from the network... Attempting to get cloud discovery metadata from hardcoded values.");
7861
- const harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
7862
- if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
7863
- this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
7864
- metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
7865
- return AuthorityMetadataSource.HARDCODED_VALUES;
7866
- }
7867
7962
  // Metadata could not be obtained from the config, cache, network or hardcoded values
7868
- this.logger.error("Did not find cloud discovery metadata from hardcoded values... Metadata could not be obtained from config, cache, network or hardcoded values. Throwing Untrusted Authority Error.");
7963
+ this.logger.error("Did not find cloud discovery metadata from network... Metadata could not be obtained from config, cache, network or hardcoded values. Throwing Untrusted Authority Error.");
7869
7964
  throw ClientConfigurationError.createUntrustedAuthorityError();
7870
7965
  }
7871
7966
  /**
@@ -7970,9 +8065,11 @@
7970
8065
  /**
7971
8066
  * Get cloud discovery metadata for common authorities
7972
8067
  */
7973
- getCloudDiscoveryMetadataFromHarcodedValues() {
8068
+ getCloudDiscoveryMetadataFromHardcodedValues() {
7974
8069
  if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
7975
- return InstanceDiscoveryMetadata[this.canonicalAuthority];
8070
+ const hardcodedMetadataResponse = InstanceDiscoveryMetadata[this.canonicalAuthority];
8071
+ const metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(hardcodedMetadataResponse.metadata, this.hostnameAndPort);
8072
+ return metadata;
7976
8073
  }
7977
8074
  return null;
7978
8075
  }
@@ -8047,6 +8144,13 @@
8047
8144
  isAlias(host) {
8048
8145
  return this.metadata.aliases.indexOf(host) > -1;
8049
8146
  }
8147
+ /**
8148
+ * Returns whether or not the provided host is an alias of a known Microsoft authority for purposes of endpoint discovery
8149
+ * @param host
8150
+ */
8151
+ isAliasOfKnownMicrosoftAuthority(host) {
8152
+ return InstanceDiscoveryMetadataAliases.has(host);
8153
+ }
8050
8154
  /**
8051
8155
  * Checks whether the provided host is that of a public cloud authority
8052
8156
  *
@@ -8088,15 +8192,17 @@
8088
8192
  * @param azureRegion string
8089
8193
  */
8090
8194
  static replaceWithRegionalInformation(metadata, azureRegion) {
8091
- metadata.authorization_endpoint =
8092
- Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
8195
+ const regionalMetadata = { ...metadata };
8196
+ regionalMetadata.authorization_endpoint =
8197
+ Authority.buildRegionalAuthorityString(regionalMetadata.authorization_endpoint, azureRegion);
8093
8198
  // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
8094
- metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
8095
- if (metadata.end_session_endpoint) {
8096
- metadata.end_session_endpoint =
8097
- Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
8199
+ regionalMetadata.token_endpoint =
8200
+ Authority.buildRegionalAuthorityString(regionalMetadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
8201
+ if (regionalMetadata.end_session_endpoint) {
8202
+ regionalMetadata.end_session_endpoint =
8203
+ Authority.buildRegionalAuthorityString(regionalMetadata.end_session_endpoint, azureRegion);
8098
8204
  }
8099
- return metadata;
8205
+ return regionalMetadata;
8100
8206
  }
8101
8207
  /**
8102
8208
  * Transform CIAM_AUTHORIY as per the below rules:
@@ -8108,11 +8214,14 @@
8108
8214
  * @param authority
8109
8215
  */
8110
8216
  static transformCIAMAuthority(authority) {
8111
- let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH) ? authority : `${authority}${Constants.FORWARD_SLASH}`;
8217
+ let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH)
8218
+ ? authority
8219
+ : `${authority}${Constants.FORWARD_SLASH}`;
8112
8220
  const authorityUrl = new UrlString(authority);
8113
8221
  const authorityUrlComponents = authorityUrl.getUrlComponents();
8114
8222
  // check if transformation is needed
8115
- if (authorityUrlComponents.PathSegments.length === 0 && (authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL))) {
8223
+ if (authorityUrlComponents.PathSegments.length === 0 &&
8224
+ authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL)) {
8116
8225
  const tenantIdOrDomain = authorityUrlComponents.HostNameAndPort.split(".")[0];
8117
8226
  ciamAuthority = `${ciamAuthority}${tenantIdOrDomain}${Constants.AAD_TENANT_DOMAIN_SUFFIX}`;
8118
8227
  }
@@ -8120,15 +8229,15 @@
8120
8229
  }
8121
8230
  }
8122
8231
  // Reserved tenant domain names that will not be replaced with tenant id
8123
- Authority.reservedTenantDomains = (new Set([
8232
+ Authority.reservedTenantDomains = new Set([
8124
8233
  "{tenant}",
8125
8234
  "{tenantid}",
8126
8235
  AADAuthorityConstants.COMMON,
8127
8236
  AADAuthorityConstants.CONSUMERS,
8128
- AADAuthorityConstants.ORGANIZATIONS
8129
- ]));
8237
+ AADAuthorityConstants.ORGANIZATIONS,
8238
+ ]);
8130
8239
 
8131
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8240
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8132
8241
 
8133
8242
  /*
8134
8243
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8178,7 +8287,7 @@
8178
8287
  }
8179
8288
  }
8180
8289
 
8181
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8290
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8182
8291
 
8183
8292
  /*
8184
8293
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8208,7 +8317,7 @@
8208
8317
  }
8209
8318
  }
8210
8319
 
8211
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8320
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8212
8321
 
8213
8322
  /*
8214
8323
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8234,7 +8343,7 @@
8234
8343
  }
8235
8344
  }
8236
8345
 
8237
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8346
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8238
8347
 
8239
8348
  /*
8240
8349
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8251,7 +8360,7 @@
8251
8360
  },
8252
8361
  };
8253
8362
 
8254
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8363
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8255
8364
 
8256
8365
  /*
8257
8366
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8293,7 +8402,7 @@
8293
8402
  }
8294
8403
  }
8295
8404
 
8296
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8405
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8297
8406
 
8298
8407
  /*
8299
8408
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8332,7 +8441,7 @@
8332
8441
  }
8333
8442
  }
8334
8443
 
8335
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8444
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8336
8445
 
8337
8446
  /*
8338
8447
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8390,7 +8499,7 @@
8390
8499
  }
8391
8500
  }
8392
8501
 
8393
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8502
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8394
8503
 
8395
8504
  /*
8396
8505
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8589,7 +8698,7 @@
8589
8698
  }
8590
8699
  }
8591
8700
 
8592
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
8701
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8593
8702
 
8594
8703
  /*
8595
8704
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8606,8 +8715,10 @@
8606
8715
  * @param {Logger} logger Logger used by the application
8607
8716
  * @param {string} libraryName Name of the library
8608
8717
  * @param {string} libraryVersion Version of the library
8718
+ * @param {ApplicationTelemetry} applicationTelemetry application name and version
8719
+ * @param {Set<String>} intFields integer fields to be truncated
8609
8720
  */
8610
- constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
8721
+ constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry, intFields) {
8611
8722
  this.authority = authority;
8612
8723
  this.libraryName = libraryName;
8613
8724
  this.libraryVersion = libraryVersion;
@@ -8618,6 +8729,10 @@
8618
8729
  this.eventsByCorrelationId = new Map();
8619
8730
  this.queueMeasurements = new Map();
8620
8731
  this.preQueueTimeByCorrelationId = new Map();
8732
+ this.intFields = intFields || new Set();
8733
+ for (const item of IntFields) {
8734
+ this.intFields.add(item);
8735
+ }
8621
8736
  }
8622
8737
  /**
8623
8738
  * Starts and returns an platform-specific implementation of IPerformanceMeasurement.
@@ -8632,13 +8747,6 @@
8632
8747
  ) {
8633
8748
  return {};
8634
8749
  }
8635
- /**
8636
- * Get integral fields.
8637
- * Override to change the set.
8638
- */
8639
- getIntFields() {
8640
- return IntFields;
8641
- }
8642
8750
  /**
8643
8751
  * Gets map of pre-queue times by correlation Id
8644
8752
  *
@@ -8756,7 +8864,7 @@
8756
8864
  this.cacheEventByCorrelationId(inProgressEvent);
8757
8865
  // Return the event and functions the caller can use to properly end/flush the measurement
8758
8866
  return {
8759
- endMeasurement: (event) => {
8867
+ end: (event) => {
8760
8868
  return this.endMeasurement({
8761
8869
  // Initial set of event properties
8762
8870
  ...inProgressEvent,
@@ -8764,14 +8872,14 @@
8764
8872
  ...event,
8765
8873
  }, performanceMeasurement);
8766
8874
  },
8767
- discardMeasurement: () => {
8875
+ discard: () => {
8768
8876
  return this.discardMeasurements(inProgressEvent.correlationId);
8769
8877
  },
8770
- addStaticFields: (fields) => {
8771
- return this.addStaticFields(fields, inProgressEvent.correlationId);
8878
+ add: (fields) => {
8879
+ return this.addFields(fields, inProgressEvent.correlationId);
8772
8880
  },
8773
- increment: (counters) => {
8774
- return this.increment(counters, inProgressEvent.correlationId);
8881
+ increment: (fields) => {
8882
+ return this.incrementFields(fields, inProgressEvent.correlationId);
8775
8883
  },
8776
8884
  measurement: performanceMeasurement,
8777
8885
  event: inProgressEvent,
@@ -8836,7 +8944,7 @@
8836
8944
  status: PerformanceEventStatus.Completed,
8837
8945
  incompleteSubsCount,
8838
8946
  };
8839
- this.truncateIntegralFields(finalEvent, this.getIntFields());
8947
+ this.truncateIntegralFields(finalEvent);
8840
8948
  this.emitEvents([finalEvent], event.correlationId);
8841
8949
  return finalEvent;
8842
8950
  }
@@ -8845,7 +8953,7 @@
8845
8953
  * @param fields
8846
8954
  * @param correlationId
8847
8955
  */
8848
- addStaticFields(fields, correlationId) {
8956
+ addFields(fields, correlationId) {
8849
8957
  this.logger.trace("PerformanceClient: Updating static fields");
8850
8958
  const event = this.eventsByCorrelationId.get(correlationId);
8851
8959
  if (event) {
@@ -8860,18 +8968,21 @@
8860
8968
  }
8861
8969
  /**
8862
8970
  * Increment counters to be emitted when the measurements are flushed
8863
- * @param counters {Counters}
8971
+ * @param fields {string[]}
8864
8972
  * @param correlationId {string} correlation identifier
8865
8973
  */
8866
- increment(counters, correlationId) {
8974
+ incrementFields(fields, correlationId) {
8867
8975
  this.logger.trace("PerformanceClient: Updating counters");
8868
8976
  const event = this.eventsByCorrelationId.get(correlationId);
8869
8977
  if (event) {
8870
- for (const counter in counters) {
8978
+ for (const counter in fields) {
8871
8979
  if (!event.hasOwnProperty(counter)) {
8872
8980
  event[counter] = 0;
8873
8981
  }
8874
- event[counter] += counters[counter];
8982
+ else if (isNaN(Number(event[counter]))) {
8983
+ return;
8984
+ }
8985
+ event[counter] += fields[counter];
8875
8986
  }
8876
8987
  }
8877
8988
  else {
@@ -8989,8 +9100,8 @@
8989
9100
  * @param {PerformanceEvent} event performance event to update.
8990
9101
  * @param {Set<string>} intFields integral fields.
8991
9102
  */
8992
- truncateIntegralFields(event, intFields) {
8993
- intFields.forEach((key) => {
9103
+ truncateIntegralFields(event) {
9104
+ this.intFields.forEach((key) => {
8994
9105
  if (key in event && typeof event[key] === "number") {
8995
9106
  event[key] = Math.floor(event[key]);
8996
9107
  }
@@ -8998,16 +9109,22 @@
8998
9109
  }
8999
9110
  }
9000
9111
 
9001
- /*! @azure/msal-common v14.0.0-beta.0 2023-06-19 */
9112
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
9002
9113
 
9003
9114
  /*
9004
9115
  * Copyright (c) Microsoft Corporation. All rights reserved.
9005
9116
  * Licensed under the MIT License.
9006
9117
  */
9007
9118
  class StubPerformanceMeasurement {
9008
- startMeasurement() { return; }
9009
- endMeasurement() { return; }
9010
- flushMeasurement() { return null; }
9119
+ startMeasurement() {
9120
+ return;
9121
+ }
9122
+ endMeasurement() {
9123
+ return;
9124
+ }
9125
+ flushMeasurement() {
9126
+ return null;
9127
+ }
9011
9128
  }
9012
9129
  class StubPerformanceClient extends PerformanceClient {
9013
9130
  generateId() {
@@ -9019,8 +9136,36 @@
9019
9136
  calculateQueuedTime() {
9020
9137
  return 0;
9021
9138
  }
9022
- addQueueMeasurement() { return; }
9023
- setPreQueueTime() { return; }
9139
+ addQueueMeasurement() {
9140
+ return;
9141
+ }
9142
+ setPreQueueTime() {
9143
+ return;
9144
+ }
9145
+ endMeasurement() {
9146
+ return null;
9147
+ }
9148
+ discardMeasurements() {
9149
+ return;
9150
+ }
9151
+ removePerformanceCallback() {
9152
+ return true;
9153
+ }
9154
+ addPerformanceCallback() {
9155
+ return "";
9156
+ }
9157
+ emitEvents() {
9158
+ return;
9159
+ }
9160
+ addFields() {
9161
+ return;
9162
+ }
9163
+ incrementFields() {
9164
+ return;
9165
+ }
9166
+ cacheEventByCorrelationId() {
9167
+ return;
9168
+ }
9024
9169
  }
9025
9170
 
9026
9171
  /*
@@ -9203,9 +9348,9 @@
9203
9348
  code: "native_connection_not_established",
9204
9349
  desc: "Connection to native platform has not been established. Please install a compatible browser extension and run initialize(). For more please visit aka.ms/msaljs/browser-errors.",
9205
9350
  },
9206
- nativeBrokerCalledBeforeInitialize: {
9207
- code: "native_broker_called_before_initialize",
9208
- desc: "You must call and await the initialize function before attempting to call any other MSAL API when native brokering is enabled. For more please visit aka.ms/msaljs/browser-errors.",
9351
+ uninitializedPublicClientApplication: {
9352
+ code: "uninitialized_public_client_application",
9353
+ desc: "You must call and await the initialize function before attempting to call any other MSAL API. For more please visit aka.ms/msaljs/browser-errors.",
9209
9354
  },
9210
9355
  nativePromptNotSupported: {
9211
9356
  code: "native_prompt_not_supported",
@@ -9495,8 +9640,8 @@
9495
9640
  /**
9496
9641
  * Create an error thrown when the initialize function hasn't been called
9497
9642
  */
9498
- static createNativeBrokerCalledBeforeInitialize() {
9499
- return new BrowserAuthError(BrowserAuthErrorMessage.nativeBrokerCalledBeforeInitialize.code, BrowserAuthErrorMessage.nativeBrokerCalledBeforeInitialize.desc);
9643
+ static createUninitializedPublicClientApplication() {
9644
+ return new BrowserAuthError(BrowserAuthErrorMessage.uninitializedPublicClientApplication.code, BrowserAuthErrorMessage.uninitializedPublicClientApplication.desc);
9500
9645
  }
9501
9646
  /**
9502
9647
  * Create an error thrown when requesting a token directly from the native platform with an unsupported prompt parameter e.g. select_account, login or create
@@ -11177,6 +11322,23 @@
11177
11322
  setRedirectRequestContext(value) {
11178
11323
  this.setTemporaryCache(TemporaryCacheKeys.REDIRECT_CONTEXT, value, true);
11179
11324
  }
11325
+ /**
11326
+ * Builds credential entities from AuthenticationResult object and saves the resulting credentials to the cache
11327
+ * @param result
11328
+ * @param request
11329
+ */
11330
+ async hydrateCache(result, request) {
11331
+ const idTokenEntity = IdTokenEntity.createIdTokenEntity(result.account?.homeAccountId, result.account?.environment, result.idToken, this.clientId, result.tenantId);
11332
+ let claimsHash;
11333
+ if (request.claims) {
11334
+ claimsHash = await this.cryptoImpl.hashString(request.claims);
11335
+ }
11336
+ const accessTokenEntity = AccessTokenEntity.createAccessTokenEntity(result.account?.homeAccountId, result.account.environment, result.accessToken, this.clientId, result.tenantId, result.scopes.join(" "), result.expiresOn?.getTime() || 0, result.extExpiresOn?.getTime() || 0, this.cryptoImpl, undefined, // refreshOn
11337
+ result.tokenType, undefined, // userAssertionHash
11338
+ request.sshKid, request.claims, claimsHash);
11339
+ const cacheRecord = new CacheRecord(undefined, idTokenEntity, accessTokenEntity);
11340
+ return this.saveCacheRecord(cacheRecord);
11341
+ }
11180
11342
  }
11181
11343
  const DEFAULT_BROWSER_CACHE_MANAGER = (clientId, logger) => {
11182
11344
  const cacheOptions = {
@@ -11185,13 +11347,14 @@
11185
11347
  storeAuthStateInCookie: false,
11186
11348
  secureCookies: false,
11187
11349
  cacheMigrationEnabled: false,
11350
+ claimsBasedCachingEnabled: false,
11188
11351
  };
11189
11352
  return new BrowserCacheManager(clientId, cacheOptions, DEFAULT_CRYPTO_IMPLEMENTATION, logger);
11190
11353
  };
11191
11354
 
11192
11355
  /* eslint-disable header/header */
11193
11356
  const name = "@azure/msal-browser";
11194
- const version = "3.0.0-beta.0";
11357
+ const version = "3.0.0";
11195
11358
 
11196
11359
  /*
11197
11360
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -11527,13 +11690,12 @@
11527
11690
  }
11528
11691
  }
11529
11692
  /**
11530
- * Throws error if native brokering is enabled but initialize hasn't been called
11531
- * @param allowNativeBroker
11693
+ * Throws error if initialize hasn't been called
11532
11694
  * @param initialized
11533
11695
  */
11534
- static blockNativeBrokerCalledBeforeInitialized(allowNativeBroker, initialized) {
11535
- if (allowNativeBroker && !initialized) {
11536
- throw BrowserAuthError.createNativeBrokerCalledBeforeInitialize();
11696
+ static blockAPICallsBeforeInitialize(initialized) {
11697
+ if (!initialized) {
11698
+ throw BrowserAuthError.createUninitializedPublicClientApplication();
11537
11699
  }
11538
11700
  }
11539
11701
  /**
@@ -11631,8 +11793,11 @@
11631
11793
  }
11632
11794
  this.logger.verbose(`Authentication Scheme set to "${validatedRequest.authenticationScheme}" as configured in Auth request`);
11633
11795
  }
11634
- // Set requested claims hash if claims were requested
11635
- if (request.claims && !StringUtils.isEmpty(request.claims)) {
11796
+ // Set requested claims hash if claims-based caching is enabled and claims were requested
11797
+ if (this.config.cache.claimsBasedCachingEnabled &&
11798
+ request.claims &&
11799
+ // Checks for empty stringified object "{}" which doesn't qualify as requested claims
11800
+ !StringUtils.isEmptyObj(request.claims)) {
11636
11801
  validatedRequest.requestedClaimsHash =
11637
11802
  await this.browserCrypto.hashString(request.claims);
11638
11803
  }
@@ -11689,6 +11854,7 @@
11689
11854
  this.logger.verbose("getDiscoveredAuthority called");
11690
11855
  const authorityOptions = {
11691
11856
  protocolMode: this.config.auth.protocolMode,
11857
+ OIDCOptions: this.config.auth.OIDCOptions,
11692
11858
  knownAuthorities: this.config.auth.knownAuthorities,
11693
11859
  cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
11694
11860
  authorityMetadata: this.config.auth.authorityMetadata,
@@ -11852,6 +12018,9 @@
11852
12018
  logLevel: logger.logLevel,
11853
12019
  correlationId: this.correlationId,
11854
12020
  },
12021
+ cacheOptions: {
12022
+ claimsBasedCachingEnabled: this.config.cache.claimsBasedCachingEnabled,
12023
+ },
11855
12024
  cryptoInterface: this.browserCrypto,
11856
12025
  networkInterface: this.networkClient,
11857
12026
  storageInterface: this.browserStorage,
@@ -11895,6 +12064,7 @@
11895
12064
  const getAuthorityMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority, this.correlationId);
11896
12065
  const authorityOptions = {
11897
12066
  protocolMode: this.config.auth.protocolMode,
12067
+ OIDCOptions: this.config.auth.OIDCOptions,
11898
12068
  knownAuthorities: this.config.auth.knownAuthorities,
11899
12069
  cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
11900
12070
  authorityMetadata: this.config.auth.authorityMetadata,
@@ -11910,13 +12080,13 @@
11910
12080
  this.performanceClient.setPreQueueTime(PerformanceEvents.AuthorityFactoryCreateDiscoveredInstance, this.correlationId);
11911
12081
  return await AuthorityFactory.createDiscoveredInstance(builtAuthority, this.config.system.networkClient, this.browserStorage, authorityOptions, this.logger, this.performanceClient, this.correlationId)
11912
12082
  .then((result) => {
11913
- getAuthorityMeasurement.endMeasurement({
12083
+ getAuthorityMeasurement.end({
11914
12084
  success: true,
11915
12085
  });
11916
12086
  return result;
11917
12087
  })
11918
12088
  .catch((error) => {
11919
- getAuthorityMeasurement.endMeasurement({
12089
+ getAuthorityMeasurement.end({
11920
12090
  errorCode: error.errorCode,
11921
12091
  subErrorCode: error.subError,
11922
12092
  success: false,
@@ -11943,7 +12113,8 @@
11943
12113
  redirectUri: redirectUri,
11944
12114
  state: state,
11945
12115
  nonce: request.nonce || this.browserCrypto.createNewGuid(),
11946
- responseMode: ResponseMode.FRAGMENT,
12116
+ responseMode: this.config.auth.OIDCOptions
12117
+ .serverResponseType,
11947
12118
  };
11948
12119
  const account = request.account || this.browserStorage.getActiveAccount();
11949
12120
  if (account) {
@@ -12055,7 +12226,7 @@
12055
12226
  }
12056
12227
  // Acquire token with retrieved code.
12057
12228
  this.performanceClient.setPreQueueTime(PerformanceEvents.AuthClientAcquireToken, this.authCodeRequest.correlationId);
12058
- const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse);
12229
+ const tokenResponse = (await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse));
12059
12230
  this.browserStorage.cleanRequestByState(state);
12060
12231
  return tokenResponse;
12061
12232
  }
@@ -12203,7 +12374,7 @@
12203
12374
  }
12204
12375
  }
12205
12376
  // Acquire token with retrieved code.
12206
- const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse);
12377
+ const tokenResponse = (await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse));
12207
12378
  this.browserStorage.cleanRequestByState(state);
12208
12379
  return tokenResponse;
12209
12380
  }
@@ -12238,7 +12409,7 @@
12238
12409
  LOGOUT_SUCCESS: "msal:logoutSuccess",
12239
12410
  LOGOUT_FAILURE: "msal:logoutFailure",
12240
12411
  LOGOUT_END: "msal:logoutEnd",
12241
- RESTORE_FROM_BFCACHE: "msal:restoreFromBFCache"
12412
+ RESTORE_FROM_BFCACHE: "msal:restoreFromBFCache",
12242
12413
  };
12243
12414
 
12244
12415
  /*
@@ -12351,8 +12522,8 @@
12351
12522
  const silentAuthClient = await this.createSilentFlowClient(serverTelemetryManager, silentRequest.authority, silentRequest.azureCloudOptions);
12352
12523
  this.logger.verbose("Silent auth client created");
12353
12524
  try {
12354
- const cachedToken = await silentAuthClient.acquireCachedToken(silentRequest);
12355
- acquireTokenMeasurement.endMeasurement({
12525
+ const cachedToken = (await silentAuthClient.acquireCachedToken(silentRequest));
12526
+ acquireTokenMeasurement.end({
12356
12527
  success: true,
12357
12528
  fromCache: true,
12358
12529
  });
@@ -12364,7 +12535,7 @@
12364
12535
  BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code) {
12365
12536
  this.logger.verbose("Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.");
12366
12537
  }
12367
- acquireTokenMeasurement.endMeasurement({
12538
+ acquireTokenMeasurement.end({
12368
12539
  errorCode: (error instanceof AuthError && error.errorCode) ||
12369
12540
  undefined,
12370
12541
  subErrorCode: (error instanceof AuthError && error.subError) || undefined,
@@ -12396,7 +12567,7 @@
12396
12567
  this.performanceClient.setPreQueueTime(PerformanceEvents.InitializeBaseRequest, this.correlationId);
12397
12568
  return {
12398
12569
  ...request,
12399
- ...await this.initializeBaseRequest(request, account),
12570
+ ...(await this.initializeBaseRequest(request, account)),
12400
12571
  account: account,
12401
12572
  forceRefresh: request.forceRefresh || false,
12402
12573
  };
@@ -12430,7 +12601,7 @@
12430
12601
  // check if the tokens can be retrieved from internal cache
12431
12602
  try {
12432
12603
  const result = await this.acquireTokensFromCache(this.accountId, nativeRequest);
12433
- nativeATMeasurement.endMeasurement({
12604
+ nativeATMeasurement.end({
12434
12605
  success: true,
12435
12606
  isNativeBroker: false,
12436
12607
  fromCache: true,
@@ -12450,7 +12621,7 @@
12450
12621
  const validatedResponse = this.validateNativeResponse(response);
12451
12622
  return this.handleNativeResponse(validatedResponse, nativeRequest, reqTimestamp)
12452
12623
  .then((result) => {
12453
- nativeATMeasurement.endMeasurement({
12624
+ nativeATMeasurement.end({
12454
12625
  success: true,
12455
12626
  isNativeBroker: true,
12456
12627
  requestId: result.requestId,
@@ -12458,7 +12629,7 @@
12458
12629
  return result;
12459
12630
  })
12460
12631
  .catch((error) => {
12461
- nativeATMeasurement.endMeasurement({
12632
+ nativeATMeasurement.end({
12462
12633
  success: false,
12463
12634
  errorCode: error.errorCode,
12464
12635
  subErrorCode: error.subError,
@@ -12504,7 +12675,10 @@
12504
12675
  try {
12505
12676
  const silentRequest = this.createSilentCacheRequest(request, account);
12506
12677
  const result = await this.silentCacheClient.acquireToken(silentRequest);
12507
- return result;
12678
+ return {
12679
+ ...result,
12680
+ account,
12681
+ };
12508
12682
  }
12509
12683
  catch (e) {
12510
12684
  throw e;
@@ -12602,16 +12776,20 @@
12602
12776
  }
12603
12777
  // Get the preferred_cache domain for the given authority
12604
12778
  const authority = await this.getDiscoveredAuthority(request.authority);
12605
- const authorityPreferredCache = authority.getPreferredCache();
12606
12779
  // generate identifiers
12607
12780
  const idTokenObj = this.createIdTokenObj(response);
12608
12781
  const homeAccountIdentifier = this.createHomeAccountIdentifier(response, idTokenObj);
12609
- const accountEntity = this.createAccountEntity(response, homeAccountIdentifier, idTokenObj, authorityPreferredCache);
12782
+ const accountEntity = AccountEntity.createAccount({
12783
+ homeAccountId: homeAccountIdentifier,
12784
+ idTokenClaims: idTokenObj.claims,
12785
+ clientInfo: response.client_info,
12786
+ nativeAccountId: response.account.id,
12787
+ }, authority);
12610
12788
  // generate authenticationResult
12611
12789
  const result = await this.generateAuthenticationResult(response, request, idTokenObj, accountEntity, authority.canonicalAuthority, reqTimestamp);
12612
12790
  // cache accounts and tokens in the appropriate storage
12613
12791
  this.cacheAccount(accountEntity);
12614
- this.cacheNativeTokens(response, request, homeAccountIdentifier, accountEntity, idTokenObj, result.accessToken, result.tenantId, reqTimestamp);
12792
+ this.cacheNativeTokens(response, request, homeAccountIdentifier, idTokenObj, result.accessToken, result.tenantId, reqTimestamp);
12615
12793
  return result;
12616
12794
  }
12617
12795
  /**
@@ -12630,20 +12808,9 @@
12630
12808
  */
12631
12809
  createHomeAccountIdentifier(response, idTokenObj) {
12632
12810
  // Save account in browser storage
12633
- const homeAccountIdentifier = AccountEntity.generateHomeAccountId(response.client_info || Constants.EMPTY_STRING, AuthorityType.Default, this.logger, this.browserCrypto, idTokenObj);
12811
+ const homeAccountIdentifier = AccountEntity.generateHomeAccountId(response.client_info || Constants.EMPTY_STRING, AuthorityType.Default, this.logger, this.browserCrypto, idTokenObj.claims);
12634
12812
  return homeAccountIdentifier;
12635
12813
  }
12636
- /**
12637
- * Creates account entity
12638
- * @param response
12639
- * @param homeAccountIdentifier
12640
- * @param idTokenObj
12641
- * @param authority
12642
- * @returns
12643
- */
12644
- createAccountEntity(response, homeAccountIdentifier, idTokenObj, authority) {
12645
- return AccountEntity.createAccount(response.client_info, homeAccountIdentifier, idTokenObj, undefined, undefined, undefined, authority, response.account.id);
12646
- }
12647
12814
  /**
12648
12815
  * Helper to generate scopes
12649
12816
  * @param response
@@ -12762,7 +12929,7 @@
12762
12929
  * @param tenantId
12763
12930
  * @param reqTimestamp
12764
12931
  */
12765
- cacheNativeTokens(response, request, homeAccountIdentifier, accountEntity, idTokenObj, responseAccessToken, tenantId, reqTimestamp) {
12932
+ cacheNativeTokens(response, request, homeAccountIdentifier, idTokenObj, responseAccessToken, tenantId, reqTimestamp) {
12766
12933
  const cachedIdToken = IdTokenEntity.createIdTokenEntity(homeAccountIdentifier, request.authority, response.id_token || Constants.EMPTY_STRING, request.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
12767
12934
  // cache accessToken in inmemory storage
12768
12935
  const expiresIn = request.tokenType === AuthenticationScheme.POP
@@ -12775,15 +12942,15 @@
12775
12942
  const cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(homeAccountIdentifier, request.authority, responseAccessToken, request.clientId, idTokenObj
12776
12943
  ? idTokenObj.claims.tid || Constants.EMPTY_STRING
12777
12944
  : tenantId, responseScopes.printScopes(), tokenExpirationSeconds, 0, this.browserCrypto);
12778
- const nativeCacheRecord = new CacheRecord(accountEntity, cachedIdToken, cachedAccessToken);
12779
- this.nativeStorageManager.saveCacheRecord(nativeCacheRecord);
12945
+ const nativeCacheRecord = new CacheRecord(undefined, cachedIdToken, cachedAccessToken);
12946
+ this.nativeStorageManager.saveCacheRecord(nativeCacheRecord, request.storeInCache);
12780
12947
  }
12781
12948
  addTelemetryFromNativeResponse(response) {
12782
12949
  const mats = this.getMATSFromResponse(response);
12783
12950
  if (!mats) {
12784
12951
  return null;
12785
12952
  }
12786
- this.performanceClient.addStaticFields({
12953
+ this.performanceClient.addFields({
12787
12954
  extensionId: this.nativeMessageHandler.getExtensionId(),
12788
12955
  extensionVersion: this.nativeMessageHandler.getExtensionVersion(),
12789
12956
  matsBrokerVersion: mats.broker_version,
@@ -12996,7 +13163,7 @@
12996
13163
  method: NativeExtensionMethod.HandshakeRequest,
12997
13164
  },
12998
13165
  };
12999
- this.handshakeEvent.addStaticFields({
13166
+ this.handshakeEvent.add({
13000
13167
  extensionId: this.extensionId,
13001
13168
  extensionHandshakeTimeoutMs: this.handshakeTimeoutMs,
13002
13169
  });
@@ -13014,7 +13181,7 @@
13014
13181
  window.removeEventListener("message", this.windowListener, false);
13015
13182
  this.messageChannel.port1.close();
13016
13183
  this.messageChannel.port2.close();
13017
- this.handshakeEvent.endMeasurement({
13184
+ this.handshakeEvent.end({
13018
13185
  extensionHandshakeTimedOut: true,
13019
13186
  success: false,
13020
13187
  });
@@ -13059,7 +13226,7 @@
13059
13226
  this.messageChannel.port1.close();
13060
13227
  this.messageChannel.port2.close();
13061
13228
  window.removeEventListener("message", this.windowListener, false);
13062
- this.handshakeEvent.endMeasurement({
13229
+ this.handshakeEvent.end({
13063
13230
  success: false,
13064
13231
  extensionInstalled: false,
13065
13232
  });
@@ -13111,7 +13278,7 @@
13111
13278
  this.extensionId = request.extensionId;
13112
13279
  this.extensionVersion = request.body.version;
13113
13280
  this.logger.verbose(`NativeMessageHandler - Received HandshakeResponse from extension: ${this.extensionId}`);
13114
- this.handshakeEvent.endMeasurement({
13281
+ this.handshakeEvent.end({
13115
13282
  extensionInstalled: true,
13116
13283
  success: true,
13117
13284
  });
@@ -13420,6 +13587,18 @@
13420
13587
  this.performanceClient.setPreQueueTime(PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, validLogoutRequest.correlationId);
13421
13588
  const authClient = await this.createAuthCodeClient(serverTelemetryManager, logoutRequest && logoutRequest.authority);
13422
13589
  this.logger.verbose("Auth code client created");
13590
+ if (authClient.authority.protocolMode === ProtocolMode.OIDC) {
13591
+ try {
13592
+ authClient.authority.endSessionEndpoint;
13593
+ }
13594
+ catch {
13595
+ if (validLogoutRequest.account?.homeAccountId) {
13596
+ this.browserStorage.removeAccount(validLogoutRequest.account?.homeAccountId);
13597
+ this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, exports.InteractionType.Redirect, validLogoutRequest);
13598
+ return;
13599
+ }
13600
+ }
13601
+ }
13423
13602
  // Create logout string and navigate user window to logout.
13424
13603
  const logoutUri = authClient.getLogoutUri(validLogoutRequest);
13425
13604
  this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, exports.InteractionType.Redirect, validLogoutRequest);
@@ -13594,7 +13773,7 @@
13594
13773
  this.logger.verbose("Account id found in hash, calling WAM for token");
13595
13774
  // end measurement for server call with native brokering enabled
13596
13775
  if (fetchNativeAccountIdMeasurement) {
13597
- fetchNativeAccountIdMeasurement.endMeasurement({
13776
+ fetchNativeAccountIdMeasurement.end({
13598
13777
  success: true,
13599
13778
  isNativeBroker: true,
13600
13779
  });
@@ -13651,6 +13830,30 @@
13651
13830
  this.performanceClient.setPreQueueTime(PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, validRequest.correlationId);
13652
13831
  const authClient = await this.createAuthCodeClient(serverTelemetryManager, requestAuthority);
13653
13832
  this.logger.verbose("Auth code client created");
13833
+ try {
13834
+ authClient.authority.endSessionEndpoint;
13835
+ }
13836
+ catch {
13837
+ if (validRequest.account?.homeAccountId &&
13838
+ validRequest.postLogoutRedirectUri &&
13839
+ authClient.authority.protocolMode === ProtocolMode.OIDC) {
13840
+ this.browserStorage.removeAccount(validRequest.account?.homeAccountId);
13841
+ this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, exports.InteractionType.Popup, validRequest);
13842
+ if (mainWindowRedirectUri) {
13843
+ const navigationOptions = {
13844
+ apiId: ApiId.logoutPopup,
13845
+ timeout: this.config.system.redirectNavigationTimeout,
13846
+ noHistory: false,
13847
+ };
13848
+ const absoluteUrl = UrlString.getAbsoluteUrl(mainWindowRedirectUri, BrowserUtils.getCurrentUri());
13849
+ await this.navigationClient.navigateInternal(absoluteUrl, navigationOptions);
13850
+ }
13851
+ if (popup) {
13852
+ popup.close();
13853
+ }
13854
+ return;
13855
+ }
13856
+ }
13654
13857
  // Create logout string and navigate user window to logout.
13655
13858
  const logoutUri = authClient.getLogoutUri(validRequest);
13656
13859
  this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, exports.InteractionType.Popup, validRequest);
@@ -13735,7 +13938,7 @@
13735
13938
  return;
13736
13939
  }
13737
13940
  let href = Constants.EMPTY_STRING;
13738
- let hash = Constants.EMPTY_STRING;
13941
+ let serverResponseString = Constants.EMPTY_STRING;
13739
13942
  try {
13740
13943
  /*
13741
13944
  * Will throw if cross origin,
@@ -13743,7 +13946,8 @@
13743
13946
  * since we need the interval to keep running while on STS UI.
13744
13947
  */
13745
13948
  href = popupWindow.location.href;
13746
- hash = popupWindow.location.hash;
13949
+ serverResponseString =
13950
+ this.extractServerResponseStringFromPopup(popupWindow, href);
13747
13951
  }
13748
13952
  catch (e) { }
13749
13953
  // Don't process blank pages or cross domain
@@ -13756,17 +13960,17 @@
13756
13960
  * as popup operations can take a long time.
13757
13961
  */
13758
13962
  ticks++;
13759
- if (hash) {
13963
+ if (serverResponseString) {
13760
13964
  this.logger.verbose("PopupHandler.monitorPopupForHash - found hash in url");
13761
13965
  clearInterval(intervalId);
13762
13966
  this.cleanPopup(popupWindow);
13763
- if (UrlString.hashContainsKnownProperties(hash)) {
13967
+ if (UrlString.hashContainsKnownProperties(serverResponseString)) {
13764
13968
  this.logger.verbose("PopupHandler.monitorPopupForHash - hash contains known properties, returning.");
13765
- resolve(hash);
13969
+ resolve(serverResponseString);
13766
13970
  }
13767
13971
  else {
13768
13972
  this.logger.error("PopupHandler.monitorPopupForHash - found hash in url but it does not contain known properties. Check that your router is not changing the hash prematurely.");
13769
- this.logger.errorPii(`PopupHandler.monitorPopupForHash - hash found: ${hash}`);
13973
+ this.logger.errorPii(`PopupHandler.monitorPopupForHash - hash found: ${serverResponseString}`);
13770
13974
  reject(BrowserAuthError.createHashDoesNotContainKnownPropertiesError());
13771
13975
  }
13772
13976
  }
@@ -13947,6 +14151,20 @@
13947
14151
  const homeAccountId = request.account && request.account.homeAccountId;
13948
14152
  return `${BrowserConstants.POPUP_NAME_PREFIX}.${this.config.auth.clientId}.${homeAccountId}.${this.correlationId}`;
13949
14153
  }
14154
+ /**
14155
+ * Extracts the server response from the popup window
14156
+ */
14157
+ extractServerResponseStringFromPopup(popupWindow, href) {
14158
+ let serverResponseString;
14159
+ if (this.config.auth.OIDCOptions?.serverResponseType ===
14160
+ ServerResponseType.QUERY) {
14161
+ serverResponseString = UrlString.parseQueryServerResponse(href);
14162
+ }
14163
+ else {
14164
+ serverResponseString = popupWindow.location.hash;
14165
+ }
14166
+ return serverResponseString;
14167
+ }
13950
14168
  }
13951
14169
 
13952
14170
  /*
@@ -14021,6 +14239,14 @@
14021
14239
  navigateToLoginRequestUrl: true,
14022
14240
  clientCapabilities: [],
14023
14241
  protocolMode: ProtocolMode.AAD,
14242
+ OIDCOptions: {
14243
+ serverResponseType: ServerResponseType.FRAGMENT,
14244
+ defaultScopes: [
14245
+ Constants.OPENID_SCOPE,
14246
+ Constants.PROFILE_SCOPE,
14247
+ Constants.OFFLINE_ACCESS_SCOPE,
14248
+ ],
14249
+ },
14024
14250
  azureCloudOptions: {
14025
14251
  azureCloudInstance: AzureCloudInstance.None,
14026
14252
  tenant: Constants.EMPTY_STRING,
@@ -14038,6 +14264,7 @@
14038
14264
  userInputCache.cacheLocation === BrowserCacheLocation.LocalStorage
14039
14265
  ? true
14040
14266
  : false,
14267
+ claimsBasedCachingEnabled: false,
14041
14268
  };
14042
14269
  // Default logger options for browser
14043
14270
  const DEFAULT_LOGGER_OPTIONS = {
@@ -14064,10 +14291,10 @@
14064
14291
  redirectNavigationTimeout: DEFAULT_REDIRECT_TIMEOUT_MS,
14065
14292
  asyncPopups: false,
14066
14293
  allowRedirectInIframe: false,
14067
- allowNativeBroker: true,
14294
+ allowNativeBroker: false,
14068
14295
  nativeBrokerHandshakeTimeout: userInputSystem?.nativeBrokerHandshakeTimeout ||
14069
14296
  DEFAULT_NATIVE_BROKER_HANDSHAKE_TIMEOUT_MS,
14070
- pollIntervalMilliseconds: BrowserConstants.DEFAULT_POLL_INTERVAL_MS
14297
+ pollIntervalMilliseconds: BrowserConstants.DEFAULT_POLL_INTERVAL_MS,
14071
14298
  };
14072
14299
  const providedSystemOptions = {
14073
14300
  ...userInputSystem,
@@ -14078,9 +14305,33 @@
14078
14305
  appName: Constants.EMPTY_STRING,
14079
14306
  appVersion: Constants.EMPTY_STRING,
14080
14307
  },
14308
+ client: new StubPerformanceClient(DEFAULT_AUTH_OPTIONS.clientId, DEFAULT_AUTH_OPTIONS.authority, new Logger(DEFAULT_LOGGER_OPTIONS, name, version), name, version, {
14309
+ appName: Constants.EMPTY_STRING,
14310
+ appVersion: Constants.EMPTY_STRING,
14311
+ }),
14081
14312
  };
14313
+ // Throw an error if user has set OIDCOptions without being in OIDC protocol mode
14314
+ if (userInputAuth?.protocolMode !== ProtocolMode.OIDC &&
14315
+ userInputAuth?.OIDCOptions) {
14316
+ // Logger has not been created yet
14317
+ // eslint-disable-next-line no-console
14318
+ console.warn(ClientConfigurationError.createCannotSetOIDCOptionsError());
14319
+ }
14320
+ // Throw an error if user has set allowNativeBroker to true without being in AAD protocol mode
14321
+ if (userInputAuth?.protocolMode &&
14322
+ userInputAuth.protocolMode !== ProtocolMode.AAD &&
14323
+ providedSystemOptions?.allowNativeBroker) {
14324
+ throw ClientConfigurationError.createCannotAllowNativeBrokerError();
14325
+ }
14082
14326
  const overlayedConfig = {
14083
- auth: { ...DEFAULT_AUTH_OPTIONS, ...userInputAuth },
14327
+ auth: {
14328
+ ...DEFAULT_AUTH_OPTIONS,
14329
+ ...userInputAuth,
14330
+ OIDCOptions: {
14331
+ ...DEFAULT_AUTH_OPTIONS.OIDCOptions,
14332
+ ...userInputAuth?.OIDCOptions,
14333
+ },
14334
+ },
14084
14335
  cache: { ...DEFAULT_CACHE_OPTIONS, ...userInputCache },
14085
14336
  system: { ...DEFAULT_BROWSER_SYSTEM_OPTIONS, ...providedSystemOptions },
14086
14337
  telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...userInputTelemetry },
@@ -14279,7 +14530,7 @@
14279
14530
  if (request.prompt &&
14280
14531
  request.prompt !== PromptValue.NONE &&
14281
14532
  request.prompt !== PromptValue.NO_SESSION) {
14282
- acquireTokenMeasurement.endMeasurement({
14533
+ acquireTokenMeasurement.end({
14283
14534
  success: false,
14284
14535
  });
14285
14536
  throw BrowserAuthError.createSilentPromptValueError(request.prompt);
@@ -14299,7 +14550,7 @@
14299
14550
  this.logger.verbose("Auth code client created");
14300
14551
  this.performanceClient.setPreQueueTime(PerformanceEvents.SilentIframeClientTokenHelper, request.correlationId);
14301
14552
  return await this.silentTokenHelper(authClient, silentRequest).then((result) => {
14302
- acquireTokenMeasurement.endMeasurement({
14553
+ acquireTokenMeasurement.end({
14303
14554
  success: true,
14304
14555
  fromCache: false,
14305
14556
  requestId: result.requestId,
@@ -14313,7 +14564,7 @@
14313
14564
  serverTelemetryManager.cacheFailedRequest(e);
14314
14565
  }
14315
14566
  this.browserStorage.cleanRequestByState(silentRequest.state);
14316
- acquireTokenMeasurement.endMeasurement({
14567
+ acquireTokenMeasurement.end({
14317
14568
  errorCode: (e instanceof AuthError && e.errorCode) || undefined,
14318
14569
  subErrorCode: (e instanceof AuthError && e.subError) || undefined,
14319
14570
  success: false,
@@ -14393,7 +14644,7 @@
14393
14644
  this.performanceClient.setPreQueueTime(PerformanceEvents.InitializeBaseRequest, request.correlationId);
14394
14645
  const silentRequest = {
14395
14646
  ...request,
14396
- ...await this.initializeBaseRequest(request, request.account)
14647
+ ...(await this.initializeBaseRequest(request, request.account)),
14397
14648
  };
14398
14649
  const acquireTokenMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SilentRefreshClientAcquireToken, silentRequest.correlationId);
14399
14650
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);
@@ -14403,8 +14654,9 @@
14403
14654
  this.performanceClient.setPreQueueTime(PerformanceEvents.RefreshTokenClientAcquireTokenByRefreshToken, request.correlationId);
14404
14655
  return refreshTokenClient
14405
14656
  .acquireTokenByRefreshToken(silentRequest)
14657
+ .then((result) => result)
14406
14658
  .then((result) => {
14407
- acquireTokenMeasurement.endMeasurement({
14659
+ acquireTokenMeasurement.end({
14408
14660
  success: true,
14409
14661
  fromCache: result.fromCache,
14410
14662
  requestId: result.requestId,
@@ -14414,7 +14666,7 @@
14414
14666
  .catch((e) => {
14415
14667
  e.setCorrelationId(this.correlationId);
14416
14668
  serverTelemetryManager.cacheFailedRequest(e);
14417
- acquireTokenMeasurement.endMeasurement({
14669
+ acquireTokenMeasurement.end({
14418
14670
  errorCode: e.errorCode,
14419
14671
  subErrorCode: e.subError,
14420
14672
  success: false,
@@ -14760,18 +15012,6 @@
14760
15012
  }
14761
15013
  return aBytes;
14762
15014
  }
14763
- /**
14764
- * Converst string to ArrayBuffer
14765
- * @param dataString
14766
- */
14767
- static stringToArrayBuffer(dataString) {
14768
- const data = new ArrayBuffer(dataString.length);
14769
- const dataView = new Uint8Array(data);
14770
- for (let i = 0; i < dataString.length; i++) {
14771
- dataView[i] = dataString.charCodeAt(i);
14772
- }
14773
- return data;
14774
- }
14775
15015
  /**
14776
15016
  * Converts Uint8Array to a string
14777
15017
  * @param aBytes
@@ -15604,7 +15844,7 @@
15604
15844
  requestUri: request.resourceRequestUri,
15605
15845
  });
15606
15846
  if (publicKeyThumbMeasurement) {
15607
- publicKeyThumbMeasurement.endMeasurement({
15847
+ publicKeyThumbMeasurement.end({
15608
15848
  success: true,
15609
15849
  });
15610
15850
  }
@@ -15655,12 +15895,12 @@
15655
15895
  // Form token string
15656
15896
  const tokenString = `${encodedShrHeader}.${encodedPayload}`;
15657
15897
  // Sign token
15658
- const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);
15898
+ const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
15659
15899
  const signatureBuffer = await this.browserCrypto.sign(cachedKeyPair.privateKey, tokenBuffer);
15660
15900
  const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));
15661
15901
  const signedJwt = `${tokenString}.${encodedSignature}`;
15662
15902
  if (signJwtMeasurement) {
15663
- signJwtMeasurement.endMeasurement({
15903
+ signJwtMeasurement.end({
15664
15904
  success: true,
15665
15905
  });
15666
15906
  }
@@ -15683,231 +15923,17 @@
15683
15923
  * Copyright (c) Microsoft Corporation. All rights reserved.
15684
15924
  * Licensed under the MIT License.
15685
15925
  */
15686
- class BrowserPerformanceMeasurement {
15687
- constructor(name, correlationId) {
15688
- this.correlationId = correlationId;
15689
- this.measureName = BrowserPerformanceMeasurement.makeMeasureName(name, correlationId);
15690
- this.startMark = BrowserPerformanceMeasurement.makeStartMark(name, correlationId);
15691
- this.endMark = BrowserPerformanceMeasurement.makeEndMark(name, correlationId);
15692
- }
15693
- static makeMeasureName(name, correlationId) {
15694
- return `msal.measure.${name}.${correlationId}`;
15695
- }
15696
- static makeStartMark(name, correlationId) {
15697
- return `msal.start.${name}.${correlationId}`;
15698
- }
15699
- static makeEndMark(name, correlationId) {
15700
- return `msal.end.${name}.${correlationId}`;
15701
- }
15702
- static supportsBrowserPerformance() {
15703
- return (typeof window !== "undefined" &&
15704
- typeof window.performance !== "undefined" &&
15705
- typeof window.performance.mark === "function" &&
15706
- typeof window.performance.measure === "function" &&
15707
- typeof window.performance.clearMarks === "function" &&
15708
- typeof window.performance.clearMeasures === "function" &&
15709
- typeof window.performance.getEntriesByName === "function");
15710
- }
15711
- /**
15712
- * Flush browser marks and measurements.
15713
- * @param {string} correlationId
15714
- * @param {SubMeasurement} measurements
15715
- */
15716
- static flushMeasurements(correlationId, measurements) {
15717
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15718
- try {
15719
- measurements.forEach((measurement) => {
15720
- const measureName = BrowserPerformanceMeasurement.makeMeasureName(measurement.name, correlationId);
15721
- const entriesForMeasurement = window.performance.getEntriesByName(measureName, "measure");
15722
- if (entriesForMeasurement.length > 0) {
15723
- window.performance.clearMeasures(measureName);
15724
- window.performance.clearMarks(BrowserPerformanceMeasurement.makeStartMark(measureName, correlationId));
15725
- window.performance.clearMarks(BrowserPerformanceMeasurement.makeEndMark(measureName, correlationId));
15726
- }
15727
- });
15728
- }
15729
- catch (e) {
15730
- // Silently catch and return null
15731
- }
15732
- }
15733
- }
15734
- startMeasurement() {
15735
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15736
- try {
15737
- window.performance.mark(this.startMark);
15738
- }
15739
- catch (e) {
15740
- // Silently catch
15741
- }
15742
- }
15743
- }
15744
- endMeasurement() {
15745
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15746
- try {
15747
- window.performance.mark(this.endMark);
15748
- window.performance.measure(this.measureName, this.startMark, this.endMark);
15749
- }
15750
- catch (e) {
15751
- // Silently catch
15752
- }
15753
- }
15754
- }
15755
- flushMeasurement() {
15756
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15757
- try {
15758
- const entriesForMeasurement = window.performance.getEntriesByName(this.measureName, "measure");
15759
- if (entriesForMeasurement.length > 0) {
15760
- const durationMs = entriesForMeasurement[0].duration;
15761
- window.performance.clearMeasures(this.measureName);
15762
- window.performance.clearMarks(this.startMark);
15763
- window.performance.clearMarks(this.endMark);
15764
- return durationMs;
15765
- }
15766
- }
15767
- catch (e) {
15768
- // Silently catch and return null
15769
- }
15770
- }
15771
- return null;
15772
- }
15773
- }
15774
-
15775
- /*
15776
- * Copyright (c) Microsoft Corporation. All rights reserved.
15777
- * Licensed under the MIT License.
15778
- */
15779
- class BrowserPerformanceClient extends PerformanceClient {
15780
- constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
15781
- super(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry);
15782
- this.browserCrypto = new BrowserCrypto(this.logger);
15783
- this.guidGenerator = new GuidGenerator(this.browserCrypto);
15784
- }
15785
- startPerformanceMeasurement(measureName, correlationId) {
15786
- return new BrowserPerformanceMeasurement(measureName, correlationId);
15787
- }
15788
- generateId() {
15789
- return this.guidGenerator.generateGuid();
15790
- }
15791
- getPageVisibility() {
15792
- return document.visibilityState?.toString() || null;
15793
- }
15794
- deleteIncompleteSubMeasurements(inProgressEvent) {
15795
- const rootEvent = this.eventsByCorrelationId.get(inProgressEvent.event.correlationId);
15796
- const isRootEvent = rootEvent && rootEvent.eventId === inProgressEvent.event.eventId;
15797
- const incompleteMeasurements = [];
15798
- if (isRootEvent && rootEvent?.incompleteSubMeasurements) {
15799
- rootEvent.incompleteSubMeasurements.forEach((subMeasurement) => {
15800
- incompleteMeasurements.push({ ...subMeasurement });
15801
- });
15802
- }
15803
- // Clean up remaining marks for incomplete sub-measurements
15804
- if (incompleteMeasurements.length > 0) {
15805
- BrowserPerformanceMeasurement.flushMeasurements(inProgressEvent.event.correlationId, incompleteMeasurements);
15806
- }
15807
- }
15808
- supportsBrowserPerformanceNow() {
15809
- return (typeof window !== "undefined" &&
15810
- typeof window.performance !== "undefined" &&
15811
- typeof window.performance.now === "function");
15812
- }
15813
- /**
15814
- * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
15815
- * Also captures browser page visibilityState.
15816
- *
15817
- * @param {PerformanceEvents} measureName
15818
- * @param {?string} [correlationId]
15819
- * @returns {((event?: Partial<PerformanceEvent>) => PerformanceEvent| null)}
15820
- */
15821
- startMeasurement(measureName, correlationId) {
15822
- // Capture page visibilityState and then invoke start/end measurement
15823
- const startPageVisibility = this.getPageVisibility();
15824
- const inProgressEvent = super.startMeasurement(measureName, correlationId);
15825
- return {
15826
- ...inProgressEvent,
15827
- endMeasurement: (event) => {
15828
- const res = inProgressEvent.endMeasurement({
15829
- startPageVisibility,
15830
- endPageVisibility: this.getPageVisibility(),
15831
- ...event,
15832
- });
15833
- this.deleteIncompleteSubMeasurements(inProgressEvent);
15834
- return res;
15835
- },
15836
- discardMeasurement: () => {
15837
- inProgressEvent.discardMeasurement();
15838
- this.deleteIncompleteSubMeasurements(inProgressEvent);
15839
- inProgressEvent.measurement.flushMeasurement();
15840
- },
15841
- };
15842
- }
15843
- /**
15844
- * Adds pre-queue time to preQueueTimeByCorrelationId map.
15845
- * @param {PerformanceEvents} eventName
15846
- * @param {?string} correlationId
15847
- * @returns
15848
- */
15849
- setPreQueueTime(eventName, correlationId) {
15850
- if (!this.supportsBrowserPerformanceNow()) {
15851
- this.logger.trace(`BrowserPerformanceClient: window performance API not available, unable to set telemetry queue time for ${eventName}`);
15852
- return;
15853
- }
15854
- if (!correlationId) {
15855
- this.logger.trace(`BrowserPerformanceClient: correlationId for ${eventName} not provided, unable to set telemetry queue time`);
15856
- return;
15857
- }
15858
- const preQueueEvent = this.preQueueTimeByCorrelationId.get(correlationId);
15859
- /**
15860
- * Manually complete queue measurement if there is an incomplete pre-queue event.
15861
- * Incomplete pre-queue events are instrumentation bugs that should be fixed.
15862
- */
15863
- if (preQueueEvent) {
15864
- this.logger.trace(`BrowserPerformanceClient: Incomplete pre-queue ${preQueueEvent.name} found`, correlationId);
15865
- this.addQueueMeasurement(preQueueEvent.name, correlationId, undefined, true);
15866
- }
15867
- this.preQueueTimeByCorrelationId.set(correlationId, {
15868
- name: eventName,
15869
- time: window.performance.now(),
15870
- });
15871
- }
15872
- /**
15873
- * Calculates and adds queue time measurement for given performance event.
15874
- *
15875
- * @param {PerformanceEvents} eventName
15876
- * @param {?string} correlationId
15877
- * @param {?number} queueTime
15878
- * @param {?boolean} manuallyCompleted - indicator for manually completed queue measurements
15879
- * @returns
15880
- */
15881
- addQueueMeasurement(eventName, correlationId, queueTime, manuallyCompleted) {
15882
- if (!this.supportsBrowserPerformanceNow()) {
15883
- this.logger.trace(`BrowserPerformanceClient: window performance API not available, unable to add queue measurement for ${eventName}`);
15884
- return;
15885
- }
15886
- if (!correlationId) {
15887
- this.logger.trace(`BrowserPerformanceClient: correlationId for ${eventName} not provided, unable to add queue measurement`);
15888
- return;
15889
- }
15890
- const preQueueTime = super.getPreQueueTime(eventName, correlationId);
15891
- if (!preQueueTime) {
15892
- return;
15893
- }
15894
- const currentTime = window.performance.now();
15895
- const resQueueTime = queueTime || super.calculateQueuedTime(preQueueTime, currentTime);
15896
- return super.addQueueMeasurement(eventName, correlationId, resQueueTime, manuallyCompleted);
15897
- }
15898
- }
15899
-
15900
- /*
15901
- * Copyright (c) Microsoft Corporation. All rights reserved.
15902
- * Licensed under the MIT License.
15926
+ /**
15927
+ * Warning: This set of exports is purely intended to be used by other MSAL libraries, and should be considered potentially unstable. We strongly discourage using them directly, you do so at your own risk.
15928
+ * Breaking changes to these APIs will be shipped under a minor version, instead of a major version.
15903
15929
  */
15930
+ // Cache Manager
15904
15931
 
15905
15932
  var internals = /*#__PURE__*/Object.freeze({
15906
15933
  __proto__: null,
15907
15934
  BrowserCacheManager: BrowserCacheManager,
15908
15935
  BrowserConstants: BrowserConstants,
15909
- BrowserPerformanceClient: BrowserPerformanceClient,
15910
- BrowserPerformanceMeasurement: BrowserPerformanceMeasurement,
15936
+ CacheRecord: CacheRecord,
15911
15937
  CryptoOps: CryptoOps,
15912
15938
  EventHandler: EventHandler,
15913
15939
  NativeAuthError: NativeAuthError,
@@ -16124,8 +16150,9 @@
16124
16150
  const idToken = new AuthToken(response.id_token, this.cryptoObj);
16125
16151
  let cacheRecord;
16126
16152
  let authority;
16153
+ let cacheRecordAccount;
16127
16154
  if (request.account) {
16128
- const cacheRecordAccount = this.loadAccount(idToken, request.account.environment, undefined, undefined, request.account.homeAccountId);
16155
+ cacheRecordAccount = AccountEntity.createFromAccountInfo(request.account);
16129
16156
  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));
16130
16157
  }
16131
16158
  else if (request.authority) {
@@ -16141,12 +16168,12 @@
16141
16168
  // "clientInfo" from options takes precedence over "clientInfo" in response
16142
16169
  if (options.clientInfo) {
16143
16170
  this.logger.trace("TokenCache - homeAccountId from options");
16144
- const cacheRecordAccount = this.loadAccount(idToken, authority.hostnameAndPort, options.clientInfo, authority.authorityType);
16171
+ cacheRecordAccount = this.loadAccount(idToken, authority, options.clientInfo);
16145
16172
  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));
16146
16173
  }
16147
16174
  else if (response.client_info) {
16148
16175
  this.logger.trace("TokenCache - homeAccountId from response");
16149
- const cacheRecordAccount = this.loadAccount(idToken, authority.hostnameAndPort, response.client_info, authority.authorityType);
16176
+ cacheRecordAccount = this.loadAccount(idToken, authority, response.client_info);
16150
16177
  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));
16151
16178
  }
16152
16179
  else {
@@ -16156,7 +16183,7 @@
16156
16183
  else {
16157
16184
  throw BrowserAuthError.createUnableToLoadTokenError("Please provide a request with an account or a request with authority.");
16158
16185
  }
16159
- return this.generateAuthenticationResult(request, idToken, cacheRecord, authority);
16186
+ return this.generateAuthenticationResult(request, idToken, cacheRecord, cacheRecordAccount, authority);
16160
16187
  }
16161
16188
  /**
16162
16189
  * Helper function to load account to msal-browser cache
@@ -16167,20 +16194,23 @@
16167
16194
  * @param requestHomeAccountId
16168
16195
  * @returns `AccountEntity`
16169
16196
  */
16170
- loadAccount(idToken, environment, clientInfo, authorityType, requestHomeAccountId) {
16197
+ loadAccount(idToken, authority, clientInfo, requestHomeAccountId) {
16171
16198
  let homeAccountId;
16172
16199
  if (requestHomeAccountId) {
16173
16200
  homeAccountId = requestHomeAccountId;
16174
16201
  }
16175
- else if (authorityType !== undefined && clientInfo) {
16176
- homeAccountId = AccountEntity.generateHomeAccountId(clientInfo, authorityType, this.logger, this.cryptoObj, idToken);
16202
+ else if (authority.authorityType !== undefined && clientInfo) {
16203
+ homeAccountId = AccountEntity.generateHomeAccountId(clientInfo, authority.authorityType, this.logger, this.cryptoObj, idToken.claims);
16177
16204
  }
16178
16205
  if (!homeAccountId) {
16179
16206
  throw BrowserAuthError.createUnableToLoadTokenError("Unexpected missing homeAccountId");
16180
16207
  }
16181
- const accountEntity = clientInfo
16182
- ? AccountEntity.createAccount(clientInfo, homeAccountId, idToken, undefined, undefined, undefined, environment)
16183
- : AccountEntity.createGenericAccount(homeAccountId, idToken, undefined, undefined, undefined, environment);
16208
+ const accountEntity = AccountEntity.createAccount({
16209
+ homeAccountId,
16210
+ idTokenClaims: idToken.claims,
16211
+ clientInfo,
16212
+ environment: authority.hostnameAndPort,
16213
+ }, authority);
16184
16214
  if (this.isBrowserEnvironment) {
16185
16215
  this.logger.verbose("TokenCache - loading account");
16186
16216
  this.storage.setAccount(accountEntity);
@@ -16274,7 +16304,7 @@
16274
16304
  * @param authority
16275
16305
  * @returns `AuthenticationResult`
16276
16306
  */
16277
- generateAuthenticationResult(request, idTokenObj, cacheRecord, authority) {
16307
+ generateAuthenticationResult(request, idTokenObj, cacheRecord, accountEntity, authority) {
16278
16308
  let accessToken = Constants.EMPTY_STRING;
16279
16309
  let responseScopes = [];
16280
16310
  let expiresOn = null;
@@ -16296,9 +16326,7 @@
16296
16326
  uniqueId: uid,
16297
16327
  tenantId: tid,
16298
16328
  scopes: responseScopes,
16299
- account: cacheRecord?.account
16300
- ? cacheRecord.account.getAccountInfo()
16301
- : null,
16329
+ account: accountEntity.getAccountInfo(),
16302
16330
  idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,
16303
16331
  idTokenClaims: idTokenObj ? idTokenObj.claims : {},
16304
16332
  accessToken: accessToken,
@@ -16310,9 +16338,8 @@
16310
16338
  familyId: Constants.EMPTY_STRING,
16311
16339
  tokenType: cacheRecord?.accessToken?.tokenType || Constants.EMPTY_STRING,
16312
16340
  state: Constants.EMPTY_STRING,
16313
- cloudGraphHostName: cacheRecord?.account?.cloudGraphHostName ||
16314
- Constants.EMPTY_STRING,
16315
- msGraphHost: cacheRecord?.account?.msGraphHost || Constants.EMPTY_STRING,
16341
+ cloudGraphHostName: accountEntity.cloudGraphHostName || Constants.EMPTY_STRING,
16342
+ msGraphHost: accountEntity.msGraphHost || Constants.EMPTY_STRING,
16316
16343
  code: undefined,
16317
16344
  fromNativeBroker: false,
16318
16345
  };
@@ -16438,9 +16465,7 @@
16438
16465
  // Initial hybrid spa map
16439
16466
  this.hybridAuthCodeResponses = new Map();
16440
16467
  // Initialize performance client
16441
- this.performanceClient = this.isBrowserEnvironment
16442
- ? new BrowserPerformanceClient(this.config.auth.clientId, this.config.auth.authority, this.logger, name, version, this.config.telemetry.application)
16443
- : new StubPerformanceClient(this.config.auth.clientId, this.config.auth.authority, this.logger, name, version, this.config.telemetry.application);
16468
+ this.performanceClient = this.config.telemetry.client;
16444
16469
  // Initialize the crypto class.
16445
16470
  this.browserCrypto = this.isBrowserEnvironment
16446
16471
  ? new CryptoOps(this.logger, this.performanceClient)
@@ -16457,6 +16482,7 @@
16457
16482
  storeAuthStateInCookie: false,
16458
16483
  secureCookies: false,
16459
16484
  cacheMigrationEnabled: false,
16485
+ claimsBasedCachingEnabled: false,
16460
16486
  };
16461
16487
  this.nativeInternalStorage = new BrowserCacheManager(this.config.auth.clientId, nativeCacheOptions, this.browserCrypto, this.logger);
16462
16488
  // Initialize the token cache
@@ -16505,7 +16531,7 @@
16505
16531
  }
16506
16532
  this.initialized = true;
16507
16533
  this.eventHandler.emitEvent(EventType.INITIALIZE_END);
16508
- initMeasurement.endMeasurement({ allowNativeBroker, success: true });
16534
+ initMeasurement.end({ allowNativeBroker, success: true });
16509
16535
  }
16510
16536
  // #region Redirect Flow
16511
16537
  /**
@@ -16517,8 +16543,14 @@
16517
16543
  */
16518
16544
  async handleRedirectPromise(hash) {
16519
16545
  this.logger.verbose("handleRedirectPromise called");
16520
- // Block token acquisition before initialize has been called if native brokering is enabled
16521
- BrowserUtils.blockNativeBrokerCalledBeforeInitialized(this.config.system.allowNativeBroker, this.initialized);
16546
+ // Block token acquisition before initialize has been called
16547
+ BrowserUtils.blockAPICallsBeforeInitialize(this.initialized);
16548
+ let foundServerResponse = hash;
16549
+ if (this.config.auth.OIDCOptions?.serverResponseType ===
16550
+ ServerResponseType.QUERY) {
16551
+ const url = window.location.href;
16552
+ foundServerResponse = UrlString.parseQueryServerResponse(url);
16553
+ }
16522
16554
  const loggedInAccounts = this.getAllAccounts();
16523
16555
  if (this.isBrowserEnvironment) {
16524
16556
  /**
@@ -16526,7 +16558,7 @@
16526
16558
  * otherwise return the promise from the first invocation. Prevents race conditions when handleRedirectPromise is called
16527
16559
  * several times concurrently.
16528
16560
  */
16529
- const redirectResponseKey = hash || Constants.EMPTY_STRING;
16561
+ const redirectResponseKey = foundServerResponse || Constants.EMPTY_STRING;
16530
16562
  let response = this.redirectResponse.get(redirectResponseKey);
16531
16563
  if (typeof response === "undefined") {
16532
16564
  this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, exports.InteractionType.Redirect);
@@ -16536,7 +16568,7 @@
16536
16568
  if (request &&
16537
16569
  NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeExtensionProvider) &&
16538
16570
  this.nativeExtensionProvider &&
16539
- !hash) {
16571
+ !foundServerResponse) {
16540
16572
  this.logger.trace("handleRedirectPromise - acquiring token from native platform");
16541
16573
  const nativeClient = new NativeInteractionClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.handleRedirectPromise, this.performanceClient, this.nativeExtensionProvider, request.accountId, this.nativeInternalStorage, request.correlationId);
16542
16574
  redirectResponse = nativeClient.handleRedirectPromise();
@@ -16546,7 +16578,7 @@
16546
16578
  const correlationId = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.CORRELATION_ID, true) || Constants.EMPTY_STRING;
16547
16579
  const redirectClient = this.createRedirectClient(correlationId);
16548
16580
  redirectResponse =
16549
- redirectClient.handleRedirectPromise(hash);
16581
+ redirectClient.handleRedirectPromise(foundServerResponse);
16550
16582
  }
16551
16583
  response = redirectResponse
16552
16584
  .then((result) => {
@@ -16677,7 +16709,7 @@
16677
16709
  result = this.acquireTokenNative(request, ApiId.acquireTokenPopup)
16678
16710
  .then((response) => {
16679
16711
  this.browserStorage.setInteractionInProgress(false);
16680
- atPopupMeasurement.endMeasurement({
16712
+ atPopupMeasurement.end({
16681
16713
  success: true,
16682
16714
  isNativeBroker: true,
16683
16715
  requestId: response.requestId,
@@ -16715,11 +16747,11 @@
16715
16747
  else {
16716
16748
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, exports.InteractionType.Popup, result);
16717
16749
  }
16718
- atPopupMeasurement.addStaticFields({
16750
+ atPopupMeasurement.add({
16719
16751
  accessTokenSize: result.accessToken.length,
16720
16752
  idTokenSize: result.idToken.length,
16721
16753
  });
16722
- atPopupMeasurement.endMeasurement({
16754
+ atPopupMeasurement.end({
16723
16755
  success: true,
16724
16756
  requestId: result.requestId,
16725
16757
  });
@@ -16732,7 +16764,7 @@
16732
16764
  else {
16733
16765
  this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, exports.InteractionType.Popup, null, e);
16734
16766
  }
16735
- atPopupMeasurement.endMeasurement({
16767
+ atPopupMeasurement.end({
16736
16768
  errorCode: e.errorCode,
16737
16769
  subErrorCode: e.subError,
16738
16770
  success: false,
@@ -16804,11 +16836,11 @@
16804
16836
  return result
16805
16837
  .then((response) => {
16806
16838
  this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, exports.InteractionType.Silent, response);
16807
- this.ssoSilentMeasurement?.addStaticFields({
16839
+ this.ssoSilentMeasurement?.add({
16808
16840
  accessTokenSize: response.accessToken.length,
16809
16841
  idTokenSize: response.idToken.length,
16810
16842
  });
16811
- this.ssoSilentMeasurement?.endMeasurement({
16843
+ this.ssoSilentMeasurement?.end({
16812
16844
  success: true,
16813
16845
  isNativeBroker: response.fromNativeBroker,
16814
16846
  requestId: response.requestId,
@@ -16817,7 +16849,7 @@
16817
16849
  })
16818
16850
  .catch((e) => {
16819
16851
  this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, exports.InteractionType.Silent, null, e);
16820
- this.ssoSilentMeasurement?.endMeasurement({
16852
+ this.ssoSilentMeasurement?.end({
16821
16853
  errorCode: e.errorCode,
16822
16854
  subErrorCode: e.subError,
16823
16855
  success: false,
@@ -16861,11 +16893,11 @@
16861
16893
  .then((result) => {
16862
16894
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, exports.InteractionType.Silent, result);
16863
16895
  this.hybridAuthCodeResponses.delete(hybridAuthCode);
16864
- atbcMeasurement.addStaticFields({
16896
+ atbcMeasurement.add({
16865
16897
  accessTokenSize: result.accessToken.length,
16866
16898
  idTokenSize: result.idToken.length,
16867
16899
  });
16868
- atbcMeasurement.endMeasurement({
16900
+ atbcMeasurement.end({
16869
16901
  success: true,
16870
16902
  isNativeBroker: result.fromNativeBroker,
16871
16903
  requestId: result.requestId,
@@ -16875,7 +16907,7 @@
16875
16907
  .catch((error) => {
16876
16908
  this.hybridAuthCodeResponses.delete(hybridAuthCode);
16877
16909
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, exports.InteractionType.Silent, null, error);
16878
- atbcMeasurement.endMeasurement({
16910
+ atbcMeasurement.end({
16879
16911
  errorCode: error.errorCode,
16880
16912
  subErrorCode: error.subError,
16881
16913
  success: false,
@@ -16886,7 +16918,7 @@
16886
16918
  }
16887
16919
  else {
16888
16920
  this.logger.verbose("Existing acquireTokenByCode request found", request.correlationId);
16889
- atbcMeasurement.discardMeasurement();
16921
+ atbcMeasurement.discard();
16890
16922
  }
16891
16923
  return response;
16892
16924
  }
@@ -16910,7 +16942,7 @@
16910
16942
  }
16911
16943
  catch (e) {
16912
16944
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, exports.InteractionType.Silent, null, e);
16913
- atbcMeasurement.endMeasurement({
16945
+ atbcMeasurement.end({
16914
16946
  errorCode: (e instanceof AuthError && e.errorCode) || undefined,
16915
16947
  subErrorCode: (e instanceof AuthError && e.subError) || undefined,
16916
16948
  success: false,
@@ -16935,7 +16967,7 @@
16935
16967
  const silentTokenResult = await silentAuthCodeClient
16936
16968
  .acquireToken(request)
16937
16969
  .then((response) => {
16938
- this.acquireTokenByCodeAsyncMeasurement?.endMeasurement({
16970
+ this.acquireTokenByCodeAsyncMeasurement?.end({
16939
16971
  success: true,
16940
16972
  fromCache: response.fromCache,
16941
16973
  isNativeBroker: response.fromNativeBroker,
@@ -16944,7 +16976,7 @@
16944
16976
  return response;
16945
16977
  })
16946
16978
  .catch((tokenRenewalError) => {
16947
- this.acquireTokenByCodeAsyncMeasurement?.endMeasurement({
16979
+ this.acquireTokenByCodeAsyncMeasurement?.end({
16948
16980
  errorCode: tokenRenewalError.errorCode,
16949
16981
  subErrorCode: tokenRenewalError.subError,
16950
16982
  success: false,
@@ -17154,6 +17186,26 @@
17154
17186
  return this.browserStorage.getActiveAccount();
17155
17187
  }
17156
17188
  // #endregion
17189
+ /**
17190
+ * Hydrates the cache with the tokens from an AuthenticationResult
17191
+ * @param result
17192
+ * @param request
17193
+ * @returns
17194
+ */
17195
+ async hydrateCache(result, request) {
17196
+ this.logger.verbose("hydrateCache called");
17197
+ // Account gets saved to browser storage regardless of native or not
17198
+ const accountEntity = AccountEntity.createFromAccountInfo(result.account, result.cloudGraphHostName, result.msGraphHost);
17199
+ this.browserStorage.setAccount(accountEntity);
17200
+ if (result.fromNativeBroker) {
17201
+ this.logger.verbose("Response was from native broker, storing in-memory");
17202
+ // Tokens from native broker are stored in-memory
17203
+ return this.nativeInternalStorage.hydrateCache(result, request);
17204
+ }
17205
+ else {
17206
+ return this.browserStorage.hydrateCache(result, request);
17207
+ }
17208
+ }
17157
17209
  // #region Helpers
17158
17210
  /**
17159
17211
  * Helper to validate app environment before making an auth request
@@ -17172,13 +17224,8 @@
17172
17224
  BrowserUtils.blockReloadInHiddenIframes();
17173
17225
  // Block redirectUri opened in a popup from calling MSAL APIs
17174
17226
  BrowserUtils.blockAcquireTokenInPopups();
17175
- /*
17176
- * Block token acquisition before initialize has been called if native brokering is enabled in top-frame.
17177
- * Skip check if application is embedded.
17178
- */
17179
- if (!isAppEmbedded) {
17180
- BrowserUtils.blockNativeBrokerCalledBeforeInitialized(this.config.system.allowNativeBroker, this.initialized);
17181
- }
17227
+ // Block token acquisition before initialize has been called
17228
+ BrowserUtils.blockAPICallsBeforeInitialize(this.initialized);
17182
17229
  // Block redirects if memory storage is enabled but storeAuthStateInCookie is not
17183
17230
  if (interactionType === exports.InteractionType.Redirect &&
17184
17231
  this.config.cache.cacheLocation ===
@@ -17504,7 +17551,7 @@
17504
17551
  async acquireTokenSilent(request) {
17505
17552
  const correlationId = this.getRequestCorrelationId(request);
17506
17553
  const atsMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenSilent, correlationId);
17507
- atsMeasurement.addStaticFields({
17554
+ atsMeasurement.add({
17508
17555
  cacheLookupPolicy: request.cacheLookupPolicy,
17509
17556
  });
17510
17557
  this.preflightBrowserEnvironmentCheck(exports.InteractionType.Silent);
@@ -17536,11 +17583,11 @@
17536
17583
  }, account)
17537
17584
  .then((result) => {
17538
17585
  this.activeSilentTokenRequests.delete(silentRequestKey);
17539
- atsMeasurement.addStaticFields({
17586
+ atsMeasurement.add({
17540
17587
  accessTokenSize: result.accessToken.length,
17541
17588
  idTokenSize: result.idToken.length,
17542
17589
  });
17543
- atsMeasurement.endMeasurement({
17590
+ atsMeasurement.end({
17544
17591
  success: true,
17545
17592
  fromCache: result.fromCache,
17546
17593
  isNativeBroker: result.fromNativeBroker,
@@ -17551,7 +17598,7 @@
17551
17598
  })
17552
17599
  .catch((error) => {
17553
17600
  this.activeSilentTokenRequests.delete(silentRequestKey);
17554
- atsMeasurement.endMeasurement({
17601
+ atsMeasurement.end({
17555
17602
  errorCode: error.errorCode,
17556
17603
  subErrorCode: error.subError,
17557
17604
  success: false,
@@ -17564,7 +17611,7 @@
17564
17611
  else {
17565
17612
  this.logger.verbose("acquireTokenSilent has been called previously, returning the result from the first call", correlationId);
17566
17613
  // Discard measurements for memoized calls, as they are usually only a couple of ms and will artificially deflate metrics
17567
- atsMeasurement.discardMeasurement();
17614
+ atsMeasurement.discard();
17568
17615
  return cachedResponse;
17569
17616
  }
17570
17617
  }
@@ -17648,7 +17695,7 @@
17648
17695
  return result
17649
17696
  .then((response) => {
17650
17697
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, exports.InteractionType.Silent, response);
17651
- this.atsAsyncMeasurement?.endMeasurement({
17698
+ this.atsAsyncMeasurement?.end({
17652
17699
  success: true,
17653
17700
  fromCache: response.fromCache,
17654
17701
  isNativeBroker: response.fromNativeBroker,
@@ -17658,7 +17705,7 @@
17658
17705
  })
17659
17706
  .catch((tokenRenewalError) => {
17660
17707
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, exports.InteractionType.Silent, null, tokenRenewalError);
17661
- this.atsAsyncMeasurement?.endMeasurement({
17708
+ this.atsAsyncMeasurement?.end({
17662
17709
  errorCode: tokenRenewalError.errorCode,
17663
17710
  subErrorCode: tokenRenewalError.subError,
17664
17711
  success: false,
@@ -17982,6 +18029,15 @@
17982
18029
  getConfiguration() {
17983
18030
  return this.controller.getConfiguration();
17984
18031
  }
18032
+ /**
18033
+ * Hydrates cache with the tokens and account in the AuthenticationResult object
18034
+ * @param result
18035
+ * @param request - The request object that was used to obtain the AuthenticationResult
18036
+ * @returns
18037
+ */
18038
+ async hydrateCache(result, request) {
18039
+ return this.controller.hydrateCache(result, request);
18040
+ }
17985
18041
  }
17986
18042
 
17987
18043
  /*
@@ -18079,6 +18135,9 @@
18079
18135
  getConfiguration: () => {
18080
18136
  throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();
18081
18137
  },
18138
+ hydrateCache: () => {
18139
+ return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());
18140
+ },
18082
18141
  };
18083
18142
 
18084
18143
  /*
@@ -18190,6 +18249,227 @@
18190
18249
  }
18191
18250
  }
18192
18251
 
18252
+ /*
18253
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18254
+ * Licensed under the MIT License.
18255
+ */
18256
+ class BrowserPerformanceMeasurement {
18257
+ constructor(name, correlationId) {
18258
+ this.correlationId = correlationId;
18259
+ this.measureName = BrowserPerformanceMeasurement.makeMeasureName(name, correlationId);
18260
+ this.startMark = BrowserPerformanceMeasurement.makeStartMark(name, correlationId);
18261
+ this.endMark = BrowserPerformanceMeasurement.makeEndMark(name, correlationId);
18262
+ }
18263
+ static makeMeasureName(name, correlationId) {
18264
+ return `msal.measure.${name}.${correlationId}`;
18265
+ }
18266
+ static makeStartMark(name, correlationId) {
18267
+ return `msal.start.${name}.${correlationId}`;
18268
+ }
18269
+ static makeEndMark(name, correlationId) {
18270
+ return `msal.end.${name}.${correlationId}`;
18271
+ }
18272
+ static supportsBrowserPerformance() {
18273
+ return (typeof window !== "undefined" &&
18274
+ typeof window.performance !== "undefined" &&
18275
+ typeof window.performance.mark === "function" &&
18276
+ typeof window.performance.measure === "function" &&
18277
+ typeof window.performance.clearMarks === "function" &&
18278
+ typeof window.performance.clearMeasures === "function" &&
18279
+ typeof window.performance.getEntriesByName === "function");
18280
+ }
18281
+ /**
18282
+ * Flush browser marks and measurements.
18283
+ * @param {string} correlationId
18284
+ * @param {SubMeasurement} measurements
18285
+ */
18286
+ static flushMeasurements(correlationId, measurements) {
18287
+ if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
18288
+ try {
18289
+ measurements.forEach((measurement) => {
18290
+ const measureName = BrowserPerformanceMeasurement.makeMeasureName(measurement.name, correlationId);
18291
+ const entriesForMeasurement = window.performance.getEntriesByName(measureName, "measure");
18292
+ if (entriesForMeasurement.length > 0) {
18293
+ window.performance.clearMeasures(measureName);
18294
+ window.performance.clearMarks(BrowserPerformanceMeasurement.makeStartMark(measureName, correlationId));
18295
+ window.performance.clearMarks(BrowserPerformanceMeasurement.makeEndMark(measureName, correlationId));
18296
+ }
18297
+ });
18298
+ }
18299
+ catch (e) {
18300
+ // Silently catch and return null
18301
+ }
18302
+ }
18303
+ }
18304
+ startMeasurement() {
18305
+ if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
18306
+ try {
18307
+ window.performance.mark(this.startMark);
18308
+ }
18309
+ catch (e) {
18310
+ // Silently catch
18311
+ }
18312
+ }
18313
+ }
18314
+ endMeasurement() {
18315
+ if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
18316
+ try {
18317
+ window.performance.mark(this.endMark);
18318
+ window.performance.measure(this.measureName, this.startMark, this.endMark);
18319
+ }
18320
+ catch (e) {
18321
+ // Silently catch
18322
+ }
18323
+ }
18324
+ }
18325
+ flushMeasurement() {
18326
+ if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
18327
+ try {
18328
+ const entriesForMeasurement = window.performance.getEntriesByName(this.measureName, "measure");
18329
+ if (entriesForMeasurement.length > 0) {
18330
+ const durationMs = entriesForMeasurement[0].duration;
18331
+ window.performance.clearMeasures(this.measureName);
18332
+ window.performance.clearMarks(this.startMark);
18333
+ window.performance.clearMarks(this.endMark);
18334
+ return durationMs;
18335
+ }
18336
+ }
18337
+ catch (e) {
18338
+ // Silently catch and return null
18339
+ }
18340
+ }
18341
+ return null;
18342
+ }
18343
+ }
18344
+
18345
+ /*
18346
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18347
+ * Licensed under the MIT License.
18348
+ */
18349
+ class BrowserPerformanceClient extends PerformanceClient {
18350
+ constructor(configuration, intFields) {
18351
+ super(configuration.auth.clientId, configuration.auth.authority || `${Constants.DEFAULT_AUTHORITY}`, new Logger(configuration.system?.loggerOptions || {}, name, version), name, version, configuration.telemetry?.application || {
18352
+ appName: "",
18353
+ appVersion: "",
18354
+ }, intFields);
18355
+ this.browserCrypto = new BrowserCrypto(this.logger);
18356
+ this.guidGenerator = new GuidGenerator(this.browserCrypto);
18357
+ }
18358
+ startPerformanceMeasurement(measureName, correlationId) {
18359
+ return new BrowserPerformanceMeasurement(measureName, correlationId);
18360
+ }
18361
+ generateId() {
18362
+ return this.guidGenerator.generateGuid();
18363
+ }
18364
+ getPageVisibility() {
18365
+ return document.visibilityState?.toString() || null;
18366
+ }
18367
+ deleteIncompleteSubMeasurements(inProgressEvent) {
18368
+ const rootEvent = this.eventsByCorrelationId.get(inProgressEvent.event.correlationId);
18369
+ const isRootEvent = rootEvent && rootEvent.eventId === inProgressEvent.event.eventId;
18370
+ const incompleteMeasurements = [];
18371
+ if (isRootEvent && rootEvent?.incompleteSubMeasurements) {
18372
+ rootEvent.incompleteSubMeasurements.forEach((subMeasurement) => {
18373
+ incompleteMeasurements.push({ ...subMeasurement });
18374
+ });
18375
+ }
18376
+ // Clean up remaining marks for incomplete sub-measurements
18377
+ if (incompleteMeasurements.length > 0) {
18378
+ BrowserPerformanceMeasurement.flushMeasurements(inProgressEvent.event.correlationId, incompleteMeasurements);
18379
+ }
18380
+ }
18381
+ supportsBrowserPerformanceNow() {
18382
+ return (typeof window !== "undefined" &&
18383
+ typeof window.performance !== "undefined" &&
18384
+ typeof window.performance.now === "function");
18385
+ }
18386
+ /**
18387
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
18388
+ * Also captures browser page visibilityState.
18389
+ *
18390
+ * @param {PerformanceEvents} measureName
18391
+ * @param {?string} [correlationId]
18392
+ * @returns {((event?: Partial<PerformanceEvent>) => PerformanceEvent| null)}
18393
+ */
18394
+ startMeasurement(measureName, correlationId) {
18395
+ // Capture page visibilityState and then invoke start/end measurement
18396
+ const startPageVisibility = this.getPageVisibility();
18397
+ const inProgressEvent = super.startMeasurement(measureName, correlationId);
18398
+ return {
18399
+ ...inProgressEvent,
18400
+ end: (event) => {
18401
+ const res = inProgressEvent.end({
18402
+ startPageVisibility,
18403
+ endPageVisibility: this.getPageVisibility(),
18404
+ ...event,
18405
+ });
18406
+ this.deleteIncompleteSubMeasurements(inProgressEvent);
18407
+ return res;
18408
+ },
18409
+ discard: () => {
18410
+ inProgressEvent.discard();
18411
+ this.deleteIncompleteSubMeasurements(inProgressEvent);
18412
+ inProgressEvent.measurement.flushMeasurement();
18413
+ },
18414
+ };
18415
+ }
18416
+ /**
18417
+ * Adds pre-queue time to preQueueTimeByCorrelationId map.
18418
+ * @param {PerformanceEvents} eventName
18419
+ * @param {?string} correlationId
18420
+ * @returns
18421
+ */
18422
+ setPreQueueTime(eventName, correlationId) {
18423
+ if (!this.supportsBrowserPerformanceNow()) {
18424
+ this.logger.trace(`BrowserPerformanceClient: window performance API not available, unable to set telemetry queue time for ${eventName}`);
18425
+ return;
18426
+ }
18427
+ if (!correlationId) {
18428
+ this.logger.trace(`BrowserPerformanceClient: correlationId for ${eventName} not provided, unable to set telemetry queue time`);
18429
+ return;
18430
+ }
18431
+ const preQueueEvent = this.preQueueTimeByCorrelationId.get(correlationId);
18432
+ /**
18433
+ * Manually complete queue measurement if there is an incomplete pre-queue event.
18434
+ * Incomplete pre-queue events are instrumentation bugs that should be fixed.
18435
+ */
18436
+ if (preQueueEvent) {
18437
+ this.logger.trace(`BrowserPerformanceClient: Incomplete pre-queue ${preQueueEvent.name} found`, correlationId);
18438
+ this.addQueueMeasurement(preQueueEvent.name, correlationId, undefined, true);
18439
+ }
18440
+ this.preQueueTimeByCorrelationId.set(correlationId, {
18441
+ name: eventName,
18442
+ time: window.performance.now(),
18443
+ });
18444
+ }
18445
+ /**
18446
+ * Calculates and adds queue time measurement for given performance event.
18447
+ *
18448
+ * @param {PerformanceEvents} eventName
18449
+ * @param {?string} correlationId
18450
+ * @param {?number} queueTime
18451
+ * @param {?boolean} manuallyCompleted - indicator for manually completed queue measurements
18452
+ * @returns
18453
+ */
18454
+ addQueueMeasurement(eventName, correlationId, queueTime, manuallyCompleted) {
18455
+ if (!this.supportsBrowserPerformanceNow()) {
18456
+ this.logger.trace(`BrowserPerformanceClient: window performance API not available, unable to add queue measurement for ${eventName}`);
18457
+ return;
18458
+ }
18459
+ if (!correlationId) {
18460
+ this.logger.trace(`BrowserPerformanceClient: correlationId for ${eventName} not provided, unable to add queue measurement`);
18461
+ return;
18462
+ }
18463
+ const preQueueTime = super.getPreQueueTime(eventName, correlationId);
18464
+ if (!preQueueTime) {
18465
+ return;
18466
+ }
18467
+ const currentTime = window.performance.now();
18468
+ const resQueueTime = queueTime || super.calculateQueuedTime(preQueueTime, currentTime);
18469
+ return super.addQueueMeasurement(eventName, correlationId, resQueueTime, manuallyCompleted);
18470
+ }
18471
+ }
18472
+
18193
18473
  exports.AccountEntity = AccountEntity;
18194
18474
  exports.ApiId = ApiId;
18195
18475
  exports.AuthError = AuthError;
@@ -18202,6 +18482,8 @@
18202
18482
  exports.BrowserCacheLocation = BrowserCacheLocation;
18203
18483
  exports.BrowserConfigurationAuthError = BrowserConfigurationAuthError;
18204
18484
  exports.BrowserConfigurationAuthErrorMessage = BrowserConfigurationAuthErrorMessage;
18485
+ exports.BrowserPerformanceClient = BrowserPerformanceClient;
18486
+ exports.BrowserPerformanceMeasurement = BrowserPerformanceMeasurement;
18205
18487
  exports.BrowserUtils = BrowserUtils;
18206
18488
  exports.CacheLookupPolicy = CacheLookupPolicy;
18207
18489
  exports.ClientAuthError = ClientAuthError;
@@ -18218,9 +18500,11 @@
18218
18500
  exports.NavigationClient = NavigationClient;
18219
18501
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;
18220
18502
  exports.PerformanceEvents = PerformanceEvents;
18503
+ exports.PromptValue = PromptValue;
18221
18504
  exports.ProtocolMode = ProtocolMode;
18222
18505
  exports.PublicClientApplication = PublicClientApplication;
18223
18506
  exports.ServerError = ServerError;
18507
+ exports.ServerResponseType = ServerResponseType;
18224
18508
  exports.SignedHttpRequest = SignedHttpRequest;
18225
18509
  exports.StringUtils = StringUtils;
18226
18510
  exports.UrlString = UrlString;