@azure/msal-common 14.0.0-beta.1 → 14.0.1

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 (241) hide show
  1. package/README.md +14 -23
  2. package/dist/account/AccountInfo.d.ts +1 -0
  3. package/dist/account/AccountInfo.d.ts.map +1 -1
  4. package/dist/account/{AuthToken.js → AuthToken.mjs} +4 -4
  5. package/dist/account/AuthToken.mjs.map +1 -0
  6. package/dist/account/CcsCredential.d.ts +1 -1
  7. package/dist/account/CcsCredential.d.ts.map +1 -1
  8. package/dist/account/{CcsCredential.js → CcsCredential.mjs} +2 -2
  9. package/dist/account/CcsCredential.mjs.map +1 -0
  10. package/dist/account/{ClientInfo.js → ClientInfo.mjs} +5 -5
  11. package/dist/account/ClientInfo.mjs.map +1 -0
  12. package/dist/authority/Authority.d.ts +6 -1
  13. package/dist/authority/Authority.d.ts.map +1 -1
  14. package/dist/authority/{Authority.js → Authority.mjs} +132 -74
  15. package/dist/authority/Authority.mjs.map +1 -0
  16. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  17. package/dist/authority/{AuthorityFactory.js → AuthorityFactory.mjs} +7 -7
  18. package/dist/authority/AuthorityFactory.mjs.map +1 -0
  19. package/dist/authority/AuthorityMetadata.d.ts +1 -0
  20. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  21. package/dist/authority/{AuthorityMetadata.js → AuthorityMetadata.mjs} +11 -3
  22. package/dist/authority/AuthorityMetadata.mjs.map +1 -0
  23. package/dist/authority/AuthorityOptions.d.ts +3 -1
  24. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  25. package/dist/authority/{AuthorityOptions.js → AuthorityOptions.mjs} +4 -4
  26. package/dist/authority/AuthorityOptions.mjs.map +1 -0
  27. package/dist/authority/AuthorityType.d.ts +1 -1
  28. package/dist/authority/AuthorityType.d.ts.map +1 -1
  29. package/dist/authority/{AuthorityType.js → AuthorityType.mjs} +3 -3
  30. package/dist/authority/AuthorityType.mjs.map +1 -0
  31. package/dist/authority/{CloudInstanceDiscoveryErrorResponse.js → CloudInstanceDiscoveryErrorResponse.mjs} +2 -2
  32. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -0
  33. package/dist/authority/{CloudInstanceDiscoveryResponse.js → CloudInstanceDiscoveryResponse.mjs} +2 -2
  34. package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -0
  35. package/dist/authority/OIDCOptions.d.ts +9 -0
  36. package/dist/authority/OIDCOptions.d.ts.map +1 -0
  37. package/dist/authority/{OpenIdConfigResponse.js → OpenIdConfigResponse.mjs} +2 -2
  38. package/dist/authority/OpenIdConfigResponse.mjs.map +1 -0
  39. package/dist/authority/ProtocolMode.d.ts +1 -1
  40. package/dist/authority/ProtocolMode.d.ts.map +1 -1
  41. package/dist/authority/{ProtocolMode.js → ProtocolMode.mjs} +2 -2
  42. package/dist/authority/ProtocolMode.mjs.map +1 -0
  43. package/dist/authority/{RegionDiscovery.js → RegionDiscovery.mjs} +4 -4
  44. package/dist/authority/RegionDiscovery.mjs.map +1 -0
  45. package/dist/cache/CacheManager.d.ts +2 -1
  46. package/dist/cache/CacheManager.d.ts.map +1 -1
  47. package/dist/cache/{CacheManager.js → CacheManager.mjs} +24 -15
  48. package/dist/cache/CacheManager.mjs.map +1 -0
  49. package/dist/cache/entities/{AccessTokenEntity.js → AccessTokenEntity.mjs} +8 -8
  50. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -0
  51. package/dist/cache/entities/AccountEntity.d.ts +18 -17
  52. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  53. package/dist/cache/entities/{AccountEntity.js → AccountEntity.mjs} +65 -92
  54. package/dist/cache/entities/AccountEntity.mjs.map +1 -0
  55. package/dist/cache/entities/{AppMetadataEntity.js → AppMetadataEntity.mjs} +3 -3
  56. package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -0
  57. package/dist/cache/entities/{AuthorityMetadataEntity.js → AuthorityMetadataEntity.mjs} +4 -4
  58. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -0
  59. package/dist/cache/entities/{CacheRecord.js → CacheRecord.mjs} +2 -2
  60. package/dist/cache/entities/CacheRecord.mjs.map +1 -0
  61. package/dist/cache/entities/{CredentialEntity.js → CredentialEntity.mjs} +4 -4
  62. package/dist/cache/entities/CredentialEntity.mjs.map +1 -0
  63. package/dist/cache/entities/{IdTokenEntity.js → IdTokenEntity.mjs} +4 -4
  64. package/dist/cache/entities/IdTokenEntity.mjs.map +1 -0
  65. package/dist/cache/entities/{RefreshTokenEntity.js → RefreshTokenEntity.mjs} +4 -4
  66. package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -0
  67. package/dist/cache/entities/{ServerTelemetryEntity.js → ServerTelemetryEntity.mjs} +3 -3
  68. package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -0
  69. package/dist/cache/entities/{ThrottlingEntity.js → ThrottlingEntity.mjs} +3 -3
  70. package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -0
  71. package/dist/cache/interface/ICacheManager.d.ts +2 -1
  72. package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
  73. package/dist/cache/persistence/{TokenCacheContext.js → TokenCacheContext.mjs} +2 -2
  74. package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -0
  75. package/dist/client/AuthorizationCodeClient.d.ts +1 -0
  76. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  77. package/dist/client/{AuthorizationCodeClient.js → AuthorizationCodeClient.mjs} +34 -29
  78. package/dist/client/AuthorizationCodeClient.mjs.map +1 -0
  79. package/dist/client/{BaseClient.js → BaseClient.mjs} +11 -11
  80. package/dist/client/BaseClient.mjs.map +1 -0
  81. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  82. package/dist/client/{RefreshTokenClient.js → RefreshTokenClient.mjs} +30 -29
  83. package/dist/client/RefreshTokenClient.mjs.map +1 -0
  84. package/dist/client/{SilentFlowClient.js → SilentFlowClient.mjs} +11 -11
  85. package/dist/client/SilentFlowClient.mjs.map +1 -0
  86. package/dist/config/ClientConfiguration.d.ts +5 -0
  87. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  88. package/dist/config/{ClientConfiguration.js → ClientConfiguration.mjs} +18 -10
  89. package/dist/config/ClientConfiguration.mjs.map +1 -0
  90. package/dist/crypto/{ICrypto.js → ICrypto.mjs} +3 -3
  91. package/dist/crypto/ICrypto.mjs.map +1 -0
  92. package/dist/crypto/{JoseHeader.js → JoseHeader.mjs} +4 -4
  93. package/dist/crypto/JoseHeader.mjs.map +1 -0
  94. package/dist/crypto/PopTokenGenerator.d.ts +1 -1
  95. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  96. package/dist/crypto/{PopTokenGenerator.js → PopTokenGenerator.mjs} +5 -5
  97. package/dist/crypto/PopTokenGenerator.mjs.map +1 -0
  98. package/dist/error/{AuthError.js → AuthError.mjs} +3 -3
  99. package/dist/error/AuthError.mjs.map +1 -0
  100. package/dist/error/{ClientAuthError.js → ClientAuthError.mjs} +3 -3
  101. package/dist/error/ClientAuthError.mjs.map +1 -0
  102. package/dist/error/ClientConfigurationError.d.ts +16 -0
  103. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  104. package/dist/error/{ClientConfigurationError.js → ClientConfigurationError.mjs} +26 -6
  105. package/dist/error/ClientConfigurationError.mjs.map +1 -0
  106. package/dist/error/{InteractionRequiredAuthError.js → InteractionRequiredAuthError.mjs} +4 -4
  107. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -0
  108. package/dist/error/{JoseHeaderError.js → JoseHeaderError.mjs} +3 -3
  109. package/dist/error/JoseHeaderError.mjs.map +1 -0
  110. package/dist/error/{ServerError.js → ServerError.mjs} +3 -3
  111. package/dist/error/ServerError.mjs.map +1 -0
  112. package/dist/{index.cjs.js → index.cjs} +420 -262
  113. package/dist/index.cjs.map +1 -0
  114. package/dist/index.d.ts +4 -2
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.mjs +54 -0
  117. package/dist/index.mjs.map +1 -0
  118. package/dist/logger/{Logger.js → Logger.mjs} +4 -4
  119. package/dist/logger/Logger.mjs.map +1 -0
  120. package/dist/network/{INetworkModule.js → INetworkModule.mjs} +3 -3
  121. package/dist/network/INetworkModule.mjs.map +1 -0
  122. package/dist/network/{NetworkManager.js → NetworkManager.mjs} +5 -5
  123. package/dist/network/NetworkManager.mjs.map +1 -0
  124. package/dist/network/{ThrottlingUtils.js → ThrottlingUtils.mjs} +4 -4
  125. package/dist/network/ThrottlingUtils.mjs.map +1 -0
  126. package/dist/packageMetadata.d.ts +1 -1
  127. package/dist/packageMetadata.d.ts.map +1 -1
  128. package/dist/packageMetadata.mjs +8 -0
  129. package/dist/packageMetadata.mjs.map +1 -0
  130. package/dist/request/{AuthenticationHeaderParser.js → AuthenticationHeaderParser.mjs} +4 -4
  131. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -0
  132. package/dist/request/BaseAuthRequest.d.ts +3 -0
  133. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  134. package/dist/request/RequestParameterBuilder.d.ts +1 -1
  135. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  136. package/dist/request/{RequestParameterBuilder.js → RequestParameterBuilder.mjs} +15 -9
  137. package/dist/request/RequestParameterBuilder.mjs.map +1 -0
  138. package/dist/request/{RequestValidator.js → RequestValidator.mjs} +6 -6
  139. package/dist/request/RequestValidator.mjs.map +1 -0
  140. package/dist/request/{ScopeSet.js → ScopeSet.mjs} +6 -6
  141. package/dist/request/ScopeSet.mjs.map +1 -0
  142. package/dist/request/StoreInCache.d.ts +9 -0
  143. package/dist/request/StoreInCache.d.ts.map +1 -0
  144. package/dist/response/ResponseHandler.d.ts +0 -7
  145. package/dist/response/ResponseHandler.d.ts.map +1 -1
  146. package/dist/response/{ResponseHandler.js → ResponseHandler.mjs} +47 -57
  147. package/dist/response/ResponseHandler.mjs.map +1 -0
  148. package/dist/telemetry/performance/IPerformanceClient.d.ts +16 -7
  149. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  150. package/dist/telemetry/performance/PerformanceClient.d.ts +14 -12
  151. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  152. package/dist/telemetry/performance/{PerformanceClient.js → PerformanceClient.mjs} +27 -25
  153. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -0
  154. package/dist/telemetry/performance/PerformanceEvent.d.ts +80 -95
  155. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  156. package/dist/telemetry/performance/{PerformanceEvent.js → PerformanceEvent.mjs} +3 -2
  157. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -0
  158. package/dist/telemetry/performance/StubPerformanceClient.d.ts +9 -0
  159. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  160. package/dist/telemetry/performance/StubPerformanceClient.mjs +63 -0
  161. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -0
  162. package/dist/telemetry/server/{ServerTelemetryManager.js → ServerTelemetryManager.mjs} +6 -6
  163. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -0
  164. package/dist/url/UrlString.d.ts +13 -0
  165. package/dist/url/UrlString.d.ts.map +1 -1
  166. package/dist/url/{UrlString.js → UrlString.mjs} +45 -6
  167. package/dist/url/UrlString.mjs.map +1 -0
  168. package/dist/utils/Constants.d.ts +29 -21
  169. package/dist/utils/Constants.d.ts.map +1 -1
  170. package/dist/utils/{Constants.js → Constants.mjs} +11 -5
  171. package/dist/utils/Constants.mjs.map +1 -0
  172. package/dist/utils/{ProtocolUtils.js → ProtocolUtils.mjs} +5 -5
  173. package/dist/utils/ProtocolUtils.mjs.map +1 -0
  174. package/dist/utils/{StringUtils.js → StringUtils.mjs} +3 -3
  175. package/dist/utils/StringUtils.mjs.map +1 -0
  176. package/dist/utils/{TimeUtils.js → TimeUtils.mjs} +2 -2
  177. package/dist/utils/TimeUtils.mjs.map +1 -0
  178. package/package.json +12 -5
  179. package/dist/account/AuthToken.js.map +0 -1
  180. package/dist/account/CcsCredential.js.map +0 -1
  181. package/dist/account/ClientInfo.js.map +0 -1
  182. package/dist/authority/Authority.js.map +0 -1
  183. package/dist/authority/AuthorityFactory.js.map +0 -1
  184. package/dist/authority/AuthorityMetadata.js.map +0 -1
  185. package/dist/authority/AuthorityOptions.js.map +0 -1
  186. package/dist/authority/AuthorityType.js.map +0 -1
  187. package/dist/authority/CloudInstanceDiscoveryErrorResponse.js.map +0 -1
  188. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +0 -1
  189. package/dist/authority/OpenIdConfigResponse.js.map +0 -1
  190. package/dist/authority/ProtocolMode.js.map +0 -1
  191. package/dist/authority/RegionDiscovery.js.map +0 -1
  192. package/dist/cache/CacheManager.js.map +0 -1
  193. package/dist/cache/entities/AccessTokenEntity.js.map +0 -1
  194. package/dist/cache/entities/AccountEntity.js.map +0 -1
  195. package/dist/cache/entities/AppMetadataEntity.js.map +0 -1
  196. package/dist/cache/entities/AuthorityMetadataEntity.js.map +0 -1
  197. package/dist/cache/entities/CacheRecord.js.map +0 -1
  198. package/dist/cache/entities/CredentialEntity.js.map +0 -1
  199. package/dist/cache/entities/IdTokenEntity.js.map +0 -1
  200. package/dist/cache/entities/RefreshTokenEntity.js.map +0 -1
  201. package/dist/cache/entities/ServerTelemetryEntity.js.map +0 -1
  202. package/dist/cache/entities/ThrottlingEntity.js.map +0 -1
  203. package/dist/cache/persistence/TokenCacheContext.js.map +0 -1
  204. package/dist/client/AuthorizationCodeClient.js.map +0 -1
  205. package/dist/client/BaseClient.js.map +0 -1
  206. package/dist/client/RefreshTokenClient.js.map +0 -1
  207. package/dist/client/SilentFlowClient.js.map +0 -1
  208. package/dist/config/ClientConfiguration.js.map +0 -1
  209. package/dist/crypto/ICrypto.js.map +0 -1
  210. package/dist/crypto/JoseHeader.js.map +0 -1
  211. package/dist/crypto/PopTokenGenerator.js.map +0 -1
  212. package/dist/error/AuthError.js.map +0 -1
  213. package/dist/error/ClientAuthError.js.map +0 -1
  214. package/dist/error/ClientConfigurationError.js.map +0 -1
  215. package/dist/error/InteractionRequiredAuthError.js.map +0 -1
  216. package/dist/error/JoseHeaderError.js.map +0 -1
  217. package/dist/error/ServerError.js.map +0 -1
  218. package/dist/index.cjs.js.map +0 -1
  219. package/dist/index.js +0 -54
  220. package/dist/index.js.map +0 -1
  221. package/dist/logger/Logger.js.map +0 -1
  222. package/dist/network/INetworkModule.js.map +0 -1
  223. package/dist/network/NetworkManager.js.map +0 -1
  224. package/dist/network/ThrottlingUtils.js.map +0 -1
  225. package/dist/packageMetadata.js +0 -8
  226. package/dist/packageMetadata.js.map +0 -1
  227. package/dist/request/AuthenticationHeaderParser.js.map +0 -1
  228. package/dist/request/RequestParameterBuilder.js.map +0 -1
  229. package/dist/request/RequestValidator.js.map +0 -1
  230. package/dist/request/ScopeSet.js.map +0 -1
  231. package/dist/response/ResponseHandler.js.map +0 -1
  232. package/dist/telemetry/performance/PerformanceClient.js.map +0 -1
  233. package/dist/telemetry/performance/PerformanceEvent.js.map +0 -1
  234. package/dist/telemetry/performance/StubPerformanceClient.js +0 -29
  235. package/dist/telemetry/performance/StubPerformanceClient.js.map +0 -1
  236. package/dist/telemetry/server/ServerTelemetryManager.js.map +0 -1
  237. package/dist/url/UrlString.js.map +0 -1
  238. package/dist/utils/Constants.js.map +0 -1
  239. package/dist/utils/ProtocolUtils.js.map +0 -1
  240. package/dist/utils/StringUtils.js.map +0 -1
  241. package/dist/utils/TimeUtils.js.map +0 -1
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.0.0-beta.1 2023-07-06 */
1
+ /*! @azure/msal-common v14.0.1 2023-08-11 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -198,11 +198,17 @@ const CodeChallengeMethodValues = {
198
198
  S256: "S256",
199
199
  };
200
200
  /**
201
- * allowed values for response_mode
201
+ * allowed values for server response type
202
202
  */
203
- const ResponseMode = {
203
+ const ServerResponseType = {
204
204
  QUERY: "query",
205
205
  FRAGMENT: "fragment",
206
+ };
207
+ /**
208
+ * allowed values for response_mode
209
+ */
210
+ const ResponseMode = {
211
+ ...ServerResponseType,
206
212
  FORM_POST: "form_post",
207
213
  };
208
214
  /**
@@ -1296,7 +1302,7 @@ class Logger {
1296
1302
 
1297
1303
  /* eslint-disable header/header */
1298
1304
  const name = "@azure/msal-common";
1299
- const version = "14.0.0-beta.1";
1305
+ const version = "14.0.1";
1300
1306
 
1301
1307
  /*
1302
1308
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1309,9 +1315,9 @@ const AzureCloudInstance = {
1309
1315
  AzurePublic: "https://login.microsoftonline.com",
1310
1316
  // Microsoft PPE
1311
1317
  AzurePpe: "https://login.windows-ppe.net",
1312
- // Microsoft Chinese national cloud
1318
+ // Microsoft Chinese national/regional cloud
1313
1319
  AzureChina: "https://login.chinacloudapi.cn",
1314
- // Microsoft German national cloud ("Black Forest")
1320
+ // Microsoft German national/regional cloud ("Black Forest")
1315
1321
  AzureGermany: "https://login.microsoftonline.de",
1316
1322
  // US Government cloud
1317
1323
  AzureUsGovernment: "https://login.microsoftonline.us",
@@ -1415,12 +1421,20 @@ const ClientConfigurationErrorMessage = {
1415
1421
  },
1416
1422
  invalidAuthenticationHeader: {
1417
1423
  code: "invalid_authentication_header",
1418
- desc: "Invalid authentication header provided"
1424
+ desc: "Invalid authentication header provided",
1425
+ },
1426
+ cannotSetOIDCOptions: {
1427
+ code: "cannot_set_OIDCOptions",
1428
+ desc: "Cannot set OIDCOptions parameter. Please change the protocol mode to OIDC or use a non-Microsoft authority.",
1429
+ },
1430
+ cannotAllowNativeBroker: {
1431
+ code: "cannot_allow_native_broker",
1432
+ desc: "Cannot set allowNativeBroker parameter to true when not in AAD protocol mode.",
1419
1433
  },
1420
1434
  authorityMismatch: {
1421
1435
  code: "authority_mismatch",
1422
- 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."
1423
- }
1436
+ 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.",
1437
+ },
1424
1438
  };
1425
1439
  /**
1426
1440
  * Error thrown when there is an error in configuration of the MSAL.js library.
@@ -1569,6 +1583,18 @@ class ClientConfigurationError extends ClientAuthError {
1569
1583
  static createInvalidAuthenticationHeaderError(invalidHeaderName, details) {
1570
1584
  return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthenticationHeader.code, `${ClientConfigurationErrorMessage.invalidAuthenticationHeader.desc}. Invalid header: ${invalidHeaderName}. Details: ${details}`);
1571
1585
  }
1586
+ /**
1587
+ * Throws error when provided non-default OIDCOptions when not in OIDC protocol mode
1588
+ */
1589
+ static createCannotSetOIDCOptionsError() {
1590
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.cannotSetOIDCOptions.code, ClientConfigurationErrorMessage.cannotSetOIDCOptions.desc);
1591
+ }
1592
+ /**
1593
+ * Throws error when allowNativeBroker is set to true when not in AAD protocol mode
1594
+ */
1595
+ static createCannotAllowNativeBrokerError() {
1596
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.cannotAllowNativeBroker.code, ClientConfigurationErrorMessage.cannotAllowNativeBroker.desc);
1597
+ }
1572
1598
  /**
1573
1599
  * Create an error when the authority provided in request does not match authority provided in account or MSAL.js configuration.
1574
1600
  */
@@ -1824,7 +1850,19 @@ const AuthorityType = {
1824
1850
  Default: 0,
1825
1851
  Adfs: 1,
1826
1852
  Dsts: 2,
1827
- Ciam: 3
1853
+ Ciam: 3,
1854
+ };
1855
+
1856
+ /*
1857
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1858
+ * Licensed under the MIT License.
1859
+ */
1860
+ /**
1861
+ * Protocol modes supported by MSAL.
1862
+ */
1863
+ const ProtocolMode = {
1864
+ AAD: "AAD",
1865
+ OIDC: "OIDC",
1828
1866
  };
1829
1867
 
1830
1868
  /*
@@ -1847,7 +1885,6 @@ const AuthorityType = {
1847
1885
  * username: primary username that represents the user, usually corresponds to preferred_username in the v2 endpt
1848
1886
  * authorityType: Accounts authority type as a string
1849
1887
  * name: Full name for the account, including given name and family name,
1850
- * clientInfo: Full base64 encoded client info received from ESTS
1851
1888
  * lastModificationTime: last time this entity was modified in the cache
1852
1889
  * lastModificationApp:
1853
1890
  * idTokenClaims: Object containing claims parsed from ID token
@@ -1874,24 +1911,6 @@ class AccountEntity {
1874
1911
  localAccountId: this.localAccountId,
1875
1912
  });
1876
1913
  }
1877
- /**
1878
- * returns the type of the cache (in this case account)
1879
- */
1880
- generateType() {
1881
- switch (this.authorityType) {
1882
- case CacheAccountType.ADFS_ACCOUNT_TYPE:
1883
- return CacheType.ADFS;
1884
- case CacheAccountType.MSAV1_ACCOUNT_TYPE:
1885
- return CacheType.MSA;
1886
- case CacheAccountType.MSSTS_ACCOUNT_TYPE:
1887
- return CacheType.MSSTS;
1888
- case CacheAccountType.GENERIC_ACCOUNT_TYPE:
1889
- return CacheType.GENERIC;
1890
- default: {
1891
- throw ClientAuthError.createUnexpectedAccountTypeError();
1892
- }
1893
- }
1894
- }
1895
1914
  /**
1896
1915
  * Returns the AccountInfo interface for this account.
1897
1916
  */
@@ -1905,6 +1924,7 @@ class AccountEntity {
1905
1924
  name: this.name,
1906
1925
  idTokenClaims: this.idTokenClaims,
1907
1926
  nativeAccountId: this.nativeAccountId,
1927
+ authorityType: this.authorityType,
1908
1928
  };
1909
1929
  }
1910
1930
  /**
@@ -1921,84 +1941,74 @@ class AccountEntity {
1921
1941
  }
1922
1942
  /**
1923
1943
  * Build Account cache from IdToken, clientInfo and authority/policy. Associated with AAD.
1924
- * @param clientInfo
1925
- * @param authority
1926
- * @param idToken
1927
- * @param policy
1944
+ * @param accountDetails
1928
1945
  */
1929
- static createAccount(clientInfo, homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
1946
+ static createAccount(accountDetails, authority) {
1930
1947
  const account = new AccountEntity();
1931
- account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE;
1932
- account.clientInfo = clientInfo;
1933
- account.homeAccountId = homeAccountId;
1934
- account.nativeAccountId = nativeAccountId;
1935
- const env = environment || (authority && authority.getPreferredCache());
1948
+ if (authority.authorityType === AuthorityType.Adfs) {
1949
+ account.authorityType = CacheAccountType.ADFS_ACCOUNT_TYPE;
1950
+ }
1951
+ else if (authority.protocolMode === ProtocolMode.AAD) {
1952
+ account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE;
1953
+ }
1954
+ else {
1955
+ account.authorityType = CacheAccountType.GENERIC_ACCOUNT_TYPE;
1956
+ }
1957
+ account.clientInfo = accountDetails.clientInfo;
1958
+ account.homeAccountId = accountDetails.homeAccountId;
1959
+ account.nativeAccountId = accountDetails.nativeAccountId;
1960
+ const env = accountDetails.environment ||
1961
+ (authority && authority.getPreferredCache());
1936
1962
  if (!env) {
1937
1963
  throw ClientAuthError.createInvalidCacheEnvironmentError();
1938
1964
  }
1939
1965
  account.environment = env;
1940
1966
  // non AAD scenarios can have empty realm
1941
- account.realm = idToken?.claims?.tid || Constants.EMPTY_STRING;
1942
- if (idToken) {
1943
- account.idTokenClaims = idToken.claims;
1944
- // How do you account for MSA CID here?
1945
- account.localAccountId =
1946
- idToken?.claims?.oid ||
1947
- idToken?.claims?.sub ||
1948
- Constants.EMPTY_STRING;
1949
- /*
1950
- * In B2C scenarios the emails claim is used instead of preferred_username and it is an array.
1951
- * In most cases it will contain a single email. This field should not be relied upon if a custom
1952
- * policy is configured to return more than 1 email.
1953
- */
1954
- const preferredUsername = idToken?.claims?.preferred_username;
1955
- const email = idToken?.claims?.emails
1956
- ? idToken.claims.emails[0]
1957
- : null;
1958
- account.username =
1959
- preferredUsername || email || Constants.EMPTY_STRING;
1960
- account.name = idToken?.claims?.name;
1961
- }
1962
- account.cloudGraphHostName = cloudGraphHostName;
1963
- account.msGraphHost = msGraphHost;
1967
+ account.realm =
1968
+ accountDetails.idTokenClaims.tid || Constants.EMPTY_STRING;
1969
+ account.idTokenClaims = accountDetails.idTokenClaims;
1970
+ // How do you account for MSA CID here?
1971
+ account.localAccountId =
1972
+ accountDetails.idTokenClaims.oid ||
1973
+ accountDetails.idTokenClaims.sub ||
1974
+ Constants.EMPTY_STRING;
1975
+ /*
1976
+ * In B2C scenarios the emails claim is used instead of preferred_username and it is an array.
1977
+ * In most cases it will contain a single email. This field should not be relied upon if a custom
1978
+ * policy is configured to return more than 1 email.
1979
+ */
1980
+ const preferredUsername = accountDetails.idTokenClaims.preferred_username ||
1981
+ accountDetails.idTokenClaims.upn;
1982
+ const email = accountDetails.idTokenClaims.emails
1983
+ ? accountDetails.idTokenClaims.emails[0]
1984
+ : null;
1985
+ account.username = preferredUsername || email || Constants.EMPTY_STRING;
1986
+ account.name = accountDetails.idTokenClaims.name;
1987
+ account.cloudGraphHostName = accountDetails.cloudGraphHostName;
1988
+ account.msGraphHost = accountDetails.msGraphHost;
1964
1989
  return account;
1965
1990
  }
1966
1991
  /**
1967
- * Builds non-AAD/ADFS account.
1968
- * @param authority
1969
- * @param idToken
1992
+ * Creates an AccountEntity object from AccountInfo
1993
+ * @param accountInfo
1994
+ * @param cloudGraphHostName
1995
+ * @param msGraphHost
1996
+ * @returns
1970
1997
  */
1971
- static createGenericAccount(homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment) {
1998
+ static createFromAccountInfo(accountInfo, cloudGraphHostName, msGraphHost) {
1972
1999
  const account = new AccountEntity();
1973
2000
  account.authorityType =
1974
- authority && authority.authorityType === AuthorityType.Adfs
1975
- ? CacheAccountType.ADFS_ACCOUNT_TYPE
1976
- : CacheAccountType.GENERIC_ACCOUNT_TYPE;
1977
- account.homeAccountId = homeAccountId;
1978
- // non AAD scenarios can have empty realm
1979
- account.realm = Constants.EMPTY_STRING;
1980
- const env = environment || (authority && authority.getPreferredCache());
1981
- if (!env) {
1982
- throw ClientAuthError.createInvalidCacheEnvironmentError();
1983
- }
1984
- if (idToken) {
1985
- // How do you account for MSA CID here?
1986
- account.localAccountId =
1987
- idToken?.claims?.oid ||
1988
- idToken?.claims?.sub ||
1989
- Constants.EMPTY_STRING;
1990
- // upn claim for most ADFS scenarios
1991
- account.username = idToken?.claims?.upn || Constants.EMPTY_STRING;
1992
- account.name = idToken?.claims?.name || Constants.EMPTY_STRING;
1993
- account.idTokenClaims = idToken?.claims;
1994
- }
1995
- account.environment = env;
2001
+ accountInfo.authorityType || CacheAccountType.GENERIC_ACCOUNT_TYPE;
2002
+ account.homeAccountId = accountInfo.homeAccountId;
2003
+ account.localAccountId = accountInfo.localAccountId;
2004
+ account.nativeAccountId = accountInfo.nativeAccountId;
2005
+ account.realm = accountInfo.tenantId;
2006
+ account.environment = accountInfo.environment;
2007
+ account.username = accountInfo.username;
2008
+ account.name = accountInfo.name;
2009
+ account.idTokenClaims = accountInfo.idTokenClaims;
1996
2010
  account.cloudGraphHostName = cloudGraphHostName;
1997
2011
  account.msGraphHost = msGraphHost;
1998
- /*
1999
- * add uniqueName to claims
2000
- * account.name = idToken.claims.uniqueName;
2001
- */
2002
2012
  return account;
2003
2013
  }
2004
2014
  /**
@@ -2006,9 +2016,9 @@ class AccountEntity {
2006
2016
  * @param serverClientInfo
2007
2017
  * @param authType
2008
2018
  */
2009
- static generateHomeAccountId(serverClientInfo, authType, logger, cryptoObj, idToken) {
2010
- const accountId = idToken?.claims?.sub
2011
- ? idToken.claims.sub
2019
+ static generateHomeAccountId(serverClientInfo, authType, logger, cryptoObj, idTokenClaims) {
2020
+ const accountId = idTokenClaims?.sub
2021
+ ? idTokenClaims.sub
2012
2022
  : Constants.EMPTY_STRING;
2013
2023
  // since ADFS does not have tid and does not set client_info
2014
2024
  if (authType === AuthorityType.Adfs ||
@@ -2189,20 +2199,21 @@ class CacheManager {
2189
2199
  * saves a cache record
2190
2200
  * @param cacheRecord
2191
2201
  */
2192
- async saveCacheRecord(cacheRecord) {
2202
+ async saveCacheRecord(cacheRecord, storeInCache) {
2193
2203
  if (!cacheRecord) {
2194
2204
  throw ClientAuthError.createNullOrUndefinedCacheRecord();
2195
2205
  }
2196
2206
  if (!!cacheRecord.account) {
2197
2207
  this.setAccount(cacheRecord.account);
2198
2208
  }
2199
- if (!!cacheRecord.idToken) {
2209
+ if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
2200
2210
  this.setIdTokenCredential(cacheRecord.idToken);
2201
2211
  }
2202
- if (!!cacheRecord.accessToken) {
2212
+ if (!!cacheRecord.accessToken && storeInCache?.accessToken !== false) {
2203
2213
  await this.saveAccessToken(cacheRecord.accessToken);
2204
2214
  }
2205
- if (!!cacheRecord.refreshToken) {
2215
+ if (!!cacheRecord.refreshToken &&
2216
+ storeInCache?.refreshToken !== false) {
2206
2217
  this.setRefreshTokenCredential(cacheRecord.refreshToken);
2207
2218
  }
2208
2219
  if (!!cacheRecord.appMetadata) {
@@ -2616,7 +2627,11 @@ class CacheManager {
2616
2627
  return null;
2617
2628
  }
2618
2629
  else if (numIdTokens > 1) {
2619
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
2630
+ this.commonLogger.info("CacheManager:getIdToken - Multiple id tokens found, clearing them");
2631
+ idTokens.forEach((idToken) => {
2632
+ this.removeIdToken(idToken.generateCredentialKey());
2633
+ });
2634
+ return null;
2620
2635
  }
2621
2636
  this.commonLogger.info("CacheManager:getIdToken - Returning id token");
2622
2637
  return idTokens[0];
@@ -2726,7 +2741,11 @@ class CacheManager {
2726
2741
  return null;
2727
2742
  }
2728
2743
  else if (numAccessTokens > 1) {
2729
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
2744
+ this.commonLogger.info("CacheManager:getAccessToken - Multiple access tokens found, clearing them");
2745
+ accessTokens.forEach((accessToken) => {
2746
+ this.removeAccessToken(accessToken.generateCredentialKey());
2747
+ });
2748
+ return null;
2730
2749
  }
2731
2750
  this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
2732
2751
  return accessTokens[0];
@@ -3229,6 +3248,13 @@ function buildAuthOptions(authOptions) {
3229
3248
  ...authOptions,
3230
3249
  };
3231
3250
  }
3251
+ /**
3252
+ * Returns true if config has protocolMode set to ProtocolMode.OIDC, false otherwise
3253
+ * @param ClientConfiguration
3254
+ */
3255
+ function isOidcProtocolMode(config) {
3256
+ return (config.authOptions.authority.options.protocolMode === ProtocolMode.OIDC);
3257
+ }
3232
3258
 
3233
3259
  /*
3234
3260
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3462,7 +3488,7 @@ class RequestValidator {
3462
3488
  }
3463
3489
  });
3464
3490
  // remove empty string parameters
3465
- return Object.fromEntries(Object.entries(eQParams).filter(kv => kv[1] !== ""));
3491
+ return Object.fromEntries(Object.entries(eQParams).filter((kv) => kv[1] !== ""));
3466
3492
  }
3467
3493
  }
3468
3494
 
@@ -3504,9 +3530,15 @@ class RequestParameterBuilder {
3504
3530
  * @param scopeSet
3505
3531
  * @param addOidcScopes
3506
3532
  */
3507
- addScopes(scopes, addOidcScopes = true) {
3533
+ addScopes(scopes, addOidcScopes = true, defaultScopes = OIDC_DEFAULT_SCOPES) {
3534
+ // Always add openid to the scopes when adding OIDC scopes
3535
+ if (addOidcScopes &&
3536
+ !defaultScopes.includes("openid") &&
3537
+ !scopes.includes("openid")) {
3538
+ defaultScopes.push("openid");
3539
+ }
3508
3540
  const requestScopes = addOidcScopes
3509
- ? [...(scopes || []), ...OIDC_DEFAULT_SCOPES]
3541
+ ? [...(scopes || []), ...defaultScopes]
3510
3542
  : scopes || [];
3511
3543
  const scopeSet = new ScopeSet(requestScopes);
3512
3544
  this.parameters.set(AADServerParamKeys.SCOPE, encodeURIComponent(scopeSet.printScopes()));
@@ -4693,6 +4725,30 @@ class UrlString {
4693
4725
  }
4694
4726
  return Constants.EMPTY_STRING;
4695
4727
  }
4728
+ /**
4729
+ * Parses query server response string from given string.
4730
+ * Extract hash between '?code=' and '#' if trailing '# is present.
4731
+ * Returns empty string if no query symbol is found.
4732
+ * @param queryString
4733
+ */
4734
+ static parseQueryServerResponse(queryString) {
4735
+ const queryIndex1 = queryString.indexOf("?code");
4736
+ const queryIndex2 = queryString.indexOf("/?code");
4737
+ const hashIndex = queryString.indexOf("#");
4738
+ if (queryIndex2 > -1 && hashIndex > -1) {
4739
+ return queryString.substring(queryIndex2 + 2, hashIndex);
4740
+ }
4741
+ else if (queryIndex2 > -1) {
4742
+ return queryString.substring(queryIndex2 + 2);
4743
+ }
4744
+ else if (queryIndex1 > -1 && hashIndex > -1) {
4745
+ return queryString.substring(queryIndex1 + 1, hashIndex);
4746
+ }
4747
+ else if (queryIndex1 > -1) {
4748
+ return queryString.substring(queryIndex1 + 1);
4749
+ }
4750
+ return Constants.EMPTY_STRING;
4751
+ }
4696
4752
  static constructAuthorityUriFromObject(urlObject) {
4697
4753
  return new UrlString(urlObject.Protocol +
4698
4754
  "//" +
@@ -4738,6 +4794,21 @@ class UrlString {
4738
4794
  }
4739
4795
  return deserializedQueryString;
4740
4796
  }
4797
+ /**
4798
+ * Returns either deserialized query string or deserialized hash, depending on the serverResponseType
4799
+ * as a server auth code response object.
4800
+ */
4801
+ static getDeserializedCodeResponse(serverResponseType, hashFragment) {
4802
+ const hashUrlString = new UrlString(hashFragment);
4803
+ let serverParams;
4804
+ if (serverResponseType === ServerResponseType.QUERY) {
4805
+ serverParams = UrlString.getDeserializedQueryString(hashFragment);
4806
+ }
4807
+ else {
4808
+ serverParams = UrlString.getDeserializedHash(hashUrlString.getHash());
4809
+ }
4810
+ return serverParams;
4811
+ }
4741
4812
  /**
4742
4813
  * Check if the hash of the URL string contains known properties
4743
4814
  */
@@ -4956,6 +5027,7 @@ const PerformanceEvents = {
4956
5027
  UpdateCloudDiscoveryMetadataMeasurement: "updateCloudDiscoveryMetadataMeasurement",
4957
5028
  UsernamePasswordClientAcquireToken: "usernamePasswordClientAcquireToken",
4958
5029
  NativeMessageHandlerHandshake: "nativeMessageHandlerHandshake",
5030
+ NativeGenerateAuthResult: "nativeGenerateAuthResult",
4959
5031
  };
4960
5032
  /**
4961
5033
  * State of the performance event.
@@ -5181,12 +5253,25 @@ class ResponseHandler {
5181
5253
  */
5182
5254
  validateServerAuthorizationCodeResponse(serverResponseHash, cachedState, cryptoObj) {
5183
5255
  if (!serverResponseHash.state || !cachedState) {
5184
- throw !serverResponseHash.state
5185
- ? ClientAuthError.createStateNotFoundError("Server State")
5186
- : ClientAuthError.createStateNotFoundError("Cached State");
5256
+ throw serverResponseHash.state
5257
+ ? ClientAuthError.createStateNotFoundError("Cached State")
5258
+ : ClientAuthError.createStateNotFoundError("Server State");
5259
+ }
5260
+ let decodedServerResponseHash;
5261
+ let decodedCachedState;
5262
+ try {
5263
+ decodedServerResponseHash = decodeURIComponent(serverResponseHash.state);
5264
+ }
5265
+ catch (e) {
5266
+ throw ClientAuthError.createInvalidStateError(serverResponseHash.state, `Server response hash URI could not be decoded`);
5267
+ }
5268
+ try {
5269
+ decodedCachedState = decodeURIComponent(cachedState);
5187
5270
  }
5188
- if (decodeURIComponent(serverResponseHash.state) !==
5189
- decodeURIComponent(cachedState)) {
5271
+ catch (e) {
5272
+ throw ClientAuthError.createInvalidStateError(serverResponseHash.state, `Cached state URI could not be decoded`);
5273
+ }
5274
+ if (decodedServerResponseHash !== decodedCachedState) {
5190
5275
  throw ClientAuthError.createStateMismatchError();
5191
5276
  }
5192
5277
  // Check for error
@@ -5246,7 +5331,7 @@ class ResponseHandler {
5246
5331
  }
5247
5332
  }
5248
5333
  // generate homeAccountId
5249
- this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);
5334
+ this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj?.claims);
5250
5335
  // save the response tokens
5251
5336
  let requestStateObj;
5252
5337
  if (!!authCodePayload && !!authCodePayload.state) {
@@ -5279,7 +5364,7 @@ class ResponseHandler {
5279
5364
  return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, undefined, serverRequestId);
5280
5365
  }
5281
5366
  }
5282
- await this.cacheStorage.saveCacheRecord(cacheRecord);
5367
+ await this.cacheStorage.saveCacheRecord(cacheRecord, request.storeInCache);
5283
5368
  }
5284
5369
  finally {
5285
5370
  if (this.persistencePlugin &&
@@ -5308,7 +5393,13 @@ class ResponseHandler {
5308
5393
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) &&
5309
5394
  !!idTokenObj) {
5310
5395
  cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
5311
- cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, authCodePayload);
5396
+ cachedAccount = AccountEntity.createAccount({
5397
+ homeAccountId: this.homeAccountIdentifier,
5398
+ idTokenClaims: idTokenObj.claims,
5399
+ clientInfo: serverTokenResponse.client_info,
5400
+ cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
5401
+ msGraphHost: authCodePayload?.msgraph_host,
5402
+ }, authority);
5312
5403
  }
5313
5404
  // AccessToken
5314
5405
  let cachedAccessToken = null;
@@ -5352,34 +5443,6 @@ class ResponseHandler {
5352
5443
  }
5353
5444
  return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);
5354
5445
  }
5355
- /**
5356
- * Generate Account
5357
- * @param serverTokenResponse
5358
- * @param idToken
5359
- * @param authority
5360
- */
5361
- generateAccountEntity(serverTokenResponse, idToken, authority, authCodePayload) {
5362
- const authorityType = authority.authorityType;
5363
- const cloudGraphHostName = authCodePayload
5364
- ? authCodePayload.cloud_graph_host_name
5365
- : Constants.EMPTY_STRING;
5366
- const msGraphhost = authCodePayload
5367
- ? authCodePayload.msgraph_host
5368
- : Constants.EMPTY_STRING;
5369
- // ADFS does not require client_info in the response
5370
- if (authorityType === AuthorityType.Adfs) {
5371
- this.logger.verbose("Authority type is ADFS, creating ADFS account");
5372
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
5373
- }
5374
- // This fallback applies to B2C as well as they fall under an AAD account type.
5375
- if (StringUtils.isEmpty(serverTokenResponse.client_info) &&
5376
- authority.protocolMode === "AAD") {
5377
- throw ClientAuthError.createClientInfoEmptyError();
5378
- }
5379
- return serverTokenResponse.client_info
5380
- ? AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost)
5381
- : AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
5382
- }
5383
5446
  /**
5384
5447
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
5385
5448
  *
@@ -5469,6 +5532,8 @@ class AuthorizationCodeClient extends BaseClient {
5469
5532
  super(configuration, performanceClient);
5470
5533
  // Flag to indicate if client is for hybrid spa auth code redemption
5471
5534
  this.includeRedirectUri = true;
5535
+ this.oidcDefaultScopes =
5536
+ this.config.authOptions.authority.options.OIDCOptions?.defaultScopes;
5472
5537
  }
5473
5538
  /**
5474
5539
  * Creates the URL of the authorization request letting the user input credentials and consent to the
@@ -5507,7 +5572,7 @@ class AuthorizationCodeClient extends BaseClient {
5507
5572
  const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
5508
5573
  const httpVerAuthority = response.headers?.[HeaderNames.X_MS_HTTP_VERSION];
5509
5574
  if (httpVerAuthority) {
5510
- atsMeasurement?.addStaticFields({
5575
+ atsMeasurement?.add({
5511
5576
  httpVerAuthority,
5512
5577
  });
5513
5578
  }
@@ -5518,14 +5583,14 @@ class AuthorizationCodeClient extends BaseClient {
5518
5583
  return responseHandler
5519
5584
  .handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, authCodePayload, undefined, undefined, undefined, requestId)
5520
5585
  .then((result) => {
5521
- atsMeasurement?.endMeasurement({
5586
+ atsMeasurement?.end({
5522
5587
  success: true,
5523
5588
  });
5524
5589
  return result;
5525
5590
  })
5526
5591
  .catch((error) => {
5527
5592
  this.logger.verbose("Error in fetching token in ACC", request.correlationId);
5528
- atsMeasurement?.endMeasurement({
5593
+ atsMeasurement?.end({
5529
5594
  errorCode: error.errorCode,
5530
5595
  subErrorCode: error.subError,
5531
5596
  success: false,
@@ -5541,10 +5606,8 @@ class AuthorizationCodeClient extends BaseClient {
5541
5606
  handleFragmentResponse(hashFragment, cachedState) {
5542
5607
  // Handle responses.
5543
5608
  const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, null, null);
5544
- // Deserialize hash fragment response parameters.
5545
- const hashUrlString = new UrlString(hashFragment);
5546
- // Deserialize hash fragment response parameters.
5547
- const serverParams = UrlString.getDeserializedHash(hashUrlString.getHash());
5609
+ const serverParams = UrlString.getDeserializedCodeResponse(this.config.authOptions.authority.options.OIDCOptions
5610
+ ?.serverResponseType, hashFragment);
5548
5611
  // Get code response
5549
5612
  responseHandler.validateServerAuthorizationCodeResponse(serverParams, cachedState, this.cryptoUtils);
5550
5613
  // throw when there is no auth code in the response
@@ -5616,7 +5679,8 @@ class AuthorizationCodeClient extends BaseClient {
5616
5679
  async createTokenRequestBody(request) {
5617
5680
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthClientCreateTokenRequestBody, request.correlationId);
5618
5681
  const parameterBuilder = new RequestParameterBuilder();
5619
- parameterBuilder.addClientId(this.config.authOptions.clientId);
5682
+ parameterBuilder.addClientId(request.tokenBodyParameters?.[AADServerParamKeys.CLIENT_ID] ||
5683
+ this.config.authOptions.clientId);
5620
5684
  /*
5621
5685
  * For hybrid spa flow, there will be a code but no verifier
5622
5686
  * In this scenario, don't include redirect uri as auth code will not be bound to redirect URI
@@ -5630,14 +5694,14 @@ class AuthorizationCodeClient extends BaseClient {
5630
5694
  parameterBuilder.addRedirectUri(request.redirectUri);
5631
5695
  }
5632
5696
  // Add scope array, parameter builder will add default scopes and dedupe
5633
- parameterBuilder.addScopes(request.scopes);
5697
+ parameterBuilder.addScopes(request.scopes, true, this.oidcDefaultScopes);
5634
5698
  // add code: user set, not validated
5635
5699
  parameterBuilder.addAuthorizationCode(request.code);
5636
5700
  // Add library metadata
5637
5701
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5638
5702
  parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5639
5703
  parameterBuilder.addThrottling();
5640
- if (this.serverTelemetryManager) {
5704
+ if (this.serverTelemetryManager && !isOidcProtocolMode(this.config)) {
5641
5705
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
5642
5706
  }
5643
5707
  // add code_verifier if passed
@@ -5731,12 +5795,13 @@ class AuthorizationCodeClient extends BaseClient {
5731
5795
  async createAuthCodeUrlQueryString(request) {
5732
5796
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthClientCreateQueryString, request.correlationId);
5733
5797
  const parameterBuilder = new RequestParameterBuilder();
5734
- parameterBuilder.addClientId(this.config.authOptions.clientId);
5798
+ parameterBuilder.addClientId(request.extraQueryParameters?.[AADServerParamKeys.CLIENT_ID] ||
5799
+ this.config.authOptions.clientId);
5735
5800
  const requestScopes = [
5736
5801
  ...(request.scopes || []),
5737
5802
  ...(request.extraScopesToConsent || []),
5738
5803
  ];
5739
- parameterBuilder.addScopes(requestScopes);
5804
+ parameterBuilder.addScopes(requestScopes, true, this.oidcDefaultScopes);
5740
5805
  // validate the redirectUri (to be a non null value)
5741
5806
  parameterBuilder.addRedirectUri(request.redirectUri);
5742
5807
  // generate the correlationId if not set by the user and add
@@ -5749,7 +5814,9 @@ class AuthorizationCodeClient extends BaseClient {
5749
5814
  parameterBuilder.addResponseTypeCode();
5750
5815
  // add library info parameters
5751
5816
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5752
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5817
+ if (!isOidcProtocolMode(this.config)) {
5818
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5819
+ }
5753
5820
  // add client_info=1
5754
5821
  parameterBuilder.addClientInfo();
5755
5822
  if (request.codeChallenge && request.codeChallengeMethod) {
@@ -5910,11 +5977,11 @@ class RefreshTokenClient extends BaseClient {
5910
5977
  this.performanceClient?.setPreQueueTime(PerformanceEvents.RefreshTokenClientExecuteTokenRequest, request.correlationId);
5911
5978
  const response = await this.executeTokenRequest(request, this.authority);
5912
5979
  const httpVerToken = response.headers?.[HeaderNames.X_MS_HTTP_VERSION];
5913
- atsMeasurement?.addStaticFields({
5980
+ atsMeasurement?.add({
5914
5981
  refreshTokenSize: response.body.refresh_token?.length || 0,
5915
5982
  });
5916
5983
  if (httpVerToken) {
5917
- atsMeasurement?.addStaticFields({
5984
+ atsMeasurement?.add({
5918
5985
  httpVerToken,
5919
5986
  });
5920
5987
  }
@@ -5926,14 +5993,14 @@ class RefreshTokenClient extends BaseClient {
5926
5993
  return responseHandler
5927
5994
  .handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true, request.forceCache, requestId)
5928
5995
  .then((result) => {
5929
- atsMeasurement?.endMeasurement({
5996
+ atsMeasurement?.end({
5930
5997
  success: true,
5931
5998
  });
5932
5999
  return result;
5933
6000
  })
5934
6001
  .catch((error) => {
5935
6002
  this.logger.verbose("Error in fetching refresh token", request.correlationId);
5936
- atsMeasurement?.endMeasurement({
6003
+ atsMeasurement?.end({
5937
6004
  errorCode: error.errorCode,
5938
6005
  subErrorCode: error.subError,
5939
6006
  success: false,
@@ -5997,11 +6064,11 @@ class RefreshTokenClient extends BaseClient {
5997
6064
  this.logger.verbose("RefreshTokenClientAcquireTokenWithCachedRefreshToken called", request.correlationId);
5998
6065
  const refreshToken = this.cacheManager.getRefreshToken(request.account, foci);
5999
6066
  if (!refreshToken) {
6000
- atsMeasurement?.discardMeasurement();
6067
+ atsMeasurement?.discard();
6001
6068
  throw InteractionRequiredAuthError.createNoTokensFoundError();
6002
6069
  }
6003
6070
  // attach cached RT size to the current measurement
6004
- atsMeasurement?.endMeasurement({
6071
+ atsMeasurement?.end({
6005
6072
  success: true,
6006
6073
  });
6007
6074
  const refreshTokenRequest = {
@@ -6042,13 +6109,13 @@ class RefreshTokenClient extends BaseClient {
6042
6109
  };
6043
6110
  return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)
6044
6111
  .then((result) => {
6045
- acquireTokenMeasurement?.endMeasurement({
6112
+ acquireTokenMeasurement?.end({
6046
6113
  success: true,
6047
6114
  });
6048
6115
  return result;
6049
6116
  })
6050
6117
  .catch((error) => {
6051
- acquireTokenMeasurement?.endMeasurement({
6118
+ acquireTokenMeasurement?.end({
6052
6119
  success: false,
6053
6120
  });
6054
6121
  throw error;
@@ -6064,13 +6131,13 @@ class RefreshTokenClient extends BaseClient {
6064
6131
  const acquireTokenMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.BaseClientCreateTokenRequestHeaders, correlationId);
6065
6132
  const parameterBuilder = new RequestParameterBuilder();
6066
6133
  parameterBuilder.addClientId(this.config.authOptions.clientId);
6067
- parameterBuilder.addScopes(request.scopes);
6134
+ parameterBuilder.addScopes(request.scopes, true, this.config.authOptions.authority.options.OIDCOptions?.defaultScopes);
6068
6135
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
6069
6136
  parameterBuilder.addClientInfo();
6070
6137
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6071
6138
  parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6072
6139
  parameterBuilder.addThrottling();
6073
- if (this.serverTelemetryManager) {
6140
+ if (this.serverTelemetryManager && !isOidcProtocolMode(this.config)) {
6074
6141
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
6075
6142
  }
6076
6143
  parameterBuilder.addCorrelationId(correlationId);
@@ -6095,7 +6162,7 @@ class RefreshTokenClient extends BaseClient {
6095
6162
  parameterBuilder.addSshJwk(request.sshJwk);
6096
6163
  }
6097
6164
  else {
6098
- acquireTokenMeasurement?.endMeasurement({
6165
+ acquireTokenMeasurement?.end({
6099
6166
  success: false,
6100
6167
  });
6101
6168
  throw ClientConfigurationError.createMissingSshJwkError();
@@ -6124,7 +6191,7 @@ class RefreshTokenClient extends BaseClient {
6124
6191
  break;
6125
6192
  }
6126
6193
  }
6127
- acquireTokenMeasurement?.endMeasurement({
6194
+ acquireTokenMeasurement?.end({
6128
6195
  success: true,
6129
6196
  });
6130
6197
  return parameterBuilder.createQueryString();
@@ -7119,18 +7186,14 @@ const rawMetdataJSON = {
7119
7186
  };
7120
7187
  const EndpointMetadata = rawMetdataJSON.endpointMetadata;
7121
7188
  const InstanceDiscoveryMetadata = rawMetdataJSON.instanceDiscoveryMetadata;
7122
-
7123
- /*
7124
- * Copyright (c) Microsoft Corporation. All rights reserved.
7125
- * Licensed under the MIT License.
7126
- */
7127
- /**
7128
- * Protocol modes supported by MSAL.
7129
- */
7130
- const ProtocolMode = {
7131
- AAD: "AAD",
7132
- OIDC: "OIDC",
7133
- };
7189
+ const InstanceDiscoveryMetadataAliases = new Set();
7190
+ for (const key in InstanceDiscoveryMetadata) {
7191
+ for (const metadata of InstanceDiscoveryMetadata[key].metadata) {
7192
+ for (const alias of metadata.aliases) {
7193
+ InstanceDiscoveryMetadataAliases.add(alias);
7194
+ }
7195
+ }
7196
+ }
7134
7197
 
7135
7198
  /*
7136
7199
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7508,10 +7571,10 @@ class Authority {
7508
7571
  * @private
7509
7572
  */
7510
7573
  canReplaceTenant(authorityUri) {
7511
- return authorityUri.PathSegments.length === 1
7512
- && !Authority.reservedTenantDomains.has(authorityUri.PathSegments[0])
7513
- && this.getAuthorityType(authorityUri) === AuthorityType.Default
7514
- && this.protocolMode === ProtocolMode.AAD;
7574
+ return (authorityUri.PathSegments.length === 1 &&
7575
+ !Authority.reservedTenantDomains.has(authorityUri.PathSegments[0]) &&
7576
+ this.getAuthorityType(authorityUri) === AuthorityType.Default &&
7577
+ this.protocolMode === ProtocolMode.AAD);
7515
7578
  }
7516
7579
  /**
7517
7580
  * Replaces tenant in url path with current tenant. Defaults to common.
@@ -7532,8 +7595,9 @@ class Authority {
7532
7595
  const currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
7533
7596
  currentAuthorityParts.forEach((currentPart, index) => {
7534
7597
  let cachedPart = cachedAuthorityParts[index];
7535
- if (index === 0 && this.canReplaceTenant(cachedAuthorityUrlComponents)) {
7536
- const tenantId = (new UrlString(this.metadata.authorization_endpoint)).getUrlComponents().PathSegments[0];
7598
+ if (index === 0 &&
7599
+ this.canReplaceTenant(cachedAuthorityUrlComponents)) {
7600
+ const tenantId = new UrlString(this.metadata.authorization_endpoint).getUrlComponents().PathSegments[0];
7537
7601
  /**
7538
7602
  * Check if AAD canonical authority contains tenant domain name, for example "testdomain.onmicrosoft.com",
7539
7603
  * by comparing its first path segment to the corresponding authorization endpoint path segment, which is
@@ -7554,8 +7618,9 @@ class Authority {
7554
7618
  * The default open id configuration endpoint for any canonical authority.
7555
7619
  */
7556
7620
  get defaultOpenIdConfigurationEndpoint() {
7621
+ const canonicalAuthorityHost = this.hostnameAndPort;
7557
7622
  if (this.authorityType === AuthorityType.Adfs ||
7558
- this.protocolMode === ProtocolMode.OIDC) {
7623
+ !this.isAliasOfKnownMicrosoftAuthority(canonicalAuthorityHost)) {
7559
7624
  return `${this.canonicalAuthority}.well-known/openid-configuration`;
7560
7625
  }
7561
7626
  return `${this.canonicalAuthority}v2.0/.well-known/openid-configuration`;
@@ -7598,41 +7663,65 @@ class Authority {
7598
7663
  */
7599
7664
  async updateEndpointMetadata(metadataEntity) {
7600
7665
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
7666
+ this.logger.verbose("Attempting to get endpoint metadata from authority configuration");
7601
7667
  let metadata = this.getEndpointMetadataFromConfig();
7602
7668
  if (metadata) {
7669
+ this.logger.verbose("Found endpoint metadata in authority configuration");
7603
7670
  metadataEntity.updateEndpointMetadata(metadata, false);
7604
7671
  return AuthorityMetadataSource.CONFIG;
7605
7672
  }
7673
+ this.logger.verbose("Did not find endpoint metadata in the config... Attempting to get endpoint metadata from the hardcoded values.");
7674
+ // 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.
7675
+ if (this.authorityOptions.skipAuthorityMetadataCache) {
7676
+ this.logger.verbose("Skipping hardcoded metadata cache since skipAuthorityMetadataCache is set to true. Attempting to get endpoint metadata from the network metadata cache.");
7677
+ }
7678
+ else {
7679
+ let hardcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
7680
+ if (hardcodedMetadata) {
7681
+ this.logger.verbose("Found endpoint metadata from hardcoded values.");
7682
+ // If the user prefers to use an azure region replace the global endpoints with regional information.
7683
+ if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7684
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7685
+ this.logger.verbose("Found azure region configuration. Updating endpoints with regional information.");
7686
+ hardcodedMetadata =
7687
+ await this.updateMetadataWithRegionalInformation(hardcodedMetadata);
7688
+ }
7689
+ metadataEntity.updateEndpointMetadata(hardcodedMetadata, false);
7690
+ return AuthorityMetadataSource.HARDCODED_VALUES;
7691
+ }
7692
+ else {
7693
+ this.logger.verbose("Did not find endpoint metadata in hardcoded values... Attempting to get endpoint metadata from the network metadata cache.");
7694
+ }
7695
+ }
7696
+ // Check cached metadata entity expiration status
7697
+ const metadataEntityExpired = metadataEntity.isExpired();
7606
7698
  if (this.isAuthoritySameType(metadataEntity) &&
7607
7699
  metadataEntity.endpointsFromNetwork &&
7608
- !metadataEntity.isExpired()) {
7700
+ !metadataEntityExpired) {
7609
7701
  // No need to update
7702
+ this.logger.verbose("Found endpoint metadata in the cache.");
7610
7703
  return AuthorityMetadataSource.CACHE;
7611
7704
  }
7705
+ else if (metadataEntityExpired) {
7706
+ this.logger.verbose("The metadata entity is expired.");
7707
+ }
7708
+ this.logger.verbose("Did not find cached endpoint metadata... Attempting to get endpoint metadata from the network.");
7612
7709
  this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
7613
7710
  metadata = await this.getEndpointMetadataFromNetwork();
7614
7711
  if (metadata) {
7712
+ this.logger.verbose("Endpoint metadata was successfully returned from getEndpointMetadataFromNetwork()");
7615
7713
  // If the user prefers to use an azure region replace the global endpoints with regional information.
7616
7714
  if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7617
7715
  this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7716
+ this.logger.verbose("Found azure region configuration. Updating endpoints with regional information.");
7618
7717
  metadata = await this.updateMetadataWithRegionalInformation(metadata);
7619
7718
  }
7620
7719
  metadataEntity.updateEndpointMetadata(metadata, true);
7621
7720
  return AuthorityMetadataSource.NETWORK;
7622
7721
  }
7623
- let harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
7624
- if (harcodedMetadata &&
7625
- !this.authorityOptions.skipAuthorityMetadataCache) {
7626
- // If the user prefers to use an azure region replace the global endpoints with regional information.
7627
- if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
7628
- this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7629
- harcodedMetadata =
7630
- await this.updateMetadataWithRegionalInformation(harcodedMetadata);
7631
- }
7632
- metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
7633
- return AuthorityMetadataSource.HARDCODED_VALUES;
7634
- }
7635
7722
  else {
7723
+ // Metadata could not be obtained from the config, cache, network or hardcoded values
7724
+ 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.");
7636
7725
  throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7637
7726
  }
7638
7727
  }
@@ -7681,17 +7770,23 @@ class Authority {
7681
7770
  const response = await this.networkInterface.sendGetRequestAsync(openIdConfigurationEndpoint, options);
7682
7771
  const isValidResponse = isOpenIdConfigResponse(response.body);
7683
7772
  if (isValidResponse) {
7684
- perfEvent?.endMeasurement({ success: true });
7773
+ perfEvent?.end({ success: true });
7685
7774
  return response.body;
7686
7775
  }
7687
7776
  else {
7688
- perfEvent?.endMeasurement({ success: false, errorCode: "invalid_response" });
7777
+ perfEvent?.end({
7778
+ success: false,
7779
+ errorCode: "invalid_response",
7780
+ });
7689
7781
  this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: could not parse response as OpenID configuration`);
7690
7782
  return null;
7691
7783
  }
7692
7784
  }
7693
7785
  catch (e) {
7694
- perfEvent?.endMeasurement({ success: false, errorCode: "request_failure" });
7786
+ perfEvent?.end({
7787
+ success: false,
7788
+ errorCode: "request_failure",
7789
+ });
7695
7790
  this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: ${e}`);
7696
7791
  return null;
7697
7792
  }
@@ -7713,19 +7808,26 @@ class Authority {
7713
7808
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
7714
7809
  const userConfiguredAzureRegion = this.authorityOptions.azureRegionConfiguration?.azureRegion;
7715
7810
  if (userConfiguredAzureRegion) {
7716
- if (userConfiguredAzureRegion !== Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7717
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7718
- this.regionDiscoveryMetadata.region_used = userConfiguredAzureRegion;
7811
+ if (userConfiguredAzureRegion !==
7812
+ Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7813
+ this.regionDiscoveryMetadata.region_outcome =
7814
+ RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7815
+ this.regionDiscoveryMetadata.region_used =
7816
+ userConfiguredAzureRegion;
7719
7817
  return Authority.replaceWithRegionalInformation(metadata, userConfiguredAzureRegion);
7720
7818
  }
7721
7819
  this.performanceClient?.setPreQueueTime(PerformanceEvents.RegionDiscoveryDetectRegion, this.correlationId);
7722
- const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration?.environmentRegion, this.regionDiscoveryMetadata);
7820
+ const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration
7821
+ ?.environmentRegion, this.regionDiscoveryMetadata);
7723
7822
  if (autodetectedRegionName) {
7724
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL;
7725
- this.regionDiscoveryMetadata.region_used = autodetectedRegionName;
7823
+ this.regionDiscoveryMetadata.region_outcome =
7824
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL;
7825
+ this.regionDiscoveryMetadata.region_used =
7826
+ autodetectedRegionName;
7726
7827
  return Authority.replaceWithRegionalInformation(metadata, autodetectedRegionName);
7727
7828
  }
7728
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7829
+ this.regionDiscoveryMetadata.region_outcome =
7830
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7729
7831
  }
7730
7832
  return metadata;
7731
7833
  }
@@ -7737,7 +7839,7 @@ class Authority {
7737
7839
  */
7738
7840
  async updateCloudDiscoveryMetadata(metadataEntity) {
7739
7841
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
7740
- this.logger.verbose("Attempting to get cloud discovery metadata in the config");
7842
+ this.logger.verbose("Attempting to get cloud discovery metadata from authority configuration");
7741
7843
  this.logger.verbosePii(`Known Authorities: ${this.authorityOptions.knownAuthorities ||
7742
7844
  Constants.NOT_APPLICABLE}`);
7743
7845
  this.logger.verbosePii(`Authority Metadata: ${this.authorityOptions.authorityMetadata ||
@@ -7745,17 +7847,29 @@ class Authority {
7745
7847
  this.logger.verbosePii(`Canonical Authority: ${metadataEntity.canonical_authority || Constants.NOT_APPLICABLE}`);
7746
7848
  let metadata = this.getCloudDiscoveryMetadataFromConfig();
7747
7849
  if (metadata) {
7748
- this.logger.verbose("Found cloud discovery metadata in the config.");
7850
+ this.logger.verbose("Found cloud discovery metadata in authority configuration");
7749
7851
  metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
7750
7852
  return AuthorityMetadataSource.CONFIG;
7751
7853
  }
7752
- // If the cached metadata came from config but that config was not passed to this instance, we must go to the network
7753
- this.logger.verbose("Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the cache.");
7854
+ // If the cached metadata came from config but that config was not passed to this instance, we must go to hardcoded values
7855
+ this.logger.verbose("Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the hardcoded values.");
7856
+ if (this.options.skipAuthorityMetadataCache) {
7857
+ 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.");
7858
+ }
7859
+ else {
7860
+ const hardcodedMetadata = this.getCloudDiscoveryMetadataFromHardcodedValues();
7861
+ if (hardcodedMetadata) {
7862
+ this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
7863
+ metadataEntity.updateCloudDiscoveryMetadata(hardcodedMetadata, false);
7864
+ return AuthorityMetadataSource.HARDCODED_VALUES;
7865
+ }
7866
+ this.logger.verbose("Did not find cloud discovery metadata in hardcoded values... Attempting to get cloud discovery metadata from the network metadata cache.");
7867
+ }
7754
7868
  const metadataEntityExpired = metadataEntity.isExpired();
7755
7869
  if (this.isAuthoritySameType(metadataEntity) &&
7756
7870
  metadataEntity.aliasesFromNetwork &&
7757
7871
  !metadataEntityExpired) {
7758
- this.logger.verbose("Found metadata in the cache.");
7872
+ this.logger.verbose("Found cloud discovery metadata in the cache.");
7759
7873
  // No need to update
7760
7874
  return AuthorityMetadataSource.CACHE;
7761
7875
  }
@@ -7770,15 +7884,8 @@ class Authority {
7770
7884
  metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
7771
7885
  return AuthorityMetadataSource.NETWORK;
7772
7886
  }
7773
- this.logger.verbose("Did not find cloud discovery metadata from the network... Attempting to get cloud discovery metadata from hardcoded values.");
7774
- const harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
7775
- if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
7776
- this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
7777
- metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
7778
- return AuthorityMetadataSource.HARDCODED_VALUES;
7779
- }
7780
7887
  // Metadata could not be obtained from the config, cache, network or hardcoded values
7781
- 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.");
7888
+ 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.");
7782
7889
  throw ClientConfigurationError.createUntrustedAuthorityError();
7783
7890
  }
7784
7891
  /**
@@ -7883,9 +7990,11 @@ class Authority {
7883
7990
  /**
7884
7991
  * Get cloud discovery metadata for common authorities
7885
7992
  */
7886
- getCloudDiscoveryMetadataFromHarcodedValues() {
7993
+ getCloudDiscoveryMetadataFromHardcodedValues() {
7887
7994
  if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
7888
- return InstanceDiscoveryMetadata[this.canonicalAuthority];
7995
+ const hardcodedMetadataResponse = InstanceDiscoveryMetadata[this.canonicalAuthority];
7996
+ const metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(hardcodedMetadataResponse.metadata, this.hostnameAndPort);
7997
+ return metadata;
7889
7998
  }
7890
7999
  return null;
7891
8000
  }
@@ -7960,6 +8069,13 @@ class Authority {
7960
8069
  isAlias(host) {
7961
8070
  return this.metadata.aliases.indexOf(host) > -1;
7962
8071
  }
8072
+ /**
8073
+ * Returns whether or not the provided host is an alias of a known Microsoft authority for purposes of endpoint discovery
8074
+ * @param host
8075
+ */
8076
+ isAliasOfKnownMicrosoftAuthority(host) {
8077
+ return InstanceDiscoveryMetadataAliases.has(host);
8078
+ }
7963
8079
  /**
7964
8080
  * Checks whether the provided host is that of a public cloud authority
7965
8081
  *
@@ -8001,15 +8117,17 @@ class Authority {
8001
8117
  * @param azureRegion string
8002
8118
  */
8003
8119
  static replaceWithRegionalInformation(metadata, azureRegion) {
8004
- metadata.authorization_endpoint =
8005
- Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
8120
+ const regionalMetadata = { ...metadata };
8121
+ regionalMetadata.authorization_endpoint =
8122
+ Authority.buildRegionalAuthorityString(regionalMetadata.authorization_endpoint, azureRegion);
8006
8123
  // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
8007
- metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
8008
- if (metadata.end_session_endpoint) {
8009
- metadata.end_session_endpoint =
8010
- Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
8124
+ regionalMetadata.token_endpoint =
8125
+ Authority.buildRegionalAuthorityString(regionalMetadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
8126
+ if (regionalMetadata.end_session_endpoint) {
8127
+ regionalMetadata.end_session_endpoint =
8128
+ Authority.buildRegionalAuthorityString(regionalMetadata.end_session_endpoint, azureRegion);
8011
8129
  }
8012
- return metadata;
8130
+ return regionalMetadata;
8013
8131
  }
8014
8132
  /**
8015
8133
  * Transform CIAM_AUTHORIY as per the below rules:
@@ -8021,11 +8139,14 @@ class Authority {
8021
8139
  * @param authority
8022
8140
  */
8023
8141
  static transformCIAMAuthority(authority) {
8024
- let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH) ? authority : `${authority}${Constants.FORWARD_SLASH}`;
8142
+ let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH)
8143
+ ? authority
8144
+ : `${authority}${Constants.FORWARD_SLASH}`;
8025
8145
  const authorityUrl = new UrlString(authority);
8026
8146
  const authorityUrlComponents = authorityUrl.getUrlComponents();
8027
8147
  // check if transformation is needed
8028
- if (authorityUrlComponents.PathSegments.length === 0 && (authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL))) {
8148
+ if (authorityUrlComponents.PathSegments.length === 0 &&
8149
+ authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL)) {
8029
8150
  const tenantIdOrDomain = authorityUrlComponents.HostNameAndPort.split(".")[0];
8030
8151
  ciamAuthority = `${ciamAuthority}${tenantIdOrDomain}${Constants.AAD_TENANT_DOMAIN_SUFFIX}`;
8031
8152
  }
@@ -8033,13 +8154,13 @@ class Authority {
8033
8154
  }
8034
8155
  }
8035
8156
  // Reserved tenant domain names that will not be replaced with tenant id
8036
- Authority.reservedTenantDomains = (new Set([
8157
+ Authority.reservedTenantDomains = new Set([
8037
8158
  "{tenant}",
8038
8159
  "{tenantid}",
8039
8160
  AADAuthorityConstants.COMMON,
8040
8161
  AADAuthorityConstants.CONSUMERS,
8041
- AADAuthorityConstants.ORGANIZATIONS
8042
- ]));
8162
+ AADAuthorityConstants.ORGANIZATIONS,
8163
+ ]);
8043
8164
 
8044
8165
  /*
8045
8166
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8501,8 +8622,10 @@ class PerformanceClient {
8501
8622
  * @param {Logger} logger Logger used by the application
8502
8623
  * @param {string} libraryName Name of the library
8503
8624
  * @param {string} libraryVersion Version of the library
8625
+ * @param {ApplicationTelemetry} applicationTelemetry application name and version
8626
+ * @param {Set<String>} intFields integer fields to be truncated
8504
8627
  */
8505
- constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
8628
+ constructor(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry, intFields) {
8506
8629
  this.authority = authority;
8507
8630
  this.libraryName = libraryName;
8508
8631
  this.libraryVersion = libraryVersion;
@@ -8513,6 +8636,10 @@ class PerformanceClient {
8513
8636
  this.eventsByCorrelationId = new Map();
8514
8637
  this.queueMeasurements = new Map();
8515
8638
  this.preQueueTimeByCorrelationId = new Map();
8639
+ this.intFields = intFields || new Set();
8640
+ for (const item of IntFields) {
8641
+ this.intFields.add(item);
8642
+ }
8516
8643
  }
8517
8644
  /**
8518
8645
  * Starts and returns an platform-specific implementation of IPerformanceMeasurement.
@@ -8527,13 +8654,6 @@ class PerformanceClient {
8527
8654
  ) {
8528
8655
  return {};
8529
8656
  }
8530
- /**
8531
- * Get integral fields.
8532
- * Override to change the set.
8533
- */
8534
- getIntFields() {
8535
- return IntFields;
8536
- }
8537
8657
  /**
8538
8658
  * Gets map of pre-queue times by correlation Id
8539
8659
  *
@@ -8651,7 +8771,7 @@ class PerformanceClient {
8651
8771
  this.cacheEventByCorrelationId(inProgressEvent);
8652
8772
  // Return the event and functions the caller can use to properly end/flush the measurement
8653
8773
  return {
8654
- endMeasurement: (event) => {
8774
+ end: (event) => {
8655
8775
  return this.endMeasurement({
8656
8776
  // Initial set of event properties
8657
8777
  ...inProgressEvent,
@@ -8659,14 +8779,14 @@ class PerformanceClient {
8659
8779
  ...event,
8660
8780
  }, performanceMeasurement);
8661
8781
  },
8662
- discardMeasurement: () => {
8782
+ discard: () => {
8663
8783
  return this.discardMeasurements(inProgressEvent.correlationId);
8664
8784
  },
8665
- addStaticFields: (fields) => {
8666
- return this.addStaticFields(fields, inProgressEvent.correlationId);
8785
+ add: (fields) => {
8786
+ return this.addFields(fields, inProgressEvent.correlationId);
8667
8787
  },
8668
- increment: (counters) => {
8669
- return this.increment(counters, inProgressEvent.correlationId);
8788
+ increment: (fields) => {
8789
+ return this.incrementFields(fields, inProgressEvent.correlationId);
8670
8790
  },
8671
8791
  measurement: performanceMeasurement,
8672
8792
  event: inProgressEvent,
@@ -8731,7 +8851,7 @@ class PerformanceClient {
8731
8851
  status: PerformanceEventStatus.Completed,
8732
8852
  incompleteSubsCount,
8733
8853
  };
8734
- this.truncateIntegralFields(finalEvent, this.getIntFields());
8854
+ this.truncateIntegralFields(finalEvent);
8735
8855
  this.emitEvents([finalEvent], event.correlationId);
8736
8856
  return finalEvent;
8737
8857
  }
@@ -8740,7 +8860,7 @@ class PerformanceClient {
8740
8860
  * @param fields
8741
8861
  * @param correlationId
8742
8862
  */
8743
- addStaticFields(fields, correlationId) {
8863
+ addFields(fields, correlationId) {
8744
8864
  this.logger.trace("PerformanceClient: Updating static fields");
8745
8865
  const event = this.eventsByCorrelationId.get(correlationId);
8746
8866
  if (event) {
@@ -8755,18 +8875,21 @@ class PerformanceClient {
8755
8875
  }
8756
8876
  /**
8757
8877
  * Increment counters to be emitted when the measurements are flushed
8758
- * @param counters {Counters}
8878
+ * @param fields {string[]}
8759
8879
  * @param correlationId {string} correlation identifier
8760
8880
  */
8761
- increment(counters, correlationId) {
8881
+ incrementFields(fields, correlationId) {
8762
8882
  this.logger.trace("PerformanceClient: Updating counters");
8763
8883
  const event = this.eventsByCorrelationId.get(correlationId);
8764
8884
  if (event) {
8765
- for (const counter in counters) {
8885
+ for (const counter in fields) {
8766
8886
  if (!event.hasOwnProperty(counter)) {
8767
8887
  event[counter] = 0;
8768
8888
  }
8769
- event[counter] += counters[counter];
8889
+ else if (isNaN(Number(event[counter]))) {
8890
+ return;
8891
+ }
8892
+ event[counter] += fields[counter];
8770
8893
  }
8771
8894
  }
8772
8895
  else {
@@ -8884,8 +9007,8 @@ class PerformanceClient {
8884
9007
  * @param {PerformanceEvent} event performance event to update.
8885
9008
  * @param {Set<string>} intFields integral fields.
8886
9009
  */
8887
- truncateIntegralFields(event, intFields) {
8888
- intFields.forEach((key) => {
9010
+ truncateIntegralFields(event) {
9011
+ this.intFields.forEach((key) => {
8889
9012
  if (key in event && typeof event[key] === "number") {
8890
9013
  event[key] = Math.floor(event[key]);
8891
9014
  }
@@ -8898,9 +9021,15 @@ class PerformanceClient {
8898
9021
  * Licensed under the MIT License.
8899
9022
  */
8900
9023
  class StubPerformanceMeasurement {
8901
- startMeasurement() { return; }
8902
- endMeasurement() { return; }
8903
- flushMeasurement() { return null; }
9024
+ startMeasurement() {
9025
+ return;
9026
+ }
9027
+ endMeasurement() {
9028
+ return;
9029
+ }
9030
+ flushMeasurement() {
9031
+ return null;
9032
+ }
8904
9033
  }
8905
9034
  class StubPerformanceClient extends PerformanceClient {
8906
9035
  generateId() {
@@ -8912,8 +9041,36 @@ class StubPerformanceClient extends PerformanceClient {
8912
9041
  calculateQueuedTime() {
8913
9042
  return 0;
8914
9043
  }
8915
- addQueueMeasurement() { return; }
8916
- setPreQueueTime() { return; }
9044
+ addQueueMeasurement() {
9045
+ return;
9046
+ }
9047
+ setPreQueueTime() {
9048
+ return;
9049
+ }
9050
+ endMeasurement() {
9051
+ return null;
9052
+ }
9053
+ discardMeasurements() {
9054
+ return;
9055
+ }
9056
+ removePerformanceCallback() {
9057
+ return true;
9058
+ }
9059
+ addPerformanceCallback() {
9060
+ return "";
9061
+ }
9062
+ emitEvents() {
9063
+ return;
9064
+ }
9065
+ addFields() {
9066
+ return;
9067
+ }
9068
+ incrementFields() {
9069
+ return;
9070
+ }
9071
+ cacheEventByCorrelationId() {
9072
+ return;
9073
+ }
8917
9074
  }
8918
9075
 
8919
9076
  exports.AADAuthorityConstants = AADAuthorityConstants;
@@ -8981,6 +9138,7 @@ exports.ResponseMode = ResponseMode;
8981
9138
  exports.SSOTypes = SSOTypes;
8982
9139
  exports.ScopeSet = ScopeSet;
8983
9140
  exports.ServerError = ServerError;
9141
+ exports.ServerResponseType = ServerResponseType;
8984
9142
  exports.ServerTelemetryEntity = ServerTelemetryEntity;
8985
9143
  exports.ServerTelemetryManager = ServerTelemetryManager;
8986
9144
  exports.SilentFlowClient = SilentFlowClient;
@@ -8997,4 +9155,4 @@ exports.UrlString = UrlString;
8997
9155
  exports.buildClientInfo = buildClientInfo;
8998
9156
  exports.buildClientInfoFromHomeAccountId = buildClientInfoFromHomeAccountId;
8999
9157
  exports.version = version;
9000
- //# sourceMappingURL=index.cjs.js.map
9158
+ //# sourceMappingURL=index.cjs.map