@azure/msal-browser 3.0.0-beta.1 → 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 (139) hide show
  1. package/README.md +0 -21
  2. package/dist/app/IPublicClientApplication.d.ts +1 -0
  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 +7 -0
  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 +19 -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.map +1 -1
  27. package/dist/cache/MemoryStorage.js +1 -1
  28. package/dist/cache/TokenCache.d.ts.map +1 -1
  29. package/dist/cache/TokenCache.js +20 -18
  30. package/dist/cache/TokenCache.js.map +1 -1
  31. package/dist/config/Configuration.d.ts +10 -2
  32. package/dist/config/Configuration.d.ts.map +1 -1
  33. package/dist/config/Configuration.js +37 -4
  34. package/dist/config/Configuration.js.map +1 -1
  35. package/dist/controllers/ControllerFactory.js +1 -1
  36. package/dist/controllers/IController.d.ts +1 -0
  37. package/dist/controllers/IController.d.ts.map +1 -1
  38. package/dist/controllers/StandardController.d.ts +7 -0
  39. package/dist/controllers/StandardController.d.ts.map +1 -1
  40. package/dist/controllers/StandardController.js +58 -41
  41. package/dist/controllers/StandardController.js.map +1 -1
  42. package/dist/crypto/BrowserCrypto.js +1 -1
  43. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  44. package/dist/crypto/CryptoOps.js +3 -3
  45. package/dist/crypto/CryptoOps.js.map +1 -1
  46. package/dist/crypto/GuidGenerator.js +1 -1
  47. package/dist/crypto/ModernBrowserCrypto.js +1 -1
  48. package/dist/crypto/PkceGenerator.js +1 -1
  49. package/dist/crypto/SignedHttpRequest.js +1 -1
  50. package/dist/encode/Base64Decode.js +1 -1
  51. package/dist/encode/Base64Encode.js +1 -1
  52. package/dist/error/BrowserAuthError.d.ts +2 -2
  53. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  54. package/dist/error/BrowserAuthError.js +6 -6
  55. package/dist/error/BrowserAuthError.js.map +1 -1
  56. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  57. package/dist/error/NativeAuthError.d.ts +1 -1
  58. package/dist/error/NativeAuthError.d.ts.map +1 -1
  59. package/dist/error/NativeAuthError.js +1 -1
  60. package/dist/error/NativeAuthError.js.map +1 -1
  61. package/dist/event/EventHandler.js +1 -1
  62. package/dist/event/EventMessage.d.ts.map +1 -1
  63. package/dist/event/EventMessage.js +1 -1
  64. package/dist/event/EventMessage.js.map +1 -1
  65. package/dist/event/EventType.d.ts +1 -1
  66. package/dist/event/EventType.d.ts.map +1 -1
  67. package/dist/event/EventType.js +2 -2
  68. package/dist/index.d.ts +3 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +4 -2
  71. package/dist/index.js.map +1 -1
  72. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  73. package/dist/interaction_client/BaseInteractionClient.js +2 -1
  74. package/dist/interaction_client/BaseInteractionClient.js.map +1 -1
  75. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
  76. package/dist/interaction_client/NativeInteractionClient.d.ts +1 -10
  77. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  78. package/dist/interaction_client/NativeInteractionClient.js +21 -26
  79. package/dist/interaction_client/NativeInteractionClient.js.map +1 -1
  80. package/dist/interaction_client/PopupClient.d.ts +4 -0
  81. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  82. package/dist/interaction_client/PopupClient.js +48 -9
  83. package/dist/interaction_client/PopupClient.js.map +1 -1
  84. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  85. package/dist/interaction_client/RedirectClient.js +14 -2
  86. package/dist/interaction_client/RedirectClient.js.map +1 -1
  87. package/dist/interaction_client/SilentAuthCodeClient.js +1 -1
  88. package/dist/interaction_client/SilentCacheClient.js +5 -5
  89. package/dist/interaction_client/SilentCacheClient.js.map +1 -1
  90. package/dist/interaction_client/SilentIframeClient.js +4 -4
  91. package/dist/interaction_client/SilentIframeClient.js.map +1 -1
  92. package/dist/interaction_client/SilentRefreshClient.js +4 -4
  93. package/dist/interaction_client/SilentRefreshClient.js.map +1 -1
  94. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  95. package/dist/interaction_client/StandardInteractionClient.js +7 -5
  96. package/dist/interaction_client/StandardInteractionClient.js.map +1 -1
  97. package/dist/interaction_handler/InteractionHandler.js +2 -2
  98. package/dist/interaction_handler/InteractionHandler.js.map +1 -1
  99. package/dist/interaction_handler/RedirectHandler.js +2 -2
  100. package/dist/interaction_handler/RedirectHandler.js.map +1 -1
  101. package/dist/interaction_handler/SilentHandler.js +1 -1
  102. package/dist/internals.d.ts +1 -3
  103. package/dist/internals.d.ts.map +1 -1
  104. package/dist/internals.js +7 -4
  105. package/dist/internals.js.map +1 -1
  106. package/dist/navigation/NavigationClient.js +1 -1
  107. package/dist/network/FetchClient.js +1 -1
  108. package/dist/network/XhrClient.js +1 -1
  109. package/dist/operatingcontext/BaseOperatingContext.js +1 -1
  110. package/dist/operatingcontext/StandardOperatingContext.js +1 -1
  111. package/dist/operatingcontext/TeamsAppOperatingContext.js +1 -1
  112. package/dist/packageMetadata.d.ts +1 -1
  113. package/dist/packageMetadata.d.ts.map +1 -1
  114. package/dist/packageMetadata.js +2 -2
  115. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  116. package/dist/telemetry/BrowserPerformanceClient.d.ts +3 -2
  117. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  118. package/dist/telemetry/BrowserPerformanceClient.js +12 -8
  119. package/dist/telemetry/BrowserPerformanceClient.js.map +1 -1
  120. package/dist/telemetry/BrowserPerformanceMeasurement.js +1 -1
  121. package/dist/utils/BrowserConstants.d.ts +10 -10
  122. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  123. package/dist/utils/BrowserConstants.js +1 -1
  124. package/dist/utils/BrowserConstants.js.map +1 -1
  125. package/dist/utils/BrowserProtocolUtils.js +1 -1
  126. package/dist/utils/BrowserStringUtils.js +1 -1
  127. package/dist/utils/BrowserUtils.d.ts +2 -3
  128. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  129. package/dist/utils/BrowserUtils.js +5 -6
  130. package/dist/utils/BrowserUtils.js.map +1 -1
  131. package/dist/utils/MathUtils.js +1 -1
  132. package/lib/msal-browser.cjs.js +942 -665
  133. package/lib/msal-browser.cjs.js.map +1 -1
  134. package/lib/msal-browser.js +942 -665
  135. package/lib/msal-browser.js.map +1 -1
  136. package/lib/msal-browser.min.js +62 -62
  137. package/package.json +16 -11
  138. package/dist/cache/entities/CacheRecord.js +0 -17
  139. package/dist/cache/entities/CacheRecord.js.map +0 -1
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v3.0.0-beta.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1";
1320
+ const version$1 = "14.0.0";
1315
1321
 
1316
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
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.1 2023-07-06 */
3181
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3170
3182
 
3171
3183
  /*
3172
3184
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3260,8 +3272,15 @@
3260
3272
  ...authOptions,
3261
3273
  };
3262
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
+ }
3263
3282
 
3264
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3283
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3265
3284
 
3266
3285
  /*
3267
3286
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3278,7 +3297,7 @@
3278
3297
  }
3279
3298
  }
3280
3299
 
3281
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3300
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3282
3301
 
3283
3302
  /*
3284
3303
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3375,7 +3394,7 @@
3375
3394
  }
3376
3395
  }
3377
3396
 
3378
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3397
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3379
3398
 
3380
3399
  /*
3381
3400
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3411,7 +3430,7 @@
3411
3430
  }
3412
3431
  }
3413
3432
 
3414
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3433
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3415
3434
  /*
3416
3435
  * Copyright (c) Microsoft Corporation. All rights reserved.
3417
3436
  * Licensed under the MIT License.
@@ -3421,7 +3440,7 @@
3421
3440
  UPN: "UPN",
3422
3441
  };
3423
3442
 
3424
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3443
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3425
3444
 
3426
3445
  /*
3427
3446
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3502,11 +3521,11 @@
3502
3521
  }
3503
3522
  });
3504
3523
  // remove empty string parameters
3505
- return Object.fromEntries(Object.entries(eQParams).filter(kv => kv[1] !== ""));
3524
+ return Object.fromEntries(Object.entries(eQParams).filter((kv) => kv[1] !== ""));
3506
3525
  }
3507
3526
  }
3508
3527
 
3509
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3528
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3510
3529
 
3511
3530
  /*
3512
3531
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3546,9 +3565,15 @@
3546
3565
  * @param scopeSet
3547
3566
  * @param addOidcScopes
3548
3567
  */
3549
- 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
+ }
3550
3575
  const requestScopes = addOidcScopes
3551
- ? [...(scopes || []), ...OIDC_DEFAULT_SCOPES]
3576
+ ? [...(scopes || []), ...defaultScopes]
3552
3577
  : scopes || [];
3553
3578
  const scopeSet = new ScopeSet(requestScopes);
3554
3579
  this.parameters.set(AADServerParamKeys.SCOPE, encodeURIComponent(scopeSet.printScopes()));
@@ -3883,7 +3908,7 @@
3883
3908
  }
3884
3909
  }
3885
3910
 
3886
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
3911
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3887
3912
 
3888
3913
  /*
3889
3914
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3978,7 +4003,7 @@
3978
4003
  }
3979
4004
  }
3980
4005
 
3981
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4006
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
3982
4007
 
3983
4008
  /*
3984
4009
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4117,7 +4142,7 @@
4117
4142
  }
4118
4143
  }
4119
4144
 
4120
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4145
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4121
4146
 
4122
4147
  /*
4123
4148
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4176,7 +4201,7 @@
4176
4201
  }
4177
4202
  }
4178
4203
 
4179
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4204
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4180
4205
  /*
4181
4206
  * Copyright (c) Microsoft Corporation. All rights reserved.
4182
4207
  * Licensed under the MIT License.
@@ -4223,7 +4248,7 @@
4223
4248
  }
4224
4249
  }
4225
4250
 
4226
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4251
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4227
4252
 
4228
4253
  /*
4229
4254
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4337,7 +4362,7 @@
4337
4362
  }
4338
4363
  }
4339
4364
 
4340
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4365
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4341
4366
 
4342
4367
  /*
4343
4368
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4399,7 +4424,7 @@
4399
4424
  }
4400
4425
  }
4401
4426
 
4402
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4427
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4403
4428
 
4404
4429
  /*
4405
4430
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4480,12 +4505,12 @@
4480
4505
  }
4481
4506
  }
4482
4507
 
4483
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4508
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4484
4509
  /*
4485
4510
  * Copyright (c) Microsoft Corporation. All rights reserved.
4486
4511
  * Licensed under the MIT License.
4487
4512
  */
4488
- let CacheRecord$1 = class CacheRecord {
4513
+ class CacheRecord {
4489
4514
  constructor(accountEntity, idTokenEntity, accessTokenEntity, refreshTokenEntity, appMetadataEntity) {
4490
4515
  this.account = accountEntity || null;
4491
4516
  this.idToken = idTokenEntity || null;
@@ -4493,9 +4518,9 @@
4493
4518
  this.refreshToken = refreshTokenEntity || null;
4494
4519
  this.appMetadata = appMetadataEntity || null;
4495
4520
  }
4496
- };
4521
+ }
4497
4522
 
4498
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4523
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4499
4524
 
4500
4525
  /*
4501
4526
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4569,7 +4594,7 @@
4569
4594
  }
4570
4595
  }
4571
4596
 
4572
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4597
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4573
4598
 
4574
4599
  /*
4575
4600
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4753,6 +4778,30 @@
4753
4778
  }
4754
4779
  return Constants.EMPTY_STRING;
4755
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
+ }
4756
4805
  static constructAuthorityUriFromObject(urlObject) {
4757
4806
  return new UrlString(urlObject.Protocol +
4758
4807
  "//" +
@@ -4798,6 +4847,21 @@
4798
4847
  }
4799
4848
  return deserializedQueryString;
4800
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
+ }
4801
4865
  /**
4802
4866
  * Check if the hash of the URL string contains known properties
4803
4867
  */
@@ -4814,7 +4878,7 @@
4814
4878
  }
4815
4879
  }
4816
4880
 
4817
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
4881
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
4818
4882
  /*
4819
4883
  * Copyright (c) Microsoft Corporation. All rights reserved.
4820
4884
  * Licensed under the MIT License.
@@ -5017,6 +5081,7 @@
5017
5081
  UpdateCloudDiscoveryMetadataMeasurement: "updateCloudDiscoveryMetadataMeasurement",
5018
5082
  UsernamePasswordClientAcquireToken: "usernamePasswordClientAcquireToken",
5019
5083
  NativeMessageHandlerHandshake: "nativeMessageHandlerHandshake",
5084
+ NativeGenerateAuthResult: "nativeGenerateAuthResult",
5020
5085
  };
5021
5086
  /**
5022
5087
  * State of the performance event.
@@ -5041,7 +5106,7 @@
5041
5106
  "status",
5042
5107
  ]);
5043
5108
 
5044
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
5109
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5045
5110
 
5046
5111
  /*
5047
5112
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5126,7 +5191,7 @@
5126
5191
  }
5127
5192
  }
5128
5193
 
5129
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
5194
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5130
5195
 
5131
5196
  /*
5132
5197
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5195,7 +5260,7 @@
5195
5260
  }
5196
5261
  }
5197
5262
 
5198
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
5263
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5199
5264
  /*
5200
5265
  * Copyright (c) Microsoft Corporation. All rights reserved.
5201
5266
  * Licensed under the MIT License.
@@ -5222,7 +5287,7 @@
5222
5287
  }
5223
5288
  }
5224
5289
 
5225
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
5290
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5226
5291
 
5227
5292
  /*
5228
5293
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5249,12 +5314,25 @@
5249
5314
  */
5250
5315
  validateServerAuthorizationCodeResponse(serverResponseHash, cachedState, cryptoObj) {
5251
5316
  if (!serverResponseHash.state || !cachedState) {
5252
- throw !serverResponseHash.state
5253
- ? ClientAuthError.createStateNotFoundError("Server State")
5254
- : 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);
5255
5331
  }
5256
- if (decodeURIComponent(serverResponseHash.state) !==
5257
- decodeURIComponent(cachedState)) {
5332
+ catch (e) {
5333
+ throw ClientAuthError.createInvalidStateError(serverResponseHash.state, `Cached state URI could not be decoded`);
5334
+ }
5335
+ if (decodedServerResponseHash !== decodedCachedState) {
5258
5336
  throw ClientAuthError.createStateMismatchError();
5259
5337
  }
5260
5338
  // Check for error
@@ -5314,7 +5392,7 @@
5314
5392
  }
5315
5393
  }
5316
5394
  // generate homeAccountId
5317
- 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);
5318
5396
  // save the response tokens
5319
5397
  let requestStateObj;
5320
5398
  if (!!authCodePayload && !!authCodePayload.state) {
@@ -5347,7 +5425,7 @@
5347
5425
  return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, undefined, serverRequestId);
5348
5426
  }
5349
5427
  }
5350
- await this.cacheStorage.saveCacheRecord(cacheRecord);
5428
+ await this.cacheStorage.saveCacheRecord(cacheRecord, request.storeInCache);
5351
5429
  }
5352
5430
  finally {
5353
5431
  if (this.persistencePlugin &&
@@ -5376,7 +5454,13 @@
5376
5454
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) &&
5377
5455
  !!idTokenObj) {
5378
5456
  cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
5379
- 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);
5380
5464
  }
5381
5465
  // AccessToken
5382
5466
  let cachedAccessToken = null;
@@ -5418,35 +5502,7 @@
5418
5502
  if (!StringUtils.isEmpty(serverTokenResponse.foci)) {
5419
5503
  cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);
5420
5504
  }
5421
- return new CacheRecord$1(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);
5422
- }
5423
- /**
5424
- * Generate Account
5425
- * @param serverTokenResponse
5426
- * @param idToken
5427
- * @param authority
5428
- */
5429
- generateAccountEntity(serverTokenResponse, idToken, authority, authCodePayload) {
5430
- const authorityType = authority.authorityType;
5431
- const cloudGraphHostName = authCodePayload
5432
- ? authCodePayload.cloud_graph_host_name
5433
- : Constants.EMPTY_STRING;
5434
- const msGraphhost = authCodePayload
5435
- ? authCodePayload.msgraph_host
5436
- : Constants.EMPTY_STRING;
5437
- // ADFS does not require client_info in the response
5438
- if (authorityType === AuthorityType.Adfs) {
5439
- this.logger.verbose("Authority type is ADFS, creating ADFS account");
5440
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
5441
- }
5442
- // This fallback applies to B2C as well as they fall under an AAD account type.
5443
- if (StringUtils.isEmpty(serverTokenResponse.client_info) &&
5444
- authority.protocolMode === "AAD") {
5445
- throw ClientAuthError.createClientInfoEmptyError();
5446
- }
5447
- return serverTokenResponse.client_info
5448
- ? AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost)
5449
- : AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
5505
+ return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);
5450
5506
  }
5451
5507
  /**
5452
5508
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
@@ -5525,7 +5581,7 @@
5525
5581
  }
5526
5582
  }
5527
5583
 
5528
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
5584
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5529
5585
 
5530
5586
  /*
5531
5587
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5539,6 +5595,8 @@
5539
5595
  super(configuration, performanceClient);
5540
5596
  // Flag to indicate if client is for hybrid spa auth code redemption
5541
5597
  this.includeRedirectUri = true;
5598
+ this.oidcDefaultScopes =
5599
+ this.config.authOptions.authority.options.OIDCOptions?.defaultScopes;
5542
5600
  }
5543
5601
  /**
5544
5602
  * Creates the URL of the authorization request letting the user input credentials and consent to the
@@ -5577,7 +5635,7 @@
5577
5635
  const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
5578
5636
  const httpVerAuthority = response.headers?.[HeaderNames.X_MS_HTTP_VERSION];
5579
5637
  if (httpVerAuthority) {
5580
- atsMeasurement?.addStaticFields({
5638
+ atsMeasurement?.add({
5581
5639
  httpVerAuthority,
5582
5640
  });
5583
5641
  }
@@ -5588,14 +5646,14 @@
5588
5646
  return responseHandler
5589
5647
  .handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, authCodePayload, undefined, undefined, undefined, requestId)
5590
5648
  .then((result) => {
5591
- atsMeasurement?.endMeasurement({
5649
+ atsMeasurement?.end({
5592
5650
  success: true,
5593
5651
  });
5594
5652
  return result;
5595
5653
  })
5596
5654
  .catch((error) => {
5597
5655
  this.logger.verbose("Error in fetching token in ACC", request.correlationId);
5598
- atsMeasurement?.endMeasurement({
5656
+ atsMeasurement?.end({
5599
5657
  errorCode: error.errorCode,
5600
5658
  subErrorCode: error.subError,
5601
5659
  success: false,
@@ -5611,10 +5669,8 @@
5611
5669
  handleFragmentResponse(hashFragment, cachedState) {
5612
5670
  // Handle responses.
5613
5671
  const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, null, null);
5614
- // Deserialize hash fragment response parameters.
5615
- const hashUrlString = new UrlString(hashFragment);
5616
- // Deserialize hash fragment response parameters.
5617
- const serverParams = UrlString.getDeserializedHash(hashUrlString.getHash());
5672
+ const serverParams = UrlString.getDeserializedCodeResponse(this.config.authOptions.authority.options.OIDCOptions
5673
+ ?.serverResponseType, hashFragment);
5618
5674
  // Get code response
5619
5675
  responseHandler.validateServerAuthorizationCodeResponse(serverParams, cachedState, this.cryptoUtils);
5620
5676
  // throw when there is no auth code in the response
@@ -5700,14 +5756,14 @@
5700
5756
  parameterBuilder.addRedirectUri(request.redirectUri);
5701
5757
  }
5702
5758
  // Add scope array, parameter builder will add default scopes and dedupe
5703
- parameterBuilder.addScopes(request.scopes);
5759
+ parameterBuilder.addScopes(request.scopes, true, this.oidcDefaultScopes);
5704
5760
  // add code: user set, not validated
5705
5761
  parameterBuilder.addAuthorizationCode(request.code);
5706
5762
  // Add library metadata
5707
5763
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5708
5764
  parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5709
5765
  parameterBuilder.addThrottling();
5710
- if (this.serverTelemetryManager) {
5766
+ if (this.serverTelemetryManager && !isOidcProtocolMode(this.config)) {
5711
5767
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
5712
5768
  }
5713
5769
  // add code_verifier if passed
@@ -5806,7 +5862,7 @@
5806
5862
  ...(request.scopes || []),
5807
5863
  ...(request.extraScopesToConsent || []),
5808
5864
  ];
5809
- parameterBuilder.addScopes(requestScopes);
5865
+ parameterBuilder.addScopes(requestScopes, true, this.oidcDefaultScopes);
5810
5866
  // validate the redirectUri (to be a non null value)
5811
5867
  parameterBuilder.addRedirectUri(request.redirectUri);
5812
5868
  // generate the correlationId if not set by the user and add
@@ -5819,7 +5875,9 @@
5819
5875
  parameterBuilder.addResponseTypeCode();
5820
5876
  // add library info parameters
5821
5877
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5822
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5878
+ if (!isOidcProtocolMode(this.config)) {
5879
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5880
+ }
5823
5881
  // add client_info=1
5824
5882
  parameterBuilder.addClientInfo();
5825
5883
  if (request.codeChallenge && request.codeChallengeMethod) {
@@ -5961,7 +6019,7 @@
5961
6019
  }
5962
6020
  }
5963
6021
 
5964
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
6022
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
5965
6023
 
5966
6024
  /*
5967
6025
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5982,11 +6040,11 @@
5982
6040
  this.performanceClient?.setPreQueueTime(PerformanceEvents.RefreshTokenClientExecuteTokenRequest, request.correlationId);
5983
6041
  const response = await this.executeTokenRequest(request, this.authority);
5984
6042
  const httpVerToken = response.headers?.[HeaderNames.X_MS_HTTP_VERSION];
5985
- atsMeasurement?.addStaticFields({
6043
+ atsMeasurement?.add({
5986
6044
  refreshTokenSize: response.body.refresh_token?.length || 0,
5987
6045
  });
5988
6046
  if (httpVerToken) {
5989
- atsMeasurement?.addStaticFields({
6047
+ atsMeasurement?.add({
5990
6048
  httpVerToken,
5991
6049
  });
5992
6050
  }
@@ -5998,14 +6056,14 @@
5998
6056
  return responseHandler
5999
6057
  .handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true, request.forceCache, requestId)
6000
6058
  .then((result) => {
6001
- atsMeasurement?.endMeasurement({
6059
+ atsMeasurement?.end({
6002
6060
  success: true,
6003
6061
  });
6004
6062
  return result;
6005
6063
  })
6006
6064
  .catch((error) => {
6007
6065
  this.logger.verbose("Error in fetching refresh token", request.correlationId);
6008
- atsMeasurement?.endMeasurement({
6066
+ atsMeasurement?.end({
6009
6067
  errorCode: error.errorCode,
6010
6068
  subErrorCode: error.subError,
6011
6069
  success: false,
@@ -6069,11 +6127,11 @@
6069
6127
  this.logger.verbose("RefreshTokenClientAcquireTokenWithCachedRefreshToken called", request.correlationId);
6070
6128
  const refreshToken = this.cacheManager.getRefreshToken(request.account, foci);
6071
6129
  if (!refreshToken) {
6072
- atsMeasurement?.discardMeasurement();
6130
+ atsMeasurement?.discard();
6073
6131
  throw InteractionRequiredAuthError.createNoTokensFoundError();
6074
6132
  }
6075
6133
  // attach cached RT size to the current measurement
6076
- atsMeasurement?.endMeasurement({
6134
+ atsMeasurement?.end({
6077
6135
  success: true,
6078
6136
  });
6079
6137
  const refreshTokenRequest = {
@@ -6114,13 +6172,13 @@
6114
6172
  };
6115
6173
  return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)
6116
6174
  .then((result) => {
6117
- acquireTokenMeasurement?.endMeasurement({
6175
+ acquireTokenMeasurement?.end({
6118
6176
  success: true,
6119
6177
  });
6120
6178
  return result;
6121
6179
  })
6122
6180
  .catch((error) => {
6123
- acquireTokenMeasurement?.endMeasurement({
6181
+ acquireTokenMeasurement?.end({
6124
6182
  success: false,
6125
6183
  });
6126
6184
  throw error;
@@ -6136,13 +6194,13 @@
6136
6194
  const acquireTokenMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.BaseClientCreateTokenRequestHeaders, correlationId);
6137
6195
  const parameterBuilder = new RequestParameterBuilder();
6138
6196
  parameterBuilder.addClientId(this.config.authOptions.clientId);
6139
- parameterBuilder.addScopes(request.scopes);
6197
+ parameterBuilder.addScopes(request.scopes, true, this.config.authOptions.authority.options.OIDCOptions?.defaultScopes);
6140
6198
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
6141
6199
  parameterBuilder.addClientInfo();
6142
6200
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6143
6201
  parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6144
6202
  parameterBuilder.addThrottling();
6145
- if (this.serverTelemetryManager) {
6203
+ if (this.serverTelemetryManager && !isOidcProtocolMode(this.config)) {
6146
6204
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
6147
6205
  }
6148
6206
  parameterBuilder.addCorrelationId(correlationId);
@@ -6167,7 +6225,7 @@
6167
6225
  parameterBuilder.addSshJwk(request.sshJwk);
6168
6226
  }
6169
6227
  else {
6170
- acquireTokenMeasurement?.endMeasurement({
6228
+ acquireTokenMeasurement?.end({
6171
6229
  success: false,
6172
6230
  });
6173
6231
  throw ClientConfigurationError.createMissingSshJwkError();
@@ -6196,14 +6254,14 @@
6196
6254
  break;
6197
6255
  }
6198
6256
  }
6199
- acquireTokenMeasurement?.endMeasurement({
6257
+ acquireTokenMeasurement?.end({
6200
6258
  success: true,
6201
6259
  });
6202
6260
  return parameterBuilder.createQueryString();
6203
6261
  }
6204
6262
  }
6205
6263
 
6206
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
6264
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
6207
6265
 
6208
6266
  /*
6209
6267
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6306,7 +6364,7 @@
6306
6364
  }
6307
6365
  }
6308
6366
 
6309
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
6367
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
6310
6368
  /*
6311
6369
  * Copyright (c) Microsoft Corporation. All rights reserved.
6312
6370
  * Licensed under the MIT License.
@@ -6318,7 +6376,7 @@
6318
6376
  response.hasOwnProperty("jwks_uri"));
6319
6377
  }
6320
6378
 
6321
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
6379
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
6322
6380
  /*
6323
6381
  * Copyright (c) Microsoft Corporation. All rights reserved.
6324
6382
  * Licensed under the MIT License.
@@ -7195,21 +7253,16 @@
7195
7253
  };
7196
7254
  const EndpointMetadata = rawMetdataJSON.endpointMetadata;
7197
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
+ }
7198
7264
 
7199
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
7200
- /*
7201
- * Copyright (c) Microsoft Corporation. All rights reserved.
7202
- * Licensed under the MIT License.
7203
- */
7204
- /**
7205
- * Protocol modes supported by MSAL.
7206
- */
7207
- const ProtocolMode = {
7208
- AAD: "AAD",
7209
- OIDC: "OIDC",
7210
- };
7211
-
7212
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
7265
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7213
7266
 
7214
7267
  /*
7215
7268
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7289,7 +7342,7 @@
7289
7342
  }
7290
7343
  }
7291
7344
 
7292
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
7345
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7293
7346
  /*
7294
7347
  * Copyright (c) Microsoft Corporation. All rights reserved.
7295
7348
  * Licensed under the MIT License.
@@ -7299,7 +7352,7 @@
7299
7352
  response.hasOwnProperty("metadata"));
7300
7353
  }
7301
7354
 
7302
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
7355
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7303
7356
  /*
7304
7357
  * Copyright (c) Microsoft Corporation. All rights reserved.
7305
7358
  * Licensed under the MIT License.
@@ -7309,7 +7362,7 @@
7309
7362
  response.hasOwnProperty("error_description"));
7310
7363
  }
7311
7364
 
7312
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
7365
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7313
7366
 
7314
7367
  /*
7315
7368
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7420,7 +7473,7 @@
7420
7473
  },
7421
7474
  };
7422
7475
 
7423
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
7476
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
7424
7477
 
7425
7478
  /*
7426
7479
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7593,10 +7646,10 @@
7593
7646
  * @private
7594
7647
  */
7595
7648
  canReplaceTenant(authorityUri) {
7596
- return authorityUri.PathSegments.length === 1
7597
- && !Authority.reservedTenantDomains.has(authorityUri.PathSegments[0])
7598
- && this.getAuthorityType(authorityUri) === AuthorityType.Default
7599
- && 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);
7600
7653
  }
7601
7654
  /**
7602
7655
  * Replaces tenant in url path with current tenant. Defaults to common.
@@ -7617,8 +7670,9 @@
7617
7670
  const currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
7618
7671
  currentAuthorityParts.forEach((currentPart, index) => {
7619
7672
  let cachedPart = cachedAuthorityParts[index];
7620
- if (index === 0 && this.canReplaceTenant(cachedAuthorityUrlComponents)) {
7621
- 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];
7622
7676
  /**
7623
7677
  * Check if AAD canonical authority contains tenant domain name, for example "testdomain.onmicrosoft.com",
7624
7678
  * by comparing its first path segment to the corresponding authorization endpoint path segment, which is
@@ -7639,8 +7693,9 @@
7639
7693
  * The default open id configuration endpoint for any canonical authority.
7640
7694
  */
7641
7695
  get defaultOpenIdConfigurationEndpoint() {
7696
+ const canonicalAuthorityHost = this.hostnameAndPort;
7642
7697
  if (this.authorityType === AuthorityType.Adfs ||
7643
- this.protocolMode === ProtocolMode.OIDC) {
7698
+ !this.isAliasOfKnownMicrosoftAuthority(canonicalAuthorityHost)) {
7644
7699
  return `${this.canonicalAuthority}.well-known/openid-configuration`;
7645
7700
  }
7646
7701
  return `${this.canonicalAuthority}v2.0/.well-known/openid-configuration`;
@@ -7683,41 +7738,65 @@
7683
7738
  */
7684
7739
  async updateEndpointMetadata(metadataEntity) {
7685
7740
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
7741
+ this.logger.verbose("Attempting to get endpoint metadata from authority configuration");
7686
7742
  let metadata = this.getEndpointMetadataFromConfig();
7687
7743
  if (metadata) {
7744
+ this.logger.verbose("Found endpoint metadata in authority configuration");
7688
7745
  metadataEntity.updateEndpointMetadata(metadata, false);
7689
7746
  return AuthorityMetadataSource.CONFIG;
7690
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();
7691
7773
  if (this.isAuthoritySameType(metadataEntity) &&
7692
7774
  metadataEntity.endpointsFromNetwork &&
7693
- !metadataEntity.isExpired()) {
7775
+ !metadataEntityExpired) {
7694
7776
  // No need to update
7777
+ this.logger.verbose("Found endpoint metadata in the cache.");
7695
7778
  return AuthorityMetadataSource.CACHE;
7696
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.");
7697
7784
  this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
7698
7785
  metadata = await this.getEndpointMetadataFromNetwork();
7699
7786
  if (metadata) {
7787
+ this.logger.verbose("Endpoint metadata was successfully returned from getEndpointMetadataFromNetwork()");
7700
7788
  // If the user prefers to use an azure region replace the global endpoints with regional information.
7701
7789
  if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7702
7790
  this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7791
+ this.logger.verbose("Found azure region configuration. Updating endpoints with regional information.");
7703
7792
  metadata = await this.updateMetadataWithRegionalInformation(metadata);
7704
7793
  }
7705
7794
  metadataEntity.updateEndpointMetadata(metadata, true);
7706
7795
  return AuthorityMetadataSource.NETWORK;
7707
7796
  }
7708
- let harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
7709
- if (harcodedMetadata &&
7710
- !this.authorityOptions.skipAuthorityMetadataCache) {
7711
- // If the user prefers to use an azure region replace the global endpoints with regional information.
7712
- if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7713
- this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7714
- harcodedMetadata =
7715
- await this.updateMetadataWithRegionalInformation(harcodedMetadata);
7716
- }
7717
- metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
7718
- return AuthorityMetadataSource.HARDCODED_VALUES;
7719
- }
7720
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.");
7721
7800
  throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7722
7801
  }
7723
7802
  }
@@ -7766,17 +7845,23 @@
7766
7845
  const response = await this.networkInterface.sendGetRequestAsync(openIdConfigurationEndpoint, options);
7767
7846
  const isValidResponse = isOpenIdConfigResponse(response.body);
7768
7847
  if (isValidResponse) {
7769
- perfEvent?.endMeasurement({ success: true });
7848
+ perfEvent?.end({ success: true });
7770
7849
  return response.body;
7771
7850
  }
7772
7851
  else {
7773
- perfEvent?.endMeasurement({ success: false, errorCode: "invalid_response" });
7852
+ perfEvent?.end({
7853
+ success: false,
7854
+ errorCode: "invalid_response",
7855
+ });
7774
7856
  this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: could not parse response as OpenID configuration`);
7775
7857
  return null;
7776
7858
  }
7777
7859
  }
7778
7860
  catch (e) {
7779
- perfEvent?.endMeasurement({ success: false, errorCode: "request_failure" });
7861
+ perfEvent?.end({
7862
+ success: false,
7863
+ errorCode: "request_failure",
7864
+ });
7780
7865
  this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: ${e}`);
7781
7866
  return null;
7782
7867
  }
@@ -7798,19 +7883,26 @@
7798
7883
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7799
7884
  const userConfiguredAzureRegion = this.authorityOptions.azureRegionConfiguration?.azureRegion;
7800
7885
  if (userConfiguredAzureRegion) {
7801
- if (userConfiguredAzureRegion !== Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7802
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7803
- this.regionDiscoveryMetadata.region_used = userConfiguredAzureRegion;
7886
+ if (userConfiguredAzureRegion !==
7887
+ Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7888
+ this.regionDiscoveryMetadata.region_outcome =
7889
+ RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7890
+ this.regionDiscoveryMetadata.region_used =
7891
+ userConfiguredAzureRegion;
7804
7892
  return Authority.replaceWithRegionalInformation(metadata, userConfiguredAzureRegion);
7805
7893
  }
7806
7894
  this.performanceClient?.setPreQueueTime(PerformanceEvents.RegionDiscoveryDetectRegion, this.correlationId);
7807
- const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration?.environmentRegion, this.regionDiscoveryMetadata);
7895
+ const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration
7896
+ ?.environmentRegion, this.regionDiscoveryMetadata);
7808
7897
  if (autodetectedRegionName) {
7809
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL;
7810
- this.regionDiscoveryMetadata.region_used = autodetectedRegionName;
7898
+ this.regionDiscoveryMetadata.region_outcome =
7899
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL;
7900
+ this.regionDiscoveryMetadata.region_used =
7901
+ autodetectedRegionName;
7811
7902
  return Authority.replaceWithRegionalInformation(metadata, autodetectedRegionName);
7812
7903
  }
7813
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7904
+ this.regionDiscoveryMetadata.region_outcome =
7905
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7814
7906
  }
7815
7907
  return metadata;
7816
7908
  }
@@ -7822,7 +7914,7 @@
7822
7914
  */
7823
7915
  async updateCloudDiscoveryMetadata(metadataEntity) {
7824
7916
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
7825
- 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");
7826
7918
  this.logger.verbosePii(`Known Authorities: ${this.authorityOptions.knownAuthorities ||
7827
7919
  Constants.NOT_APPLICABLE}`);
7828
7920
  this.logger.verbosePii(`Authority Metadata: ${this.authorityOptions.authorityMetadata ||
@@ -7830,17 +7922,29 @@
7830
7922
  this.logger.verbosePii(`Canonical Authority: ${metadataEntity.canonical_authority || Constants.NOT_APPLICABLE}`);
7831
7923
  let metadata = this.getCloudDiscoveryMetadataFromConfig();
7832
7924
  if (metadata) {
7833
- this.logger.verbose("Found cloud discovery metadata in the config.");
7925
+ this.logger.verbose("Found cloud discovery metadata in authority configuration");
7834
7926
  metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
7835
7927
  return AuthorityMetadataSource.CONFIG;
7836
7928
  }
7837
- // If the cached metadata came from config but that config was not passed to this instance, we must go to the network
7838
- 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
+ }
7839
7943
  const metadataEntityExpired = metadataEntity.isExpired();
7840
7944
  if (this.isAuthoritySameType(metadataEntity) &&
7841
7945
  metadataEntity.aliasesFromNetwork &&
7842
7946
  !metadataEntityExpired) {
7843
- this.logger.verbose("Found metadata in the cache.");
7947
+ this.logger.verbose("Found cloud discovery metadata in the cache.");
7844
7948
  // No need to update
7845
7949
  return AuthorityMetadataSource.CACHE;
7846
7950
  }
@@ -7855,15 +7959,8 @@
7855
7959
  metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
7856
7960
  return AuthorityMetadataSource.NETWORK;
7857
7961
  }
7858
- this.logger.verbose("Did not find cloud discovery metadata from the network... Attempting to get cloud discovery metadata from hardcoded values.");
7859
- const harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
7860
- if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
7861
- this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
7862
- metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
7863
- return AuthorityMetadataSource.HARDCODED_VALUES;
7864
- }
7865
7962
  // Metadata could not be obtained from the config, cache, network or hardcoded values
7866
- 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.");
7867
7964
  throw ClientConfigurationError.createUntrustedAuthorityError();
7868
7965
  }
7869
7966
  /**
@@ -7968,9 +8065,11 @@
7968
8065
  /**
7969
8066
  * Get cloud discovery metadata for common authorities
7970
8067
  */
7971
- getCloudDiscoveryMetadataFromHarcodedValues() {
8068
+ getCloudDiscoveryMetadataFromHardcodedValues() {
7972
8069
  if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
7973
- return InstanceDiscoveryMetadata[this.canonicalAuthority];
8070
+ const hardcodedMetadataResponse = InstanceDiscoveryMetadata[this.canonicalAuthority];
8071
+ const metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(hardcodedMetadataResponse.metadata, this.hostnameAndPort);
8072
+ return metadata;
7974
8073
  }
7975
8074
  return null;
7976
8075
  }
@@ -8045,6 +8144,13 @@
8045
8144
  isAlias(host) {
8046
8145
  return this.metadata.aliases.indexOf(host) > -1;
8047
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
+ }
8048
8154
  /**
8049
8155
  * Checks whether the provided host is that of a public cloud authority
8050
8156
  *
@@ -8086,15 +8192,17 @@
8086
8192
  * @param azureRegion string
8087
8193
  */
8088
8194
  static replaceWithRegionalInformation(metadata, azureRegion) {
8089
- metadata.authorization_endpoint =
8090
- Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
8195
+ const regionalMetadata = { ...metadata };
8196
+ regionalMetadata.authorization_endpoint =
8197
+ Authority.buildRegionalAuthorityString(regionalMetadata.authorization_endpoint, azureRegion);
8091
8198
  // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
8092
- metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
8093
- if (metadata.end_session_endpoint) {
8094
- metadata.end_session_endpoint =
8095
- 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);
8096
8204
  }
8097
- return metadata;
8205
+ return regionalMetadata;
8098
8206
  }
8099
8207
  /**
8100
8208
  * Transform CIAM_AUTHORIY as per the below rules:
@@ -8106,11 +8214,14 @@
8106
8214
  * @param authority
8107
8215
  */
8108
8216
  static transformCIAMAuthority(authority) {
8109
- 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}`;
8110
8220
  const authorityUrl = new UrlString(authority);
8111
8221
  const authorityUrlComponents = authorityUrl.getUrlComponents();
8112
8222
  // check if transformation is needed
8113
- 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)) {
8114
8225
  const tenantIdOrDomain = authorityUrlComponents.HostNameAndPort.split(".")[0];
8115
8226
  ciamAuthority = `${ciamAuthority}${tenantIdOrDomain}${Constants.AAD_TENANT_DOMAIN_SUFFIX}`;
8116
8227
  }
@@ -8118,15 +8229,15 @@
8118
8229
  }
8119
8230
  }
8120
8231
  // Reserved tenant domain names that will not be replaced with tenant id
8121
- Authority.reservedTenantDomains = (new Set([
8232
+ Authority.reservedTenantDomains = new Set([
8122
8233
  "{tenant}",
8123
8234
  "{tenantid}",
8124
8235
  AADAuthorityConstants.COMMON,
8125
8236
  AADAuthorityConstants.CONSUMERS,
8126
- AADAuthorityConstants.ORGANIZATIONS
8127
- ]));
8237
+ AADAuthorityConstants.ORGANIZATIONS,
8238
+ ]);
8128
8239
 
8129
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8240
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8130
8241
 
8131
8242
  /*
8132
8243
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8176,7 +8287,7 @@
8176
8287
  }
8177
8288
  }
8178
8289
 
8179
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8290
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8180
8291
 
8181
8292
  /*
8182
8293
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8206,7 +8317,7 @@
8206
8317
  }
8207
8318
  }
8208
8319
 
8209
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8320
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8210
8321
 
8211
8322
  /*
8212
8323
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8232,7 +8343,7 @@
8232
8343
  }
8233
8344
  }
8234
8345
 
8235
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8346
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8236
8347
 
8237
8348
  /*
8238
8349
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8249,7 +8360,7 @@
8249
8360
  },
8250
8361
  };
8251
8362
 
8252
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8363
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8253
8364
 
8254
8365
  /*
8255
8366
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8291,7 +8402,7 @@
8291
8402
  }
8292
8403
  }
8293
8404
 
8294
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8405
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8295
8406
 
8296
8407
  /*
8297
8408
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8330,7 +8441,7 @@
8330
8441
  }
8331
8442
  }
8332
8443
 
8333
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8444
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8334
8445
 
8335
8446
  /*
8336
8447
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8388,7 +8499,7 @@
8388
8499
  }
8389
8500
  }
8390
8501
 
8391
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8502
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8392
8503
 
8393
8504
  /*
8394
8505
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8587,7 +8698,7 @@
8587
8698
  }
8588
8699
  }
8589
8700
 
8590
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
8701
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
8591
8702
 
8592
8703
  /*
8593
8704
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8604,8 +8715,10 @@
8604
8715
  * @param {Logger} logger Logger used by the application
8605
8716
  * @param {string} libraryName Name of the library
8606
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
8607
8720
  */
8608
- constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
8721
+ constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry, intFields) {
8609
8722
  this.authority = authority;
8610
8723
  this.libraryName = libraryName;
8611
8724
  this.libraryVersion = libraryVersion;
@@ -8616,6 +8729,10 @@
8616
8729
  this.eventsByCorrelationId = new Map();
8617
8730
  this.queueMeasurements = new Map();
8618
8731
  this.preQueueTimeByCorrelationId = new Map();
8732
+ this.intFields = intFields || new Set();
8733
+ for (const item of IntFields) {
8734
+ this.intFields.add(item);
8735
+ }
8619
8736
  }
8620
8737
  /**
8621
8738
  * Starts and returns an platform-specific implementation of IPerformanceMeasurement.
@@ -8630,13 +8747,6 @@
8630
8747
  ) {
8631
8748
  return {};
8632
8749
  }
8633
- /**
8634
- * Get integral fields.
8635
- * Override to change the set.
8636
- */
8637
- getIntFields() {
8638
- return IntFields;
8639
- }
8640
8750
  /**
8641
8751
  * Gets map of pre-queue times by correlation Id
8642
8752
  *
@@ -8754,7 +8864,7 @@
8754
8864
  this.cacheEventByCorrelationId(inProgressEvent);
8755
8865
  // Return the event and functions the caller can use to properly end/flush the measurement
8756
8866
  return {
8757
- endMeasurement: (event) => {
8867
+ end: (event) => {
8758
8868
  return this.endMeasurement({
8759
8869
  // Initial set of event properties
8760
8870
  ...inProgressEvent,
@@ -8762,14 +8872,14 @@
8762
8872
  ...event,
8763
8873
  }, performanceMeasurement);
8764
8874
  },
8765
- discardMeasurement: () => {
8875
+ discard: () => {
8766
8876
  return this.discardMeasurements(inProgressEvent.correlationId);
8767
8877
  },
8768
- addStaticFields: (fields) => {
8769
- return this.addStaticFields(fields, inProgressEvent.correlationId);
8878
+ add: (fields) => {
8879
+ return this.addFields(fields, inProgressEvent.correlationId);
8770
8880
  },
8771
- increment: (counters) => {
8772
- return this.increment(counters, inProgressEvent.correlationId);
8881
+ increment: (fields) => {
8882
+ return this.incrementFields(fields, inProgressEvent.correlationId);
8773
8883
  },
8774
8884
  measurement: performanceMeasurement,
8775
8885
  event: inProgressEvent,
@@ -8834,7 +8944,7 @@
8834
8944
  status: PerformanceEventStatus.Completed,
8835
8945
  incompleteSubsCount,
8836
8946
  };
8837
- this.truncateIntegralFields(finalEvent, this.getIntFields());
8947
+ this.truncateIntegralFields(finalEvent);
8838
8948
  this.emitEvents([finalEvent], event.correlationId);
8839
8949
  return finalEvent;
8840
8950
  }
@@ -8843,7 +8953,7 @@
8843
8953
  * @param fields
8844
8954
  * @param correlationId
8845
8955
  */
8846
- addStaticFields(fields, correlationId) {
8956
+ addFields(fields, correlationId) {
8847
8957
  this.logger.trace("PerformanceClient: Updating static fields");
8848
8958
  const event = this.eventsByCorrelationId.get(correlationId);
8849
8959
  if (event) {
@@ -8858,18 +8968,21 @@
8858
8968
  }
8859
8969
  /**
8860
8970
  * Increment counters to be emitted when the measurements are flushed
8861
- * @param counters {Counters}
8971
+ * @param fields {string[]}
8862
8972
  * @param correlationId {string} correlation identifier
8863
8973
  */
8864
- increment(counters, correlationId) {
8974
+ incrementFields(fields, correlationId) {
8865
8975
  this.logger.trace("PerformanceClient: Updating counters");
8866
8976
  const event = this.eventsByCorrelationId.get(correlationId);
8867
8977
  if (event) {
8868
- for (const counter in counters) {
8978
+ for (const counter in fields) {
8869
8979
  if (!event.hasOwnProperty(counter)) {
8870
8980
  event[counter] = 0;
8871
8981
  }
8872
- event[counter] += counters[counter];
8982
+ else if (isNaN(Number(event[counter]))) {
8983
+ return;
8984
+ }
8985
+ event[counter] += fields[counter];
8873
8986
  }
8874
8987
  }
8875
8988
  else {
@@ -8987,8 +9100,8 @@
8987
9100
  * @param {PerformanceEvent} event performance event to update.
8988
9101
  * @param {Set<string>} intFields integral fields.
8989
9102
  */
8990
- truncateIntegralFields(event, intFields) {
8991
- intFields.forEach((key) => {
9103
+ truncateIntegralFields(event) {
9104
+ this.intFields.forEach((key) => {
8992
9105
  if (key in event && typeof event[key] === "number") {
8993
9106
  event[key] = Math.floor(event[key]);
8994
9107
  }
@@ -8996,16 +9109,22 @@
8996
9109
  }
8997
9110
  }
8998
9111
 
8999
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
9112
+ /*! @azure/msal-common v14.0.0 2023-08-08 */
9000
9113
 
9001
9114
  /*
9002
9115
  * Copyright (c) Microsoft Corporation. All rights reserved.
9003
9116
  * Licensed under the MIT License.
9004
9117
  */
9005
9118
  class StubPerformanceMeasurement {
9006
- startMeasurement() { return; }
9007
- endMeasurement() { return; }
9008
- flushMeasurement() { return null; }
9119
+ startMeasurement() {
9120
+ return;
9121
+ }
9122
+ endMeasurement() {
9123
+ return;
9124
+ }
9125
+ flushMeasurement() {
9126
+ return null;
9127
+ }
9009
9128
  }
9010
9129
  class StubPerformanceClient extends PerformanceClient {
9011
9130
  generateId() {
@@ -9017,8 +9136,36 @@
9017
9136
  calculateQueuedTime() {
9018
9137
  return 0;
9019
9138
  }
9020
- addQueueMeasurement() { return; }
9021
- 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
+ }
9022
9169
  }
9023
9170
 
9024
9171
  /*
@@ -9201,9 +9348,9 @@
9201
9348
  code: "native_connection_not_established",
9202
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.",
9203
9350
  },
9204
- nativeBrokerCalledBeforeInitialize: {
9205
- code: "native_broker_called_before_initialize",
9206
- 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.",
9207
9354
  },
9208
9355
  nativePromptNotSupported: {
9209
9356
  code: "native_prompt_not_supported",
@@ -9493,8 +9640,8 @@
9493
9640
  /**
9494
9641
  * Create an error thrown when the initialize function hasn't been called
9495
9642
  */
9496
- static createNativeBrokerCalledBeforeInitialize() {
9497
- return new BrowserAuthError(BrowserAuthErrorMessage.nativeBrokerCalledBeforeInitialize.code, BrowserAuthErrorMessage.nativeBrokerCalledBeforeInitialize.desc);
9643
+ static createUninitializedPublicClientApplication() {
9644
+ return new BrowserAuthError(BrowserAuthErrorMessage.uninitializedPublicClientApplication.code, BrowserAuthErrorMessage.uninitializedPublicClientApplication.desc);
9498
9645
  }
9499
9646
  /**
9500
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
@@ -11175,6 +11322,23 @@
11175
11322
  setRedirectRequestContext(value) {
11176
11323
  this.setTemporaryCache(TemporaryCacheKeys.REDIRECT_CONTEXT, value, true);
11177
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
+ }
11178
11342
  }
11179
11343
  const DEFAULT_BROWSER_CACHE_MANAGER = (clientId, logger) => {
11180
11344
  const cacheOptions = {
@@ -11188,20 +11352,9 @@
11188
11352
  return new BrowserCacheManager(clientId, cacheOptions, DEFAULT_CRYPTO_IMPLEMENTATION, logger);
11189
11353
  };
11190
11354
 
11191
- /*
11192
- * Copyright (c) Microsoft Corporation. All rights reserved.
11193
- * Licensed under the MIT License.
11194
- */
11195
- class CacheRecord extends CacheRecord$1 {
11196
- constructor(accountEntity, idTokenEntity, accessTokenEntity, refreshTokenEntity, appMetadataEntity) {
11197
- super(accountEntity, idTokenEntity, accessTokenEntity, refreshTokenEntity, appMetadataEntity);
11198
- this.account = accountEntity;
11199
- }
11200
- }
11201
-
11202
11355
  /* eslint-disable header/header */
11203
11356
  const name = "@azure/msal-browser";
11204
- const version = "3.0.0-beta.1";
11357
+ const version = "3.0.0";
11205
11358
 
11206
11359
  /*
11207
11360
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -11537,13 +11690,12 @@
11537
11690
  }
11538
11691
  }
11539
11692
  /**
11540
- * Throws error if native brokering is enabled but initialize hasn't been called
11541
- * @param allowNativeBroker
11693
+ * Throws error if initialize hasn't been called
11542
11694
  * @param initialized
11543
11695
  */
11544
- static blockNativeBrokerCalledBeforeInitialized(allowNativeBroker, initialized) {
11545
- if (allowNativeBroker && !initialized) {
11546
- throw BrowserAuthError.createNativeBrokerCalledBeforeInitialize();
11696
+ static blockAPICallsBeforeInitialize(initialized) {
11697
+ if (!initialized) {
11698
+ throw BrowserAuthError.createUninitializedPublicClientApplication();
11547
11699
  }
11548
11700
  }
11549
11701
  /**
@@ -11702,6 +11854,7 @@
11702
11854
  this.logger.verbose("getDiscoveredAuthority called");
11703
11855
  const authorityOptions = {
11704
11856
  protocolMode: this.config.auth.protocolMode,
11857
+ OIDCOptions: this.config.auth.OIDCOptions,
11705
11858
  knownAuthorities: this.config.auth.knownAuthorities,
11706
11859
  cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
11707
11860
  authorityMetadata: this.config.auth.authorityMetadata,
@@ -11911,6 +12064,7 @@
11911
12064
  const getAuthorityMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority, this.correlationId);
11912
12065
  const authorityOptions = {
11913
12066
  protocolMode: this.config.auth.protocolMode,
12067
+ OIDCOptions: this.config.auth.OIDCOptions,
11914
12068
  knownAuthorities: this.config.auth.knownAuthorities,
11915
12069
  cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
11916
12070
  authorityMetadata: this.config.auth.authorityMetadata,
@@ -11926,13 +12080,13 @@
11926
12080
  this.performanceClient.setPreQueueTime(PerformanceEvents.AuthorityFactoryCreateDiscoveredInstance, this.correlationId);
11927
12081
  return await AuthorityFactory.createDiscoveredInstance(builtAuthority, this.config.system.networkClient, this.browserStorage, authorityOptions, this.logger, this.performanceClient, this.correlationId)
11928
12082
  .then((result) => {
11929
- getAuthorityMeasurement.endMeasurement({
12083
+ getAuthorityMeasurement.end({
11930
12084
  success: true,
11931
12085
  });
11932
12086
  return result;
11933
12087
  })
11934
12088
  .catch((error) => {
11935
- getAuthorityMeasurement.endMeasurement({
12089
+ getAuthorityMeasurement.end({
11936
12090
  errorCode: error.errorCode,
11937
12091
  subErrorCode: error.subError,
11938
12092
  success: false,
@@ -11959,7 +12113,8 @@
11959
12113
  redirectUri: redirectUri,
11960
12114
  state: state,
11961
12115
  nonce: request.nonce || this.browserCrypto.createNewGuid(),
11962
- responseMode: ResponseMode.FRAGMENT,
12116
+ responseMode: this.config.auth.OIDCOptions
12117
+ .serverResponseType,
11963
12118
  };
11964
12119
  const account = request.account || this.browserStorage.getActiveAccount();
11965
12120
  if (account) {
@@ -12071,7 +12226,7 @@
12071
12226
  }
12072
12227
  // Acquire token with retrieved code.
12073
12228
  this.performanceClient.setPreQueueTime(PerformanceEvents.AuthClientAcquireToken, this.authCodeRequest.correlationId);
12074
- const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse);
12229
+ const tokenResponse = (await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse));
12075
12230
  this.browserStorage.cleanRequestByState(state);
12076
12231
  return tokenResponse;
12077
12232
  }
@@ -12219,7 +12374,7 @@
12219
12374
  }
12220
12375
  }
12221
12376
  // Acquire token with retrieved code.
12222
- const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse);
12377
+ const tokenResponse = (await this.authModule.acquireToken(this.authCodeRequest, authCodeResponse));
12223
12378
  this.browserStorage.cleanRequestByState(state);
12224
12379
  return tokenResponse;
12225
12380
  }
@@ -12254,7 +12409,7 @@
12254
12409
  LOGOUT_SUCCESS: "msal:logoutSuccess",
12255
12410
  LOGOUT_FAILURE: "msal:logoutFailure",
12256
12411
  LOGOUT_END: "msal:logoutEnd",
12257
- RESTORE_FROM_BFCACHE: "msal:restoreFromBFCache"
12412
+ RESTORE_FROM_BFCACHE: "msal:restoreFromBFCache",
12258
12413
  };
12259
12414
 
12260
12415
  /*
@@ -12367,8 +12522,8 @@
12367
12522
  const silentAuthClient = await this.createSilentFlowClient(serverTelemetryManager, silentRequest.authority, silentRequest.azureCloudOptions);
12368
12523
  this.logger.verbose("Silent auth client created");
12369
12524
  try {
12370
- const cachedToken = await silentAuthClient.acquireCachedToken(silentRequest);
12371
- acquireTokenMeasurement.endMeasurement({
12525
+ const cachedToken = (await silentAuthClient.acquireCachedToken(silentRequest));
12526
+ acquireTokenMeasurement.end({
12372
12527
  success: true,
12373
12528
  fromCache: true,
12374
12529
  });
@@ -12380,7 +12535,7 @@
12380
12535
  BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code) {
12381
12536
  this.logger.verbose("Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.");
12382
12537
  }
12383
- acquireTokenMeasurement.endMeasurement({
12538
+ acquireTokenMeasurement.end({
12384
12539
  errorCode: (error instanceof AuthError && error.errorCode) ||
12385
12540
  undefined,
12386
12541
  subErrorCode: (error instanceof AuthError && error.subError) || undefined,
@@ -12412,7 +12567,7 @@
12412
12567
  this.performanceClient.setPreQueueTime(PerformanceEvents.InitializeBaseRequest, this.correlationId);
12413
12568
  return {
12414
12569
  ...request,
12415
- ...await this.initializeBaseRequest(request, account),
12570
+ ...(await this.initializeBaseRequest(request, account)),
12416
12571
  account: account,
12417
12572
  forceRefresh: request.forceRefresh || false,
12418
12573
  };
@@ -12446,7 +12601,7 @@
12446
12601
  // check if the tokens can be retrieved from internal cache
12447
12602
  try {
12448
12603
  const result = await this.acquireTokensFromCache(this.accountId, nativeRequest);
12449
- nativeATMeasurement.endMeasurement({
12604
+ nativeATMeasurement.end({
12450
12605
  success: true,
12451
12606
  isNativeBroker: false,
12452
12607
  fromCache: true,
@@ -12466,7 +12621,7 @@
12466
12621
  const validatedResponse = this.validateNativeResponse(response);
12467
12622
  return this.handleNativeResponse(validatedResponse, nativeRequest, reqTimestamp)
12468
12623
  .then((result) => {
12469
- nativeATMeasurement.endMeasurement({
12624
+ nativeATMeasurement.end({
12470
12625
  success: true,
12471
12626
  isNativeBroker: true,
12472
12627
  requestId: result.requestId,
@@ -12474,7 +12629,7 @@
12474
12629
  return result;
12475
12630
  })
12476
12631
  .catch((error) => {
12477
- nativeATMeasurement.endMeasurement({
12632
+ nativeATMeasurement.end({
12478
12633
  success: false,
12479
12634
  errorCode: error.errorCode,
12480
12635
  subErrorCode: error.subError,
@@ -12520,7 +12675,10 @@
12520
12675
  try {
12521
12676
  const silentRequest = this.createSilentCacheRequest(request, account);
12522
12677
  const result = await this.silentCacheClient.acquireToken(silentRequest);
12523
- return result;
12678
+ return {
12679
+ ...result,
12680
+ account,
12681
+ };
12524
12682
  }
12525
12683
  catch (e) {
12526
12684
  throw e;
@@ -12618,16 +12776,20 @@
12618
12776
  }
12619
12777
  // Get the preferred_cache domain for the given authority
12620
12778
  const authority = await this.getDiscoveredAuthority(request.authority);
12621
- const authorityPreferredCache = authority.getPreferredCache();
12622
12779
  // generate identifiers
12623
12780
  const idTokenObj = this.createIdTokenObj(response);
12624
12781
  const homeAccountIdentifier = this.createHomeAccountIdentifier(response, idTokenObj);
12625
- 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);
12626
12788
  // generate authenticationResult
12627
12789
  const result = await this.generateAuthenticationResult(response, request, idTokenObj, accountEntity, authority.canonicalAuthority, reqTimestamp);
12628
12790
  // cache accounts and tokens in the appropriate storage
12629
12791
  this.cacheAccount(accountEntity);
12630
- this.cacheNativeTokens(response, request, homeAccountIdentifier, accountEntity, idTokenObj, result.accessToken, result.tenantId, reqTimestamp);
12792
+ this.cacheNativeTokens(response, request, homeAccountIdentifier, idTokenObj, result.accessToken, result.tenantId, reqTimestamp);
12631
12793
  return result;
12632
12794
  }
12633
12795
  /**
@@ -12646,20 +12808,9 @@
12646
12808
  */
12647
12809
  createHomeAccountIdentifier(response, idTokenObj) {
12648
12810
  // Save account in browser storage
12649
- 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);
12650
12812
  return homeAccountIdentifier;
12651
12813
  }
12652
- /**
12653
- * Creates account entity
12654
- * @param response
12655
- * @param homeAccountIdentifier
12656
- * @param idTokenObj
12657
- * @param authority
12658
- * @returns
12659
- */
12660
- createAccountEntity(response, homeAccountIdentifier, idTokenObj, authority) {
12661
- return AccountEntity.createAccount(response.client_info, homeAccountIdentifier, idTokenObj, undefined, undefined, undefined, authority, response.account.id);
12662
- }
12663
12814
  /**
12664
12815
  * Helper to generate scopes
12665
12816
  * @param response
@@ -12778,7 +12929,7 @@
12778
12929
  * @param tenantId
12779
12930
  * @param reqTimestamp
12780
12931
  */
12781
- cacheNativeTokens(response, request, homeAccountIdentifier, accountEntity, idTokenObj, responseAccessToken, tenantId, reqTimestamp) {
12932
+ cacheNativeTokens(response, request, homeAccountIdentifier, idTokenObj, responseAccessToken, tenantId, reqTimestamp) {
12782
12933
  const cachedIdToken = IdTokenEntity.createIdTokenEntity(homeAccountIdentifier, request.authority, response.id_token || Constants.EMPTY_STRING, request.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
12783
12934
  // cache accessToken in inmemory storage
12784
12935
  const expiresIn = request.tokenType === AuthenticationScheme.POP
@@ -12791,15 +12942,15 @@
12791
12942
  const cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(homeAccountIdentifier, request.authority, responseAccessToken, request.clientId, idTokenObj
12792
12943
  ? idTokenObj.claims.tid || Constants.EMPTY_STRING
12793
12944
  : tenantId, responseScopes.printScopes(), tokenExpirationSeconds, 0, this.browserCrypto);
12794
- const nativeCacheRecord = new CacheRecord(accountEntity, cachedIdToken, cachedAccessToken);
12795
- this.nativeStorageManager.saveCacheRecord(nativeCacheRecord);
12945
+ const nativeCacheRecord = new CacheRecord(undefined, cachedIdToken, cachedAccessToken);
12946
+ this.nativeStorageManager.saveCacheRecord(nativeCacheRecord, request.storeInCache);
12796
12947
  }
12797
12948
  addTelemetryFromNativeResponse(response) {
12798
12949
  const mats = this.getMATSFromResponse(response);
12799
12950
  if (!mats) {
12800
12951
  return null;
12801
12952
  }
12802
- this.performanceClient.addStaticFields({
12953
+ this.performanceClient.addFields({
12803
12954
  extensionId: this.nativeMessageHandler.getExtensionId(),
12804
12955
  extensionVersion: this.nativeMessageHandler.getExtensionVersion(),
12805
12956
  matsBrokerVersion: mats.broker_version,
@@ -13012,7 +13163,7 @@
13012
13163
  method: NativeExtensionMethod.HandshakeRequest,
13013
13164
  },
13014
13165
  };
13015
- this.handshakeEvent.addStaticFields({
13166
+ this.handshakeEvent.add({
13016
13167
  extensionId: this.extensionId,
13017
13168
  extensionHandshakeTimeoutMs: this.handshakeTimeoutMs,
13018
13169
  });
@@ -13030,7 +13181,7 @@
13030
13181
  window.removeEventListener("message", this.windowListener, false);
13031
13182
  this.messageChannel.port1.close();
13032
13183
  this.messageChannel.port2.close();
13033
- this.handshakeEvent.endMeasurement({
13184
+ this.handshakeEvent.end({
13034
13185
  extensionHandshakeTimedOut: true,
13035
13186
  success: false,
13036
13187
  });
@@ -13075,7 +13226,7 @@
13075
13226
  this.messageChannel.port1.close();
13076
13227
  this.messageChannel.port2.close();
13077
13228
  window.removeEventListener("message", this.windowListener, false);
13078
- this.handshakeEvent.endMeasurement({
13229
+ this.handshakeEvent.end({
13079
13230
  success: false,
13080
13231
  extensionInstalled: false,
13081
13232
  });
@@ -13127,7 +13278,7 @@
13127
13278
  this.extensionId = request.extensionId;
13128
13279
  this.extensionVersion = request.body.version;
13129
13280
  this.logger.verbose(`NativeMessageHandler - Received HandshakeResponse from extension: ${this.extensionId}`);
13130
- this.handshakeEvent.endMeasurement({
13281
+ this.handshakeEvent.end({
13131
13282
  extensionInstalled: true,
13132
13283
  success: true,
13133
13284
  });
@@ -13436,6 +13587,18 @@
13436
13587
  this.performanceClient.setPreQueueTime(PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, validLogoutRequest.correlationId);
13437
13588
  const authClient = await this.createAuthCodeClient(serverTelemetryManager, logoutRequest && logoutRequest.authority);
13438
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
+ }
13439
13602
  // Create logout string and navigate user window to logout.
13440
13603
  const logoutUri = authClient.getLogoutUri(validLogoutRequest);
13441
13604
  this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, exports.InteractionType.Redirect, validLogoutRequest);
@@ -13610,7 +13773,7 @@
13610
13773
  this.logger.verbose("Account id found in hash, calling WAM for token");
13611
13774
  // end measurement for server call with native brokering enabled
13612
13775
  if (fetchNativeAccountIdMeasurement) {
13613
- fetchNativeAccountIdMeasurement.endMeasurement({
13776
+ fetchNativeAccountIdMeasurement.end({
13614
13777
  success: true,
13615
13778
  isNativeBroker: true,
13616
13779
  });
@@ -13667,6 +13830,30 @@
13667
13830
  this.performanceClient.setPreQueueTime(PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, validRequest.correlationId);
13668
13831
  const authClient = await this.createAuthCodeClient(serverTelemetryManager, requestAuthority);
13669
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
+ }
13670
13857
  // Create logout string and navigate user window to logout.
13671
13858
  const logoutUri = authClient.getLogoutUri(validRequest);
13672
13859
  this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, exports.InteractionType.Popup, validRequest);
@@ -13751,7 +13938,7 @@
13751
13938
  return;
13752
13939
  }
13753
13940
  let href = Constants.EMPTY_STRING;
13754
- let hash = Constants.EMPTY_STRING;
13941
+ let serverResponseString = Constants.EMPTY_STRING;
13755
13942
  try {
13756
13943
  /*
13757
13944
  * Will throw if cross origin,
@@ -13759,7 +13946,8 @@
13759
13946
  * since we need the interval to keep running while on STS UI.
13760
13947
  */
13761
13948
  href = popupWindow.location.href;
13762
- hash = popupWindow.location.hash;
13949
+ serverResponseString =
13950
+ this.extractServerResponseStringFromPopup(popupWindow, href);
13763
13951
  }
13764
13952
  catch (e) { }
13765
13953
  // Don't process blank pages or cross domain
@@ -13772,17 +13960,17 @@
13772
13960
  * as popup operations can take a long time.
13773
13961
  */
13774
13962
  ticks++;
13775
- if (hash) {
13963
+ if (serverResponseString) {
13776
13964
  this.logger.verbose("PopupHandler.monitorPopupForHash - found hash in url");
13777
13965
  clearInterval(intervalId);
13778
13966
  this.cleanPopup(popupWindow);
13779
- if (UrlString.hashContainsKnownProperties(hash)) {
13967
+ if (UrlString.hashContainsKnownProperties(serverResponseString)) {
13780
13968
  this.logger.verbose("PopupHandler.monitorPopupForHash - hash contains known properties, returning.");
13781
- resolve(hash);
13969
+ resolve(serverResponseString);
13782
13970
  }
13783
13971
  else {
13784
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.");
13785
- this.logger.errorPii(`PopupHandler.monitorPopupForHash - hash found: ${hash}`);
13973
+ this.logger.errorPii(`PopupHandler.monitorPopupForHash - hash found: ${serverResponseString}`);
13786
13974
  reject(BrowserAuthError.createHashDoesNotContainKnownPropertiesError());
13787
13975
  }
13788
13976
  }
@@ -13963,6 +14151,20 @@
13963
14151
  const homeAccountId = request.account && request.account.homeAccountId;
13964
14152
  return `${BrowserConstants.POPUP_NAME_PREFIX}.${this.config.auth.clientId}.${homeAccountId}.${this.correlationId}`;
13965
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
+ }
13966
14168
  }
13967
14169
 
13968
14170
  /*
@@ -14037,6 +14239,14 @@
14037
14239
  navigateToLoginRequestUrl: true,
14038
14240
  clientCapabilities: [],
14039
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
+ },
14040
14250
  azureCloudOptions: {
14041
14251
  azureCloudInstance: AzureCloudInstance.None,
14042
14252
  tenant: Constants.EMPTY_STRING,
@@ -14081,7 +14291,7 @@
14081
14291
  redirectNavigationTimeout: DEFAULT_REDIRECT_TIMEOUT_MS,
14082
14292
  asyncPopups: false,
14083
14293
  allowRedirectInIframe: false,
14084
- allowNativeBroker: true,
14294
+ allowNativeBroker: false,
14085
14295
  nativeBrokerHandshakeTimeout: userInputSystem?.nativeBrokerHandshakeTimeout ||
14086
14296
  DEFAULT_NATIVE_BROKER_HANDSHAKE_TIMEOUT_MS,
14087
14297
  pollIntervalMilliseconds: BrowserConstants.DEFAULT_POLL_INTERVAL_MS,
@@ -14095,9 +14305,33 @@
14095
14305
  appName: Constants.EMPTY_STRING,
14096
14306
  appVersion: Constants.EMPTY_STRING,
14097
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
+ }),
14098
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
+ }
14099
14326
  const overlayedConfig = {
14100
- 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
+ },
14101
14335
  cache: { ...DEFAULT_CACHE_OPTIONS, ...userInputCache },
14102
14336
  system: { ...DEFAULT_BROWSER_SYSTEM_OPTIONS, ...providedSystemOptions },
14103
14337
  telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...userInputTelemetry },
@@ -14296,7 +14530,7 @@
14296
14530
  if (request.prompt &&
14297
14531
  request.prompt !== PromptValue.NONE &&
14298
14532
  request.prompt !== PromptValue.NO_SESSION) {
14299
- acquireTokenMeasurement.endMeasurement({
14533
+ acquireTokenMeasurement.end({
14300
14534
  success: false,
14301
14535
  });
14302
14536
  throw BrowserAuthError.createSilentPromptValueError(request.prompt);
@@ -14316,7 +14550,7 @@
14316
14550
  this.logger.verbose("Auth code client created");
14317
14551
  this.performanceClient.setPreQueueTime(PerformanceEvents.SilentIframeClientTokenHelper, request.correlationId);
14318
14552
  return await this.silentTokenHelper(authClient, silentRequest).then((result) => {
14319
- acquireTokenMeasurement.endMeasurement({
14553
+ acquireTokenMeasurement.end({
14320
14554
  success: true,
14321
14555
  fromCache: false,
14322
14556
  requestId: result.requestId,
@@ -14330,7 +14564,7 @@
14330
14564
  serverTelemetryManager.cacheFailedRequest(e);
14331
14565
  }
14332
14566
  this.browserStorage.cleanRequestByState(silentRequest.state);
14333
- acquireTokenMeasurement.endMeasurement({
14567
+ acquireTokenMeasurement.end({
14334
14568
  errorCode: (e instanceof AuthError && e.errorCode) || undefined,
14335
14569
  subErrorCode: (e instanceof AuthError && e.subError) || undefined,
14336
14570
  success: false,
@@ -14410,7 +14644,7 @@
14410
14644
  this.performanceClient.setPreQueueTime(PerformanceEvents.InitializeBaseRequest, request.correlationId);
14411
14645
  const silentRequest = {
14412
14646
  ...request,
14413
- ...await this.initializeBaseRequest(request, request.account)
14647
+ ...(await this.initializeBaseRequest(request, request.account)),
14414
14648
  };
14415
14649
  const acquireTokenMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SilentRefreshClientAcquireToken, silentRequest.correlationId);
14416
14650
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);
@@ -14422,7 +14656,7 @@
14422
14656
  .acquireTokenByRefreshToken(silentRequest)
14423
14657
  .then((result) => result)
14424
14658
  .then((result) => {
14425
- acquireTokenMeasurement.endMeasurement({
14659
+ acquireTokenMeasurement.end({
14426
14660
  success: true,
14427
14661
  fromCache: result.fromCache,
14428
14662
  requestId: result.requestId,
@@ -14432,7 +14666,7 @@
14432
14666
  .catch((e) => {
14433
14667
  e.setCorrelationId(this.correlationId);
14434
14668
  serverTelemetryManager.cacheFailedRequest(e);
14435
- acquireTokenMeasurement.endMeasurement({
14669
+ acquireTokenMeasurement.end({
14436
14670
  errorCode: e.errorCode,
14437
14671
  subErrorCode: e.subError,
14438
14672
  success: false,
@@ -15610,7 +15844,7 @@
15610
15844
  requestUri: request.resourceRequestUri,
15611
15845
  });
15612
15846
  if (publicKeyThumbMeasurement) {
15613
- publicKeyThumbMeasurement.endMeasurement({
15847
+ publicKeyThumbMeasurement.end({
15614
15848
  success: true,
15615
15849
  });
15616
15850
  }
@@ -15666,7 +15900,7 @@
15666
15900
  const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));
15667
15901
  const signedJwt = `${tokenString}.${encodedSignature}`;
15668
15902
  if (signJwtMeasurement) {
15669
- signJwtMeasurement.endMeasurement({
15903
+ signJwtMeasurement.end({
15670
15904
  success: true,
15671
15905
  });
15672
15906
  }
@@ -15689,231 +15923,16 @@
15689
15923
  * Copyright (c) Microsoft Corporation. All rights reserved.
15690
15924
  * Licensed under the MIT License.
15691
15925
  */
15692
- class BrowserPerformanceMeasurement {
15693
- constructor(name, correlationId) {
15694
- this.correlationId = correlationId;
15695
- this.measureName = BrowserPerformanceMeasurement.makeMeasureName(name, correlationId);
15696
- this.startMark = BrowserPerformanceMeasurement.makeStartMark(name, correlationId);
15697
- this.endMark = BrowserPerformanceMeasurement.makeEndMark(name, correlationId);
15698
- }
15699
- static makeMeasureName(name, correlationId) {
15700
- return `msal.measure.${name}.${correlationId}`;
15701
- }
15702
- static makeStartMark(name, correlationId) {
15703
- return `msal.start.${name}.${correlationId}`;
15704
- }
15705
- static makeEndMark(name, correlationId) {
15706
- return `msal.end.${name}.${correlationId}`;
15707
- }
15708
- static supportsBrowserPerformance() {
15709
- return (typeof window !== "undefined" &&
15710
- typeof window.performance !== "undefined" &&
15711
- typeof window.performance.mark === "function" &&
15712
- typeof window.performance.measure === "function" &&
15713
- typeof window.performance.clearMarks === "function" &&
15714
- typeof window.performance.clearMeasures === "function" &&
15715
- typeof window.performance.getEntriesByName === "function");
15716
- }
15717
- /**
15718
- * Flush browser marks and measurements.
15719
- * @param {string} correlationId
15720
- * @param {SubMeasurement} measurements
15721
- */
15722
- static flushMeasurements(correlationId, measurements) {
15723
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15724
- try {
15725
- measurements.forEach((measurement) => {
15726
- const measureName = BrowserPerformanceMeasurement.makeMeasureName(measurement.name, correlationId);
15727
- const entriesForMeasurement = window.performance.getEntriesByName(measureName, "measure");
15728
- if (entriesForMeasurement.length > 0) {
15729
- window.performance.clearMeasures(measureName);
15730
- window.performance.clearMarks(BrowserPerformanceMeasurement.makeStartMark(measureName, correlationId));
15731
- window.performance.clearMarks(BrowserPerformanceMeasurement.makeEndMark(measureName, correlationId));
15732
- }
15733
- });
15734
- }
15735
- catch (e) {
15736
- // Silently catch and return null
15737
- }
15738
- }
15739
- }
15740
- startMeasurement() {
15741
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15742
- try {
15743
- window.performance.mark(this.startMark);
15744
- }
15745
- catch (e) {
15746
- // Silently catch
15747
- }
15748
- }
15749
- }
15750
- endMeasurement() {
15751
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15752
- try {
15753
- window.performance.mark(this.endMark);
15754
- window.performance.measure(this.measureName, this.startMark, this.endMark);
15755
- }
15756
- catch (e) {
15757
- // Silently catch
15758
- }
15759
- }
15760
- }
15761
- flushMeasurement() {
15762
- if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {
15763
- try {
15764
- const entriesForMeasurement = window.performance.getEntriesByName(this.measureName, "measure");
15765
- if (entriesForMeasurement.length > 0) {
15766
- const durationMs = entriesForMeasurement[0].duration;
15767
- window.performance.clearMeasures(this.measureName);
15768
- window.performance.clearMarks(this.startMark);
15769
- window.performance.clearMarks(this.endMark);
15770
- return durationMs;
15771
- }
15772
- }
15773
- catch (e) {
15774
- // Silently catch and return null
15775
- }
15776
- }
15777
- return null;
15778
- }
15779
- }
15780
-
15781
- /*
15782
- * Copyright (c) Microsoft Corporation. All rights reserved.
15783
- * Licensed under the MIT License.
15784
- */
15785
- class BrowserPerformanceClient extends PerformanceClient {
15786
- constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
15787
- super(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry);
15788
- this.browserCrypto = new BrowserCrypto(this.logger);
15789
- this.guidGenerator = new GuidGenerator(this.browserCrypto);
15790
- }
15791
- startPerformanceMeasurement(measureName, correlationId) {
15792
- return new BrowserPerformanceMeasurement(measureName, correlationId);
15793
- }
15794
- generateId() {
15795
- return this.guidGenerator.generateGuid();
15796
- }
15797
- getPageVisibility() {
15798
- return document.visibilityState?.toString() || null;
15799
- }
15800
- deleteIncompleteSubMeasurements(inProgressEvent) {
15801
- const rootEvent = this.eventsByCorrelationId.get(inProgressEvent.event.correlationId);
15802
- const isRootEvent = rootEvent && rootEvent.eventId === inProgressEvent.event.eventId;
15803
- const incompleteMeasurements = [];
15804
- if (isRootEvent && rootEvent?.incompleteSubMeasurements) {
15805
- rootEvent.incompleteSubMeasurements.forEach((subMeasurement) => {
15806
- incompleteMeasurements.push({ ...subMeasurement });
15807
- });
15808
- }
15809
- // Clean up remaining marks for incomplete sub-measurements
15810
- if (incompleteMeasurements.length > 0) {
15811
- BrowserPerformanceMeasurement.flushMeasurements(inProgressEvent.event.correlationId, incompleteMeasurements);
15812
- }
15813
- }
15814
- supportsBrowserPerformanceNow() {
15815
- return (typeof window !== "undefined" &&
15816
- typeof window.performance !== "undefined" &&
15817
- typeof window.performance.now === "function");
15818
- }
15819
- /**
15820
- * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
15821
- * Also captures browser page visibilityState.
15822
- *
15823
- * @param {PerformanceEvents} measureName
15824
- * @param {?string} [correlationId]
15825
- * @returns {((event?: Partial<PerformanceEvent>) => PerformanceEvent| null)}
15826
- */
15827
- startMeasurement(measureName, correlationId) {
15828
- // Capture page visibilityState and then invoke start/end measurement
15829
- const startPageVisibility = this.getPageVisibility();
15830
- const inProgressEvent = super.startMeasurement(measureName, correlationId);
15831
- return {
15832
- ...inProgressEvent,
15833
- endMeasurement: (event) => {
15834
- const res = inProgressEvent.endMeasurement({
15835
- startPageVisibility,
15836
- endPageVisibility: this.getPageVisibility(),
15837
- ...event,
15838
- });
15839
- this.deleteIncompleteSubMeasurements(inProgressEvent);
15840
- return res;
15841
- },
15842
- discardMeasurement: () => {
15843
- inProgressEvent.discardMeasurement();
15844
- this.deleteIncompleteSubMeasurements(inProgressEvent);
15845
- inProgressEvent.measurement.flushMeasurement();
15846
- },
15847
- };
15848
- }
15849
- /**
15850
- * Adds pre-queue time to preQueueTimeByCorrelationId map.
15851
- * @param {PerformanceEvents} eventName
15852
- * @param {?string} correlationId
15853
- * @returns
15854
- */
15855
- setPreQueueTime(eventName, correlationId) {
15856
- if (!this.supportsBrowserPerformanceNow()) {
15857
- this.logger.trace(`BrowserPerformanceClient: window performance API not available, unable to set telemetry queue time for ${eventName}`);
15858
- return;
15859
- }
15860
- if (!correlationId) {
15861
- this.logger.trace(`BrowserPerformanceClient: correlationId for ${eventName} not provided, unable to set telemetry queue time`);
15862
- return;
15863
- }
15864
- const preQueueEvent = this.preQueueTimeByCorrelationId.get(correlationId);
15865
- /**
15866
- * Manually complete queue measurement if there is an incomplete pre-queue event.
15867
- * Incomplete pre-queue events are instrumentation bugs that should be fixed.
15868
- */
15869
- if (preQueueEvent) {
15870
- this.logger.trace(`BrowserPerformanceClient: Incomplete pre-queue ${preQueueEvent.name} found`, correlationId);
15871
- this.addQueueMeasurement(preQueueEvent.name, correlationId, undefined, true);
15872
- }
15873
- this.preQueueTimeByCorrelationId.set(correlationId, {
15874
- name: eventName,
15875
- time: window.performance.now(),
15876
- });
15877
- }
15878
- /**
15879
- * Calculates and adds queue time measurement for given performance event.
15880
- *
15881
- * @param {PerformanceEvents} eventName
15882
- * @param {?string} correlationId
15883
- * @param {?number} queueTime
15884
- * @param {?boolean} manuallyCompleted - indicator for manually completed queue measurements
15885
- * @returns
15886
- */
15887
- addQueueMeasurement(eventName, correlationId, queueTime, manuallyCompleted) {
15888
- if (!this.supportsBrowserPerformanceNow()) {
15889
- this.logger.trace(`BrowserPerformanceClient: window performance API not available, unable to add queue measurement for ${eventName}`);
15890
- return;
15891
- }
15892
- if (!correlationId) {
15893
- this.logger.trace(`BrowserPerformanceClient: correlationId for ${eventName} not provided, unable to add queue measurement`);
15894
- return;
15895
- }
15896
- const preQueueTime = super.getPreQueueTime(eventName, correlationId);
15897
- if (!preQueueTime) {
15898
- return;
15899
- }
15900
- const currentTime = window.performance.now();
15901
- const resQueueTime = queueTime || super.calculateQueuedTime(preQueueTime, currentTime);
15902
- return super.addQueueMeasurement(eventName, correlationId, resQueueTime, manuallyCompleted);
15903
- }
15904
- }
15905
-
15906
- /*
15907
- * Copyright (c) Microsoft Corporation. All rights reserved.
15908
- * 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.
15909
15929
  */
15930
+ // Cache Manager
15910
15931
 
15911
15932
  var internals = /*#__PURE__*/Object.freeze({
15912
15933
  __proto__: null,
15913
15934
  BrowserCacheManager: BrowserCacheManager,
15914
15935
  BrowserConstants: BrowserConstants,
15915
- BrowserPerformanceClient: BrowserPerformanceClient,
15916
- BrowserPerformanceMeasurement: BrowserPerformanceMeasurement,
15917
15936
  CacheRecord: CacheRecord,
15918
15937
  CryptoOps: CryptoOps,
15919
15938
  EventHandler: EventHandler,
@@ -16131,8 +16150,9 @@
16131
16150
  const idToken = new AuthToken(response.id_token, this.cryptoObj);
16132
16151
  let cacheRecord;
16133
16152
  let authority;
16153
+ let cacheRecordAccount;
16134
16154
  if (request.account) {
16135
- const cacheRecordAccount = this.loadAccount(idToken, request.account.environment, undefined, undefined, request.account.homeAccountId);
16155
+ cacheRecordAccount = AccountEntity.createFromAccountInfo(request.account);
16136
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));
16137
16157
  }
16138
16158
  else if (request.authority) {
@@ -16148,12 +16168,12 @@
16148
16168
  // "clientInfo" from options takes precedence over "clientInfo" in response
16149
16169
  if (options.clientInfo) {
16150
16170
  this.logger.trace("TokenCache - homeAccountId from options");
16151
- const cacheRecordAccount = this.loadAccount(idToken, authority.hostnameAndPort, options.clientInfo, authority.authorityType);
16171
+ cacheRecordAccount = this.loadAccount(idToken, authority, options.clientInfo);
16152
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));
16153
16173
  }
16154
16174
  else if (response.client_info) {
16155
16175
  this.logger.trace("TokenCache - homeAccountId from response");
16156
- const cacheRecordAccount = this.loadAccount(idToken, authority.hostnameAndPort, response.client_info, authority.authorityType);
16176
+ cacheRecordAccount = this.loadAccount(idToken, authority, response.client_info);
16157
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));
16158
16178
  }
16159
16179
  else {
@@ -16163,7 +16183,7 @@
16163
16183
  else {
16164
16184
  throw BrowserAuthError.createUnableToLoadTokenError("Please provide a request with an account or a request with authority.");
16165
16185
  }
16166
- return this.generateAuthenticationResult(request, idToken, cacheRecord, authority);
16186
+ return this.generateAuthenticationResult(request, idToken, cacheRecord, cacheRecordAccount, authority);
16167
16187
  }
16168
16188
  /**
16169
16189
  * Helper function to load account to msal-browser cache
@@ -16174,20 +16194,23 @@
16174
16194
  * @param requestHomeAccountId
16175
16195
  * @returns `AccountEntity`
16176
16196
  */
16177
- loadAccount(idToken, environment, clientInfo, authorityType, requestHomeAccountId) {
16197
+ loadAccount(idToken, authority, clientInfo, requestHomeAccountId) {
16178
16198
  let homeAccountId;
16179
16199
  if (requestHomeAccountId) {
16180
16200
  homeAccountId = requestHomeAccountId;
16181
16201
  }
16182
- else if (authorityType !== undefined && clientInfo) {
16183
- 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);
16184
16204
  }
16185
16205
  if (!homeAccountId) {
16186
16206
  throw BrowserAuthError.createUnableToLoadTokenError("Unexpected missing homeAccountId");
16187
16207
  }
16188
- const accountEntity = clientInfo
16189
- ? AccountEntity.createAccount(clientInfo, homeAccountId, idToken, undefined, undefined, undefined, environment)
16190
- : 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);
16191
16214
  if (this.isBrowserEnvironment) {
16192
16215
  this.logger.verbose("TokenCache - loading account");
16193
16216
  this.storage.setAccount(accountEntity);
@@ -16281,7 +16304,7 @@
16281
16304
  * @param authority
16282
16305
  * @returns `AuthenticationResult`
16283
16306
  */
16284
- generateAuthenticationResult(request, idTokenObj, cacheRecord, authority) {
16307
+ generateAuthenticationResult(request, idTokenObj, cacheRecord, accountEntity, authority) {
16285
16308
  let accessToken = Constants.EMPTY_STRING;
16286
16309
  let responseScopes = [];
16287
16310
  let expiresOn = null;
@@ -16303,7 +16326,7 @@
16303
16326
  uniqueId: uid,
16304
16327
  tenantId: tid,
16305
16328
  scopes: responseScopes,
16306
- account: cacheRecord.account.getAccountInfo(),
16329
+ account: accountEntity.getAccountInfo(),
16307
16330
  idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,
16308
16331
  idTokenClaims: idTokenObj ? idTokenObj.claims : {},
16309
16332
  accessToken: accessToken,
@@ -16315,9 +16338,8 @@
16315
16338
  familyId: Constants.EMPTY_STRING,
16316
16339
  tokenType: cacheRecord?.accessToken?.tokenType || Constants.EMPTY_STRING,
16317
16340
  state: Constants.EMPTY_STRING,
16318
- cloudGraphHostName: cacheRecord?.account?.cloudGraphHostName ||
16319
- Constants.EMPTY_STRING,
16320
- msGraphHost: cacheRecord?.account?.msGraphHost || Constants.EMPTY_STRING,
16341
+ cloudGraphHostName: accountEntity.cloudGraphHostName || Constants.EMPTY_STRING,
16342
+ msGraphHost: accountEntity.msGraphHost || Constants.EMPTY_STRING,
16321
16343
  code: undefined,
16322
16344
  fromNativeBroker: false,
16323
16345
  };
@@ -16443,9 +16465,7 @@
16443
16465
  // Initial hybrid spa map
16444
16466
  this.hybridAuthCodeResponses = new Map();
16445
16467
  // Initialize performance client
16446
- this.performanceClient = this.isBrowserEnvironment
16447
- ? new BrowserPerformanceClient(this.config.auth.clientId, this.config.auth.authority, this.logger, name, version, this.config.telemetry.application)
16448
- : 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;
16449
16469
  // Initialize the crypto class.
16450
16470
  this.browserCrypto = this.isBrowserEnvironment
16451
16471
  ? new CryptoOps(this.logger, this.performanceClient)
@@ -16511,7 +16531,7 @@
16511
16531
  }
16512
16532
  this.initialized = true;
16513
16533
  this.eventHandler.emitEvent(EventType.INITIALIZE_END);
16514
- initMeasurement.endMeasurement({ allowNativeBroker, success: true });
16534
+ initMeasurement.end({ allowNativeBroker, success: true });
16515
16535
  }
16516
16536
  // #region Redirect Flow
16517
16537
  /**
@@ -16523,8 +16543,14 @@
16523
16543
  */
16524
16544
  async handleRedirectPromise(hash) {
16525
16545
  this.logger.verbose("handleRedirectPromise called");
16526
- // Block token acquisition before initialize has been called if native brokering is enabled
16527
- 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
+ }
16528
16554
  const loggedInAccounts = this.getAllAccounts();
16529
16555
  if (this.isBrowserEnvironment) {
16530
16556
  /**
@@ -16532,7 +16558,7 @@
16532
16558
  * otherwise return the promise from the first invocation. Prevents race conditions when handleRedirectPromise is called
16533
16559
  * several times concurrently.
16534
16560
  */
16535
- const redirectResponseKey = hash || Constants.EMPTY_STRING;
16561
+ const redirectResponseKey = foundServerResponse || Constants.EMPTY_STRING;
16536
16562
  let response = this.redirectResponse.get(redirectResponseKey);
16537
16563
  if (typeof response === "undefined") {
16538
16564
  this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, exports.InteractionType.Redirect);
@@ -16542,7 +16568,7 @@
16542
16568
  if (request &&
16543
16569
  NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeExtensionProvider) &&
16544
16570
  this.nativeExtensionProvider &&
16545
- !hash) {
16571
+ !foundServerResponse) {
16546
16572
  this.logger.trace("handleRedirectPromise - acquiring token from native platform");
16547
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);
16548
16574
  redirectResponse = nativeClient.handleRedirectPromise();
@@ -16552,7 +16578,7 @@
16552
16578
  const correlationId = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.CORRELATION_ID, true) || Constants.EMPTY_STRING;
16553
16579
  const redirectClient = this.createRedirectClient(correlationId);
16554
16580
  redirectResponse =
16555
- redirectClient.handleRedirectPromise(hash);
16581
+ redirectClient.handleRedirectPromise(foundServerResponse);
16556
16582
  }
16557
16583
  response = redirectResponse
16558
16584
  .then((result) => {
@@ -16683,7 +16709,7 @@
16683
16709
  result = this.acquireTokenNative(request, ApiId.acquireTokenPopup)
16684
16710
  .then((response) => {
16685
16711
  this.browserStorage.setInteractionInProgress(false);
16686
- atPopupMeasurement.endMeasurement({
16712
+ atPopupMeasurement.end({
16687
16713
  success: true,
16688
16714
  isNativeBroker: true,
16689
16715
  requestId: response.requestId,
@@ -16721,11 +16747,11 @@
16721
16747
  else {
16722
16748
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, exports.InteractionType.Popup, result);
16723
16749
  }
16724
- atPopupMeasurement.addStaticFields({
16750
+ atPopupMeasurement.add({
16725
16751
  accessTokenSize: result.accessToken.length,
16726
16752
  idTokenSize: result.idToken.length,
16727
16753
  });
16728
- atPopupMeasurement.endMeasurement({
16754
+ atPopupMeasurement.end({
16729
16755
  success: true,
16730
16756
  requestId: result.requestId,
16731
16757
  });
@@ -16738,7 +16764,7 @@
16738
16764
  else {
16739
16765
  this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, exports.InteractionType.Popup, null, e);
16740
16766
  }
16741
- atPopupMeasurement.endMeasurement({
16767
+ atPopupMeasurement.end({
16742
16768
  errorCode: e.errorCode,
16743
16769
  subErrorCode: e.subError,
16744
16770
  success: false,
@@ -16810,11 +16836,11 @@
16810
16836
  return result
16811
16837
  .then((response) => {
16812
16838
  this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, exports.InteractionType.Silent, response);
16813
- this.ssoSilentMeasurement?.addStaticFields({
16839
+ this.ssoSilentMeasurement?.add({
16814
16840
  accessTokenSize: response.accessToken.length,
16815
16841
  idTokenSize: response.idToken.length,
16816
16842
  });
16817
- this.ssoSilentMeasurement?.endMeasurement({
16843
+ this.ssoSilentMeasurement?.end({
16818
16844
  success: true,
16819
16845
  isNativeBroker: response.fromNativeBroker,
16820
16846
  requestId: response.requestId,
@@ -16823,7 +16849,7 @@
16823
16849
  })
16824
16850
  .catch((e) => {
16825
16851
  this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, exports.InteractionType.Silent, null, e);
16826
- this.ssoSilentMeasurement?.endMeasurement({
16852
+ this.ssoSilentMeasurement?.end({
16827
16853
  errorCode: e.errorCode,
16828
16854
  subErrorCode: e.subError,
16829
16855
  success: false,
@@ -16867,11 +16893,11 @@
16867
16893
  .then((result) => {
16868
16894
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, exports.InteractionType.Silent, result);
16869
16895
  this.hybridAuthCodeResponses.delete(hybridAuthCode);
16870
- atbcMeasurement.addStaticFields({
16896
+ atbcMeasurement.add({
16871
16897
  accessTokenSize: result.accessToken.length,
16872
16898
  idTokenSize: result.idToken.length,
16873
16899
  });
16874
- atbcMeasurement.endMeasurement({
16900
+ atbcMeasurement.end({
16875
16901
  success: true,
16876
16902
  isNativeBroker: result.fromNativeBroker,
16877
16903
  requestId: result.requestId,
@@ -16881,7 +16907,7 @@
16881
16907
  .catch((error) => {
16882
16908
  this.hybridAuthCodeResponses.delete(hybridAuthCode);
16883
16909
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, exports.InteractionType.Silent, null, error);
16884
- atbcMeasurement.endMeasurement({
16910
+ atbcMeasurement.end({
16885
16911
  errorCode: error.errorCode,
16886
16912
  subErrorCode: error.subError,
16887
16913
  success: false,
@@ -16892,7 +16918,7 @@
16892
16918
  }
16893
16919
  else {
16894
16920
  this.logger.verbose("Existing acquireTokenByCode request found", request.correlationId);
16895
- atbcMeasurement.discardMeasurement();
16921
+ atbcMeasurement.discard();
16896
16922
  }
16897
16923
  return response;
16898
16924
  }
@@ -16916,7 +16942,7 @@
16916
16942
  }
16917
16943
  catch (e) {
16918
16944
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, exports.InteractionType.Silent, null, e);
16919
- atbcMeasurement.endMeasurement({
16945
+ atbcMeasurement.end({
16920
16946
  errorCode: (e instanceof AuthError && e.errorCode) || undefined,
16921
16947
  subErrorCode: (e instanceof AuthError && e.subError) || undefined,
16922
16948
  success: false,
@@ -16941,7 +16967,7 @@
16941
16967
  const silentTokenResult = await silentAuthCodeClient
16942
16968
  .acquireToken(request)
16943
16969
  .then((response) => {
16944
- this.acquireTokenByCodeAsyncMeasurement?.endMeasurement({
16970
+ this.acquireTokenByCodeAsyncMeasurement?.end({
16945
16971
  success: true,
16946
16972
  fromCache: response.fromCache,
16947
16973
  isNativeBroker: response.fromNativeBroker,
@@ -16950,7 +16976,7 @@
16950
16976
  return response;
16951
16977
  })
16952
16978
  .catch((tokenRenewalError) => {
16953
- this.acquireTokenByCodeAsyncMeasurement?.endMeasurement({
16979
+ this.acquireTokenByCodeAsyncMeasurement?.end({
16954
16980
  errorCode: tokenRenewalError.errorCode,
16955
16981
  subErrorCode: tokenRenewalError.subError,
16956
16982
  success: false,
@@ -17160,6 +17186,26 @@
17160
17186
  return this.browserStorage.getActiveAccount();
17161
17187
  }
17162
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
+ }
17163
17209
  // #region Helpers
17164
17210
  /**
17165
17211
  * Helper to validate app environment before making an auth request
@@ -17178,13 +17224,8 @@
17178
17224
  BrowserUtils.blockReloadInHiddenIframes();
17179
17225
  // Block redirectUri opened in a popup from calling MSAL APIs
17180
17226
  BrowserUtils.blockAcquireTokenInPopups();
17181
- /*
17182
- * Block token acquisition before initialize has been called if native brokering is enabled in top-frame.
17183
- * Skip check if application is embedded.
17184
- */
17185
- if (!isAppEmbedded) {
17186
- BrowserUtils.blockNativeBrokerCalledBeforeInitialized(this.config.system.allowNativeBroker, this.initialized);
17187
- }
17227
+ // Block token acquisition before initialize has been called
17228
+ BrowserUtils.blockAPICallsBeforeInitialize(this.initialized);
17188
17229
  // Block redirects if memory storage is enabled but storeAuthStateInCookie is not
17189
17230
  if (interactionType === exports.InteractionType.Redirect &&
17190
17231
  this.config.cache.cacheLocation ===
@@ -17510,7 +17551,7 @@
17510
17551
  async acquireTokenSilent(request) {
17511
17552
  const correlationId = this.getRequestCorrelationId(request);
17512
17553
  const atsMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenSilent, correlationId);
17513
- atsMeasurement.addStaticFields({
17554
+ atsMeasurement.add({
17514
17555
  cacheLookupPolicy: request.cacheLookupPolicy,
17515
17556
  });
17516
17557
  this.preflightBrowserEnvironmentCheck(exports.InteractionType.Silent);
@@ -17542,11 +17583,11 @@
17542
17583
  }, account)
17543
17584
  .then((result) => {
17544
17585
  this.activeSilentTokenRequests.delete(silentRequestKey);
17545
- atsMeasurement.addStaticFields({
17586
+ atsMeasurement.add({
17546
17587
  accessTokenSize: result.accessToken.length,
17547
17588
  idTokenSize: result.idToken.length,
17548
17589
  });
17549
- atsMeasurement.endMeasurement({
17590
+ atsMeasurement.end({
17550
17591
  success: true,
17551
17592
  fromCache: result.fromCache,
17552
17593
  isNativeBroker: result.fromNativeBroker,
@@ -17557,7 +17598,7 @@
17557
17598
  })
17558
17599
  .catch((error) => {
17559
17600
  this.activeSilentTokenRequests.delete(silentRequestKey);
17560
- atsMeasurement.endMeasurement({
17601
+ atsMeasurement.end({
17561
17602
  errorCode: error.errorCode,
17562
17603
  subErrorCode: error.subError,
17563
17604
  success: false,
@@ -17570,7 +17611,7 @@
17570
17611
  else {
17571
17612
  this.logger.verbose("acquireTokenSilent has been called previously, returning the result from the first call", correlationId);
17572
17613
  // Discard measurements for memoized calls, as they are usually only a couple of ms and will artificially deflate metrics
17573
- atsMeasurement.discardMeasurement();
17614
+ atsMeasurement.discard();
17574
17615
  return cachedResponse;
17575
17616
  }
17576
17617
  }
@@ -17654,7 +17695,7 @@
17654
17695
  return result
17655
17696
  .then((response) => {
17656
17697
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, exports.InteractionType.Silent, response);
17657
- this.atsAsyncMeasurement?.endMeasurement({
17698
+ this.atsAsyncMeasurement?.end({
17658
17699
  success: true,
17659
17700
  fromCache: response.fromCache,
17660
17701
  isNativeBroker: response.fromNativeBroker,
@@ -17664,7 +17705,7 @@
17664
17705
  })
17665
17706
  .catch((tokenRenewalError) => {
17666
17707
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, exports.InteractionType.Silent, null, tokenRenewalError);
17667
- this.atsAsyncMeasurement?.endMeasurement({
17708
+ this.atsAsyncMeasurement?.end({
17668
17709
  errorCode: tokenRenewalError.errorCode,
17669
17710
  subErrorCode: tokenRenewalError.subError,
17670
17711
  success: false,
@@ -17988,6 +18029,15 @@
17988
18029
  getConfiguration() {
17989
18030
  return this.controller.getConfiguration();
17990
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
+ }
17991
18041
  }
17992
18042
 
17993
18043
  /*
@@ -18085,6 +18135,9 @@
18085
18135
  getConfiguration: () => {
18086
18136
  throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();
18087
18137
  },
18138
+ hydrateCache: () => {
18139
+ return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());
18140
+ },
18088
18141
  };
18089
18142
 
18090
18143
  /*
@@ -18196,6 +18249,227 @@
18196
18249
  }
18197
18250
  }
18198
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
+
18199
18473
  exports.AccountEntity = AccountEntity;
18200
18474
  exports.ApiId = ApiId;
18201
18475
  exports.AuthError = AuthError;
@@ -18208,6 +18482,8 @@
18208
18482
  exports.BrowserCacheLocation = BrowserCacheLocation;
18209
18483
  exports.BrowserConfigurationAuthError = BrowserConfigurationAuthError;
18210
18484
  exports.BrowserConfigurationAuthErrorMessage = BrowserConfigurationAuthErrorMessage;
18485
+ exports.BrowserPerformanceClient = BrowserPerformanceClient;
18486
+ exports.BrowserPerformanceMeasurement = BrowserPerformanceMeasurement;
18211
18487
  exports.BrowserUtils = BrowserUtils;
18212
18488
  exports.CacheLookupPolicy = CacheLookupPolicy;
18213
18489
  exports.ClientAuthError = ClientAuthError;
@@ -18228,6 +18504,7 @@
18228
18504
  exports.ProtocolMode = ProtocolMode;
18229
18505
  exports.PublicClientApplication = PublicClientApplication;
18230
18506
  exports.ServerError = ServerError;
18507
+ exports.ServerResponseType = ServerResponseType;
18231
18508
  exports.SignedHttpRequest = SignedHttpRequest;
18232
18509
  exports.StringUtils = StringUtils;
18233
18510
  exports.UrlString = UrlString;