@azure/msal-common 13.0.0 → 14.0.0-alpha.2

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 (333) hide show
  1. package/dist/account/AccountInfo.d.ts +31 -31
  2. package/dist/account/AccountInfo.d.ts.map +1 -1
  3. package/dist/account/AuthToken.d.ts +20 -20
  4. package/dist/account/AuthToken.d.ts.map +1 -1
  5. package/dist/account/AuthToken.js +49 -50
  6. package/dist/account/AuthToken.js.map +1 -1
  7. package/dist/account/CcsCredential.d.ts +8 -8
  8. package/dist/account/CcsCredential.d.ts.map +1 -1
  9. package/dist/account/CcsCredential.js +9 -9
  10. package/dist/account/CcsCredential.js.map +1 -1
  11. package/dist/account/ClientCredentials.d.ts +14 -14
  12. package/dist/account/ClientCredentials.d.ts.map +1 -1
  13. package/dist/account/ClientInfo.d.ts +19 -19
  14. package/dist/account/ClientInfo.d.ts.map +1 -1
  15. package/dist/account/ClientInfo.js +37 -35
  16. package/dist/account/ClientInfo.js.map +1 -1
  17. package/dist/account/DecodedAuthToken.d.ts +8 -8
  18. package/dist/account/DecodedAuthToken.d.ts.map +1 -1
  19. package/dist/account/TokenClaims.d.ts +65 -65
  20. package/dist/account/TokenClaims.d.ts.map +1 -1
  21. package/dist/authority/Authority.d.ts +228 -215
  22. package/dist/authority/Authority.d.ts.map +1 -1
  23. package/dist/authority/Authority.js +717 -765
  24. package/dist/authority/Authority.js.map +1 -1
  25. package/dist/authority/AuthorityFactory.d.ts +30 -30
  26. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  27. package/dist/authority/AuthorityFactory.js +48 -63
  28. package/dist/authority/AuthorityFactory.js.map +1 -1
  29. package/dist/authority/AuthorityMetadata.d.ts +622 -622
  30. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  31. package/dist/authority/AuthorityMetadata.js +877 -8
  32. package/dist/authority/AuthorityMetadata.js.map +1 -1
  33. package/dist/authority/AuthorityOptions.d.ts +18 -18
  34. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  35. package/dist/authority/AuthorityOptions.js +19 -19
  36. package/dist/authority/AuthorityOptions.js.map +1 -1
  37. package/dist/authority/AuthorityType.d.ts +9 -9
  38. package/dist/authority/AuthorityType.js +14 -14
  39. package/dist/authority/AuthorityType.js.map +1 -1
  40. package/dist/authority/AzureRegion.d.ts +1 -1
  41. package/dist/authority/AzureRegion.d.ts.map +1 -1
  42. package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
  43. package/dist/authority/AzureRegionConfiguration.d.ts.map +1 -1
  44. package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
  45. package/dist/authority/CloudDiscoveryMetadata.d.ts.map +1 -1
  46. package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
  47. package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts.map +1 -1
  48. package/dist/authority/CloudInstanceDiscoveryErrorResponse.js +8 -8
  49. package/dist/authority/CloudInstanceDiscoveryErrorResponse.js.map +1 -1
  50. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
  51. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts.map +1 -1
  52. package/dist/authority/CloudInstanceDiscoveryResponse.js +8 -8
  53. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  54. package/dist/authority/ImdsOptions.d.ts +5 -5
  55. package/dist/authority/ImdsOptions.d.ts.map +1 -1
  56. package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
  57. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
  58. package/dist/authority/OpenIdConfigResponse.js +10 -10
  59. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  60. package/dist/authority/ProtocolMode.d.ts +7 -7
  61. package/dist/authority/ProtocolMode.js +12 -12
  62. package/dist/authority/ProtocolMode.js.map +1 -1
  63. package/dist/authority/RegionDiscovery.d.ts +30 -30
  64. package/dist/authority/RegionDiscovery.d.ts.map +1 -1
  65. package/dist/authority/RegionDiscovery.js +110 -132
  66. package/dist/authority/RegionDiscovery.js.map +1 -1
  67. package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
  68. package/dist/authority/RegionDiscoveryMetadata.d.ts.map +1 -1
  69. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
  70. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts.map +1 -1
  71. package/dist/cache/CacheManager.d.ts +443 -443
  72. package/dist/cache/CacheManager.d.ts.map +1 -1
  73. package/dist/cache/CacheManager.js +1012 -1047
  74. package/dist/cache/CacheManager.js.map +1 -1
  75. package/dist/cache/entities/AccessTokenEntity.d.ts +56 -56
  76. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  77. package/dist/cache/entities/AccessTokenEntity.js +112 -113
  78. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  79. package/dist/cache/entities/AccountEntity.d.ts +99 -99
  80. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  81. package/dist/cache/entities/AccountEntity.js +249 -237
  82. package/dist/cache/entities/AccountEntity.js.map +1 -1
  83. package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
  84. package/dist/cache/entities/AppMetadataEntity.d.ts.map +1 -1
  85. package/dist/cache/entities/AppMetadataEntity.js +67 -68
  86. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  87. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +47 -47
  88. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  89. package/dist/cache/entities/AuthorityMetadataEntity.js +78 -75
  90. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  91. package/dist/cache/entities/CacheRecord.d.ts +13 -13
  92. package/dist/cache/entities/CacheRecord.d.ts.map +1 -1
  93. package/dist/cache/entities/CacheRecord.js +14 -15
  94. package/dist/cache/entities/CacheRecord.js.map +1 -1
  95. package/dist/cache/entities/CredentialEntity.d.ts +88 -88
  96. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  97. package/dist/cache/entities/CredentialEntity.js +137 -136
  98. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  99. package/dist/cache/entities/IdTokenEntity.d.ts +34 -34
  100. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  101. package/dist/cache/entities/IdTokenEntity.js +57 -63
  102. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  103. package/dist/cache/entities/RefreshTokenEntity.d.ts +36 -36
  104. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  105. package/dist/cache/entities/RefreshTokenEntity.js +60 -66
  106. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  107. package/dist/cache/entities/ServerTelemetryEntity.d.ts +12 -12
  108. package/dist/cache/entities/ServerTelemetryEntity.d.ts.map +1 -1
  109. package/dist/cache/entities/ServerTelemetryEntity.js +28 -29
  110. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  111. package/dist/cache/entities/ThrottlingEntity.d.ts +13 -13
  112. package/dist/cache/entities/ThrottlingEntity.js +24 -26
  113. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  114. package/dist/cache/interface/ICacheManager.d.ts +165 -165
  115. package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
  116. package/dist/cache/interface/ICachePlugin.d.ts +5 -5
  117. package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
  118. package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
  119. package/dist/cache/persistence/TokenCacheContext.d.ts.map +1 -1
  120. package/dist/cache/persistence/TokenCacheContext.js +26 -35
  121. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  122. package/dist/cache/utils/CacheTypes.d.ts +62 -62
  123. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  124. package/dist/client/AuthorizationCodeClient.d.ts +71 -71
  125. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  126. package/dist/client/AuthorizationCodeClient.js +435 -478
  127. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  128. package/dist/client/BaseClient.d.ts +50 -50
  129. package/dist/client/BaseClient.d.ts.map +1 -1
  130. package/dist/client/BaseClient.js +93 -101
  131. package/dist/client/BaseClient.js.map +1 -1
  132. package/dist/client/RefreshTokenClient.d.ts +34 -34
  133. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  134. package/dist/client/RefreshTokenClient.js +241 -274
  135. package/dist/client/RefreshTokenClient.js.map +1 -1
  136. package/dist/client/SilentFlowClient.d.ts +24 -24
  137. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  138. package/dist/client/SilentFlowClient.js +95 -123
  139. package/dist/client/SilentFlowClient.js.map +1 -1
  140. package/dist/config/AppTokenProvider.d.ts +38 -38
  141. package/dist/config/AppTokenProvider.d.ts.map +1 -1
  142. package/dist/config/ClientConfiguration.d.ts +133 -133
  143. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  144. package/dist/config/ClientConfiguration.js +88 -91
  145. package/dist/config/ClientConfiguration.js.map +1 -1
  146. package/dist/crypto/ICrypto.d.ts +62 -62
  147. package/dist/crypto/ICrypto.d.ts.map +1 -1
  148. package/dist/crypto/ICrypto.js +42 -73
  149. package/dist/crypto/ICrypto.js.map +1 -1
  150. package/dist/crypto/IGuidGenerator.d.ts +4 -4
  151. package/dist/crypto/JoseHeader.d.ts +21 -21
  152. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  153. package/dist/crypto/JoseHeader.js +37 -38
  154. package/dist/crypto/JoseHeader.js.map +1 -1
  155. package/dist/crypto/PopTokenGenerator.d.ts +57 -57
  156. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  157. package/dist/crypto/PopTokenGenerator.js +84 -108
  158. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  159. package/dist/crypto/SignedHttpRequest.d.ts +11 -11
  160. package/dist/crypto/SignedHttpRequest.d.ts.map +1 -1
  161. package/dist/error/AuthError.d.ts +47 -47
  162. package/dist/error/AuthError.d.ts.map +1 -1
  163. package/dist/error/AuthError.js +52 -55
  164. package/dist/error/AuthError.js.map +1 -1
  165. package/dist/error/ClientAuthError.d.ts +412 -404
  166. package/dist/error/ClientAuthError.d.ts.map +1 -1
  167. package/dist/error/ClientAuthError.js +520 -514
  168. package/dist/error/ClientAuthError.js.map +1 -1
  169. package/dist/error/ClientConfigurationError.d.ts +198 -198
  170. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  171. package/dist/error/ClientConfigurationError.js +250 -254
  172. package/dist/error/ClientConfigurationError.js.map +1 -1
  173. package/dist/error/InteractionRequiredAuthError.d.ts +59 -59
  174. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  175. package/dist/error/InteractionRequiredAuthError.js +79 -78
  176. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  177. package/dist/error/JoseHeaderError.d.ts +28 -28
  178. package/dist/error/JoseHeaderError.d.ts.map +1 -1
  179. package/dist/error/JoseHeaderError.js +40 -44
  180. package/dist/error/JoseHeaderError.js.map +1 -1
  181. package/dist/error/ServerError.d.ts +7 -7
  182. package/dist/error/ServerError.d.ts.map +1 -1
  183. package/dist/error/ServerError.js +15 -19
  184. package/dist/error/ServerError.js.map +1 -1
  185. package/dist/index.cjs.js +8890 -9111
  186. package/dist/index.cjs.js.map +1 -1
  187. package/dist/index.d.ts +93 -94
  188. package/dist/index.d.ts.map +1 -1
  189. package/dist/index.js +5 -6
  190. package/dist/index.js.map +1 -1
  191. package/dist/logger/Logger.d.ts +95 -95
  192. package/dist/logger/Logger.d.ts.map +1 -1
  193. package/dist/logger/Logger.js +198 -188
  194. package/dist/logger/Logger.js.map +1 -1
  195. package/dist/network/INetworkModule.d.ts +29 -29
  196. package/dist/network/INetworkModule.d.ts.map +1 -1
  197. package/dist/network/INetworkModule.js +14 -14
  198. package/dist/network/INetworkModule.js.map +1 -1
  199. package/dist/network/NetworkManager.d.ts +32 -31
  200. package/dist/network/NetworkManager.d.ts.map +1 -1
  201. package/dist/network/NetworkManager.js +34 -48
  202. package/dist/network/NetworkManager.js.map +1 -1
  203. package/dist/network/RequestThumbprint.d.ts +16 -16
  204. package/dist/network/RequestThumbprint.d.ts.map +1 -1
  205. package/dist/network/ThrottlingUtils.d.ts +41 -41
  206. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  207. package/dist/network/ThrottlingUtils.js +95 -94
  208. package/dist/network/ThrottlingUtils.js.map +1 -1
  209. package/dist/packageMetadata.d.ts +2 -2
  210. package/dist/packageMetadata.d.ts.map +1 -1
  211. package/dist/packageMetadata.js +4 -4
  212. package/dist/packageMetadata.js.map +1 -1
  213. package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
  214. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
  215. package/dist/request/AuthenticationHeaderParser.js +56 -57
  216. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  217. package/dist/request/BaseAuthRequest.d.ts +37 -37
  218. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  219. package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
  220. package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
  221. package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
  222. package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
  223. package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
  224. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  225. package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
  226. package/dist/request/CommonDeviceCodeRequest.d.ts.map +1 -1
  227. package/dist/request/CommonEndSessionRequest.d.ts +21 -21
  228. package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
  229. package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
  230. package/dist/request/CommonOnBehalfOfRequest.d.ts.map +1 -1
  231. package/dist/request/CommonRefreshTokenRequest.d.ts +19 -19
  232. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  233. package/dist/request/CommonSilentFlowRequest.d.ts +18 -18
  234. package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
  235. package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
  236. package/dist/request/CommonUsernamePasswordRequest.d.ts.map +1 -1
  237. package/dist/request/NativeRequest.d.ts +19 -19
  238. package/dist/request/NativeRequest.d.ts.map +1 -1
  239. package/dist/request/NativeSignOutRequest.d.ts +5 -5
  240. package/dist/request/NativeSignOutRequest.d.ts.map +1 -1
  241. package/dist/request/RequestParameterBuilder.d.ts +216 -216
  242. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  243. package/dist/request/RequestParameterBuilder.js +376 -378
  244. package/dist/request/RequestParameterBuilder.js.map +1 -1
  245. package/dist/request/RequestValidator.d.ts +33 -33
  246. package/dist/request/RequestValidator.d.ts.map +1 -1
  247. package/dist/request/RequestValidator.js +84 -89
  248. package/dist/request/RequestValidator.js.map +1 -1
  249. package/dist/request/ScopeSet.d.ts +88 -88
  250. package/dist/request/ScopeSet.d.ts.map +1 -1
  251. package/dist/request/ScopeSet.js +198 -198
  252. package/dist/request/ScopeSet.js.map +1 -1
  253. package/dist/response/AuthenticationResult.d.ts +39 -39
  254. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  255. package/dist/response/AuthorizationCodePayload.d.ts +13 -13
  256. package/dist/response/AuthorizationCodePayload.d.ts.map +1 -1
  257. package/dist/response/DeviceCodeResponse.d.ts +25 -25
  258. package/dist/response/DeviceCodeResponse.d.ts.map +1 -1
  259. package/dist/response/ExternalTokenResponse.d.ts +15 -15
  260. package/dist/response/ExternalTokenResponse.d.ts.map +1 -1
  261. package/dist/response/IMDSBadResponse.d.ts +4 -4
  262. package/dist/response/IMDSBadResponse.d.ts.map +1 -1
  263. package/dist/response/ResponseHandler.d.ts +72 -72
  264. package/dist/response/ResponseHandler.d.ts.map +1 -1
  265. package/dist/response/ResponseHandler.js +301 -286
  266. package/dist/response/ResponseHandler.js.map +1 -1
  267. package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
  268. package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +1 -1
  269. package/dist/response/ServerAuthorizationTokenResponse.d.ts +44 -44
  270. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  271. package/dist/telemetry/performance/IPerformanceClient.d.ts +42 -43
  272. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  273. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
  274. package/dist/telemetry/performance/PerformanceClient.d.ts +189 -197
  275. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  276. package/dist/telemetry/performance/PerformanceClient.js +407 -402
  277. package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
  278. package/dist/telemetry/performance/PerformanceEvent.d.ts +439 -439
  279. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  280. package/dist/telemetry/performance/PerformanceEvent.js +227 -227
  281. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  282. package/dist/telemetry/performance/StubPerformanceClient.d.ts +19 -17
  283. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  284. package/dist/telemetry/performance/StubPerformanceClient.js +37 -46
  285. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -1
  286. package/dist/telemetry/server/ServerTelemetryManager.d.ts +65 -66
  287. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  288. package/dist/telemetry/server/ServerTelemetryManager.js +199 -161
  289. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  290. package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
  291. package/dist/telemetry/server/ServerTelemetryRequest.d.ts.map +1 -1
  292. package/dist/url/IUri.d.ts +12 -12
  293. package/dist/url/UrlString.d.ts +70 -70
  294. package/dist/url/UrlString.d.ts.map +1 -1
  295. package/dist/url/UrlString.js +243 -232
  296. package/dist/url/UrlString.js.map +1 -1
  297. package/dist/utils/Constants.d.ts +331 -331
  298. package/dist/utils/Constants.d.ts.map +1 -1
  299. package/dist/utils/Constants.js +374 -373
  300. package/dist/utils/Constants.js.map +1 -1
  301. package/dist/utils/MsalTypes.d.ts +6 -6
  302. package/dist/utils/MsalTypes.d.ts.map +1 -1
  303. package/dist/utils/ProtocolUtils.d.ts +42 -42
  304. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  305. package/dist/utils/ProtocolUtils.js +72 -69
  306. package/dist/utils/ProtocolUtils.js.map +1 -1
  307. package/dist/utils/StringUtils.d.ts +53 -53
  308. package/dist/utils/StringUtils.d.ts.map +1 -1
  309. package/dist/utils/StringUtils.js +125 -123
  310. package/dist/utils/StringUtils.js.map +1 -1
  311. package/dist/utils/TimeUtils.d.ts +27 -27
  312. package/dist/utils/TimeUtils.d.ts.map +1 -1
  313. package/dist/utils/TimeUtils.js +46 -49
  314. package/dist/utils/TimeUtils.js.map +1 -1
  315. package/package.json +10 -7
  316. package/dist/_virtual/_tslib.js +0 -90
  317. package/dist/_virtual/_tslib.js.map +0 -1
  318. package/dist/client/ClientCredentialClient.d.ts +0 -38
  319. package/dist/client/ClientCredentialClient.d.ts.map +0 -1
  320. package/dist/client/ClientCredentialClient.js +0 -203
  321. package/dist/client/ClientCredentialClient.js.map +0 -1
  322. package/dist/client/DeviceCodeClient.d.ts +0 -57
  323. package/dist/client/DeviceCodeClient.d.ts.map +0 -1
  324. package/dist/client/DeviceCodeClient.js +0 -250
  325. package/dist/client/DeviceCodeClient.js.map +0 -1
  326. package/dist/client/OnBehalfOfClient.d.ts +0 -51
  327. package/dist/client/OnBehalfOfClient.d.ts.map +0 -1
  328. package/dist/client/OnBehalfOfClient.js +0 -248
  329. package/dist/client/OnBehalfOfClient.js.map +0 -1
  330. package/dist/client/UsernamePasswordClient.d.ts +0 -29
  331. package/dist/client/UsernamePasswordClient.d.ts.map +0 -1
  332. package/dist/client/UsernamePasswordClient.js +0 -129
  333. package/dist/client/UsernamePasswordClient.js.map +0 -1
@@ -1,11 +1,10 @@
1
- /*! @azure/msal-common v13.0.0 2023-05-01 */
1
+ /*! @azure/msal-common v14.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
- import { __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
4
3
  import { AuthorityType } from './AuthorityType.js';
5
4
  import { isOpenIdConfigResponse } from './OpenIdConfigResponse.js';
6
5
  import { UrlString } from '../url/UrlString.js';
7
6
  import { ClientAuthError } from '../error/ClientAuthError.js';
8
- import { Constants, AuthorityMetadataSource, RegionDiscoveryOutcomes } from '../utils/Constants.js';
7
+ import { Constants, AuthorityMetadataSource, RegionDiscoveryOutcomes, AADAuthorityConstants } from '../utils/Constants.js';
9
8
  import { EndpointMetadata, InstanceDiscoveryMetadata } from './AuthorityMetadata.js';
10
9
  import { ClientConfigurationError } from '../error/ClientConfigurationError.js';
11
10
  import { ProtocolMode } from './ProtocolMode.js';
@@ -17,768 +16,721 @@ import { RegionDiscovery } from './RegionDiscovery.js';
17
16
  import { AuthError } from '../error/AuthError.js';
18
17
  import { PerformanceEvents } from '../telemetry/performance/PerformanceEvent.js';
19
18
 
20
- /*
21
- * Copyright (c) Microsoft Corporation. All rights reserved.
22
- * Licensed under the MIT License.
23
- */
24
- /**
25
- * The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the
26
- * endpoint. It will store the pertinent config data in this object for use during token calls.
27
- */
28
- var Authority = /** @class */ (function () {
29
- function Authority(authority, networkInterface, cacheManager, authorityOptions, logger, performanceClient, correlationId) {
30
- this.canonicalAuthority = authority;
31
- this._canonicalAuthority.validateAsUri();
32
- this.networkInterface = networkInterface;
33
- this.cacheManager = cacheManager;
34
- this.authorityOptions = authorityOptions;
35
- this.regionDiscoveryMetadata = { region_used: undefined, region_source: undefined, region_outcome: undefined };
36
- this.logger = logger;
37
- this.performanceClient = performanceClient;
38
- this.correlationId = correlationId;
39
- this.regionDiscovery = new RegionDiscovery(networkInterface, this.performanceClient, this.correlationId);
40
- }
41
- Object.defineProperty(Authority.prototype, "authorityType", {
42
- // See above for AuthorityType
43
- get: function () {
44
- // CIAM auth url pattern is being standardized as: <tenant>.ciamlogin.com
45
- if (this.canonicalAuthorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL)) {
46
- return AuthorityType.Ciam;
47
- }
48
- var pathSegments = this.canonicalAuthorityUrlComponents.PathSegments;
49
- if (pathSegments.length) {
50
- switch (pathSegments[0].toLowerCase()) {
51
- case Constants.ADFS:
52
- return AuthorityType.Adfs;
53
- case Constants.DSTS:
54
- return AuthorityType.Dsts;
55
- }
56
- }
57
- return AuthorityType.Default;
58
- },
59
- enumerable: false,
60
- configurable: true
61
- });
62
- Object.defineProperty(Authority.prototype, "protocolMode", {
63
- /**
64
- * ProtocolMode enum representing the way endpoints are constructed.
65
- */
66
- get: function () {
67
- return this.authorityOptions.protocolMode;
68
- },
69
- enumerable: false,
70
- configurable: true
71
- });
72
- Object.defineProperty(Authority.prototype, "options", {
73
- /**
74
- * Returns authorityOptions which can be used to reinstantiate a new authority instance
75
- */
76
- get: function () {
77
- return this.authorityOptions;
78
- },
79
- enumerable: false,
80
- configurable: true
81
- });
82
- Object.defineProperty(Authority.prototype, "canonicalAuthority", {
83
- /**
84
- * A URL that is the authority set by the developer
85
- */
86
- get: function () {
87
- return this._canonicalAuthority.urlString;
88
- },
89
- /**
90
- * Sets canonical authority.
91
- */
92
- set: function (url) {
93
- this._canonicalAuthority = new UrlString(url);
94
- this._canonicalAuthority.validateAsUri();
95
- this._canonicalAuthorityUrlComponents = null;
96
- },
97
- enumerable: false,
98
- configurable: true
99
- });
100
- Object.defineProperty(Authority.prototype, "canonicalAuthorityUrlComponents", {
101
- /**
102
- * Get authority components.
103
- */
104
- get: function () {
105
- if (!this._canonicalAuthorityUrlComponents) {
106
- this._canonicalAuthorityUrlComponents = this._canonicalAuthority.getUrlComponents();
107
- }
108
- return this._canonicalAuthorityUrlComponents;
109
- },
110
- enumerable: false,
111
- configurable: true
112
- });
113
- Object.defineProperty(Authority.prototype, "hostnameAndPort", {
114
- /**
115
- * Get hostname and port i.e. login.microsoftonline.com
116
- */
117
- get: function () {
118
- return this.canonicalAuthorityUrlComponents.HostNameAndPort.toLowerCase();
119
- },
120
- enumerable: false,
121
- configurable: true
122
- });
123
- Object.defineProperty(Authority.prototype, "tenant", {
124
- /**
125
- * Get tenant for authority.
126
- */
127
- get: function () {
128
- return this.canonicalAuthorityUrlComponents.PathSegments[0];
129
- },
130
- enumerable: false,
131
- configurable: true
132
- });
133
- Object.defineProperty(Authority.prototype, "authorizationEndpoint", {
134
- /**
135
- * OAuth /authorize endpoint for requests
136
- */
137
- get: function () {
138
- if (this.discoveryComplete()) {
139
- var endpoint = this.replacePath(this.metadata.authorization_endpoint);
140
- return this.replaceTenant(endpoint);
141
- }
142
- else {
143
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
144
- }
145
- },
146
- enumerable: false,
147
- configurable: true
148
- });
149
- Object.defineProperty(Authority.prototype, "tokenEndpoint", {
150
- /**
151
- * OAuth /token endpoint for requests
152
- */
153
- get: function () {
154
- if (this.discoveryComplete()) {
155
- var endpoint = this.replacePath(this.metadata.token_endpoint);
156
- return this.replaceTenant(endpoint);
157
- }
158
- else {
159
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
160
- }
161
- },
162
- enumerable: false,
163
- configurable: true
164
- });
165
- Object.defineProperty(Authority.prototype, "deviceCodeEndpoint", {
166
- get: function () {
167
- if (this.discoveryComplete()) {
168
- var endpoint = this.replacePath(this.metadata.token_endpoint.replace("/token", "/devicecode"));
169
- return this.replaceTenant(endpoint);
170
- }
171
- else {
172
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
173
- }
174
- },
175
- enumerable: false,
176
- configurable: true
177
- });
178
- Object.defineProperty(Authority.prototype, "endSessionEndpoint", {
179
- /**
180
- * OAuth logout endpoint for requests
181
- */
182
- get: function () {
183
- if (this.discoveryComplete()) {
184
- // ROPC policies may not have end_session_endpoint set
185
- if (!this.metadata.end_session_endpoint) {
186
- throw ClientAuthError.createLogoutNotSupportedError();
187
- }
188
- var endpoint = this.replacePath(this.metadata.end_session_endpoint);
189
- return this.replaceTenant(endpoint);
190
- }
191
- else {
192
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
193
- }
194
- },
195
- enumerable: false,
196
- configurable: true
197
- });
198
- Object.defineProperty(Authority.prototype, "selfSignedJwtAudience", {
199
- /**
200
- * OAuth issuer for requests
201
- */
202
- get: function () {
203
- if (this.discoveryComplete()) {
204
- var endpoint = this.replacePath(this.metadata.issuer);
205
- return this.replaceTenant(endpoint);
206
- }
207
- else {
208
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
209
- }
210
- },
211
- enumerable: false,
212
- configurable: true
213
- });
214
- Object.defineProperty(Authority.prototype, "jwksUri", {
215
- /**
216
- * Jwks_uri for token signing keys
217
- */
218
- get: function () {
219
- if (this.discoveryComplete()) {
220
- var endpoint = this.replacePath(this.metadata.jwks_uri);
221
- return this.replaceTenant(endpoint);
222
- }
223
- else {
224
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
225
- }
226
- },
227
- enumerable: false,
228
- configurable: true
229
- });
230
- /**
231
- * Replaces tenant in url path with current tenant. Defaults to common.
232
- * @param urlString
233
- */
234
- Authority.prototype.replaceTenant = function (urlString) {
235
- return urlString.replace(/{tenant}|{tenantid}/g, this.tenant);
236
- };
237
- /**
238
- * Replaces path such as tenant or policy with the current tenant or policy.
239
- * @param urlString
240
- */
241
- Authority.prototype.replacePath = function (urlString) {
242
- var endpoint = urlString;
243
- var cachedAuthorityUrl = new UrlString(this.metadata.canonical_authority);
244
- var cachedAuthorityParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
245
- var currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
246
- currentAuthorityParts.forEach(function (currentPart, index) {
247
- var cachedPart = cachedAuthorityParts[index];
248
- if (currentPart !== cachedPart) {
249
- endpoint = endpoint.replace("/" + cachedPart + "/", "/" + currentPart + "/");
250
- }
251
- });
252
- return endpoint;
253
- };
254
- Object.defineProperty(Authority.prototype, "defaultOpenIdConfigurationEndpoint", {
255
- /**
256
- * The default open id configuration endpoint for any canonical authority.
257
- */
258
- get: function () {
259
- if (this.authorityType === AuthorityType.Adfs ||
260
- this.authorityType === AuthorityType.Dsts ||
261
- this.protocolMode === ProtocolMode.OIDC) {
262
- return this.canonicalAuthority + ".well-known/openid-configuration";
263
- }
264
- return this.canonicalAuthority + "v2.0/.well-known/openid-configuration";
265
- },
266
- enumerable: false,
267
- configurable: true
268
- });
269
- /**
270
- * Boolean that returns whethr or not tenant discovery has been completed.
271
- */
272
- Authority.prototype.discoveryComplete = function () {
273
- return !!this.metadata;
274
- };
275
- /**
276
- * Perform endpoint discovery to discover aliases, preferred_cache, preferred_network
277
- * and the /authorize, /token and logout endpoints.
278
- */
279
- Authority.prototype.resolveEndpointsAsync = function () {
280
- var _a, _b, _c;
281
- return __awaiter(this, void 0, void 0, function () {
282
- var metadataEntity, cloudDiscoverySource, endpointSource, cacheKey;
283
- return __generator(this, function (_d) {
284
- switch (_d.label) {
285
- case 0:
286
- (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(PerformanceEvents.AuthorityResolveEndpointsAsync, this.correlationId);
287
- metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(this.hostnameAndPort);
288
- if (!metadataEntity) {
289
- metadataEntity = new AuthorityMetadataEntity();
290
- metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
291
- }
292
- (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.setPreQueueTime(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
293
- return [4 /*yield*/, this.updateCloudDiscoveryMetadata(metadataEntity)];
294
- case 1:
295
- cloudDiscoverySource = _d.sent();
296
- this.canonicalAuthority = this.canonicalAuthority.replace(this.hostnameAndPort, metadataEntity.preferred_network);
297
- (_c = this.performanceClient) === null || _c === void 0 ? void 0 : _c.setPreQueueTime(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
298
- return [4 /*yield*/, this.updateEndpointMetadata(metadataEntity)];
299
- case 2:
300
- endpointSource = _d.sent();
301
- if (cloudDiscoverySource !== AuthorityMetadataSource.CACHE && endpointSource !== AuthorityMetadataSource.CACHE) {
302
- // Reset the expiration time unless both values came from a successful cache lookup
303
- metadataEntity.resetExpiresAt();
304
- metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
305
- }
306
- cacheKey = this.cacheManager.generateAuthorityMetadataCacheKey(metadataEntity.preferred_cache);
307
- this.cacheManager.setAuthorityMetadata(cacheKey, metadataEntity);
308
- this.metadata = metadataEntity;
309
- return [2 /*return*/];
310
- }
311
- });
312
- });
313
- };
314
- /**
315
- * Update AuthorityMetadataEntity with new endpoints and return where the information came from
316
- * @param metadataEntity
317
- */
318
- Authority.prototype.updateEndpointMetadata = function (metadataEntity) {
319
- var _a, _b, _c, _d, _e, _f;
320
- return __awaiter(this, void 0, void 0, function () {
321
- var metadata, harcodedMetadata;
322
- return __generator(this, function (_g) {
323
- switch (_g.label) {
324
- case 0:
325
- (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
326
- metadata = this.getEndpointMetadataFromConfig();
327
- if (metadata) {
328
- metadataEntity.updateEndpointMetadata(metadata, false);
329
- return [2 /*return*/, AuthorityMetadataSource.CONFIG];
330
- }
331
- if (this.isAuthoritySameType(metadataEntity) && metadataEntity.endpointsFromNetwork && !metadataEntity.isExpired()) {
332
- // No need to update
333
- return [2 /*return*/, AuthorityMetadataSource.CACHE];
334
- }
335
- (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.setPreQueueTime(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
336
- return [4 /*yield*/, this.getEndpointMetadataFromNetwork()];
337
- case 1:
338
- metadata = _g.sent();
339
- if (!metadata) return [3 /*break*/, 4];
340
- if (!((_c = this.authorityOptions.azureRegionConfiguration) === null || _c === void 0 ? void 0 : _c.azureRegion)) return [3 /*break*/, 3];
341
- (_d = this.performanceClient) === null || _d === void 0 ? void 0 : _d.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
342
- return [4 /*yield*/, this.updateMetadataWithRegionalInformation(metadata)];
343
- case 2:
344
- metadata = _g.sent();
345
- _g.label = 3;
346
- case 3:
347
- metadataEntity.updateEndpointMetadata(metadata, true);
348
- return [2 /*return*/, AuthorityMetadataSource.NETWORK];
349
- case 4:
350
- harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
351
- if (!(harcodedMetadata && !this.authorityOptions.skipAuthorityMetadataCache)) return [3 /*break*/, 7];
352
- if (!((_e = this.authorityOptions.azureRegionConfiguration) === null || _e === void 0 ? void 0 : _e.azureRegion)) return [3 /*break*/, 6];
353
- (_f = this.performanceClient) === null || _f === void 0 ? void 0 : _f.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
354
- return [4 /*yield*/, this.updateMetadataWithRegionalInformation(harcodedMetadata)];
355
- case 5:
356
- harcodedMetadata = _g.sent();
357
- _g.label = 6;
358
- case 6:
359
- metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
360
- return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
361
- case 7: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
362
- }
363
- });
364
- });
365
- };
366
- /**
367
- * Compares the number of url components after the domain to determine if the cached
368
- * authority metadata can be used for the requested authority. Protects against same domain different
369
- * authority such as login.microsoftonline.com/tenant and login.microsoftonline.com/tfp/tenant/policy
370
- * @param metadataEntity
371
- */
372
- Authority.prototype.isAuthoritySameType = function (metadataEntity) {
373
- var cachedAuthorityUrl = new UrlString(metadataEntity.canonical_authority);
374
- var cachedParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
375
- return cachedParts.length === this.canonicalAuthorityUrlComponents.PathSegments.length;
376
- };
377
- /**
378
- * Parse authorityMetadata config option
379
- */
380
- Authority.prototype.getEndpointMetadataFromConfig = function () {
381
- if (this.authorityOptions.authorityMetadata) {
382
- try {
383
- return JSON.parse(this.authorityOptions.authorityMetadata);
384
- }
385
- catch (e) {
386
- throw ClientConfigurationError.createInvalidAuthorityMetadataError();
387
- }
388
- }
389
- return null;
390
- };
391
- /**
392
- * Gets OAuth endpoints from the given OpenID configuration endpoint.
393
- *
394
- * @param hasHardcodedMetadata boolean
395
- */
396
- Authority.prototype.getEndpointMetadataFromNetwork = function () {
397
- var _a;
398
- return __awaiter(this, void 0, void 0, function () {
399
- var options, response;
400
- return __generator(this, function (_b) {
401
- switch (_b.label) {
402
- case 0:
403
- (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
404
- options = {};
405
- _b.label = 1;
406
- case 1:
407
- _b.trys.push([1, 3, , 4]);
408
- return [4 /*yield*/, this.networkInterface.
409
- sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint, options)];
410
- case 2:
411
- response = _b.sent();
412
- return [2 /*return*/, isOpenIdConfigResponse(response.body) ? response.body : null];
413
- case 3:
414
- _b.sent();
415
- return [2 /*return*/, null];
416
- case 4: return [2 /*return*/];
417
- }
418
- });
419
- });
420
- };
421
- /**
422
- * Get OAuth endpoints for common authorities.
423
- */
424
- Authority.prototype.getEndpointMetadataFromHardcodedValues = function () {
425
- if (this.canonicalAuthority in EndpointMetadata) {
426
- return EndpointMetadata[this.canonicalAuthority];
427
- }
428
- return null;
429
- };
430
- /**
431
- * Update the retrieved metadata with regional information.
432
- */
433
- Authority.prototype.updateMetadataWithRegionalInformation = function (metadata) {
434
- var _a, _b, _c, _d, _e, _f, _g;
435
- return __awaiter(this, void 0, void 0, function () {
436
- var autodetectedRegionName, azureRegion;
437
- return __generator(this, function (_h) {
438
- switch (_h.label) {
439
- case 0:
440
- (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
441
- (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.setPreQueueTime(PerformanceEvents.RegionDiscoveryDetectRegion, this.correlationId);
442
- return [4 /*yield*/, this.regionDiscovery.detectRegion((_c = this.authorityOptions.azureRegionConfiguration) === null || _c === void 0 ? void 0 : _c.environmentRegion, this.regionDiscoveryMetadata)];
443
- case 1:
444
- autodetectedRegionName = _h.sent();
445
- azureRegion = ((_d = this.authorityOptions.azureRegionConfiguration) === null || _d === void 0 ? void 0 : _d.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
446
- ? autodetectedRegionName
447
- : (_e = this.authorityOptions.azureRegionConfiguration) === null || _e === void 0 ? void 0 : _e.azureRegion;
448
- if (((_f = this.authorityOptions.azureRegionConfiguration) === null || _f === void 0 ? void 0 : _f.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
449
- this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
450
- RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
451
- RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
452
- }
453
- else {
454
- if (autodetectedRegionName) {
455
- this.regionDiscoveryMetadata.region_outcome = (((_g = this.authorityOptions.azureRegionConfiguration) === null || _g === void 0 ? void 0 : _g.azureRegion) === autodetectedRegionName) ?
456
- RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
457
- RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
458
- }
459
- else {
460
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
461
- }
462
- }
463
- if (azureRegion) {
464
- this.regionDiscoveryMetadata.region_used = azureRegion;
465
- return [2 /*return*/, Authority.replaceWithRegionalInformation(metadata, azureRegion)];
466
- }
467
- return [2 /*return*/, metadata];
468
- }
469
- });
470
- });
471
- };
472
- /**
473
- * Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache
474
- * and returns where the information was retrieved from
475
- * @param metadataEntity
476
- * @returns AuthorityMetadataSource
477
- */
478
- Authority.prototype.updateCloudDiscoveryMetadata = function (metadataEntity) {
479
- var _a, _b;
480
- return __awaiter(this, void 0, void 0, function () {
481
- var metadata, metadataEntityExpired, harcodedMetadata;
482
- return __generator(this, function (_c) {
483
- switch (_c.label) {
484
- case 0:
485
- (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
486
- // attempt to read metadata from the config
487
- this.logger.verbose("Attempting to get cloud discovery metadata in the config");
488
- this.logger.verbosePii("Known Authorities: " + (this.authorityOptions.knownAuthorities || Constants.NOT_APPLICABLE));
489
- this.logger.verbosePii("Authority Metadata: " + (this.authorityOptions.authorityMetadata || Constants.NOT_APPLICABLE));
490
- this.logger.verbosePii("Canonical Authority: " + (metadataEntity.canonical_authority || Constants.NOT_APPLICABLE));
491
- metadata = this.getCloudDiscoveryMetadataFromConfig();
492
- if (metadata) {
493
- this.logger.verbose("Found cloud discovery metadata in the config.");
494
- metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
495
- return [2 /*return*/, AuthorityMetadataSource.CONFIG];
496
- }
497
- // If the cached metadata came from config but that config was not passed to this instance, we must go to the network
498
- this.logger.verbose("Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the cache.");
499
- metadataEntityExpired = metadataEntity.isExpired();
500
- if (this.isAuthoritySameType(metadataEntity) && metadataEntity.aliasesFromNetwork && !metadataEntityExpired) {
501
- this.logger.verbose("Found metadata in the cache.");
502
- // No need to update
503
- return [2 /*return*/, AuthorityMetadataSource.CACHE];
504
- }
505
- else if (metadataEntityExpired) {
506
- this.logger.verbose("The metadata entity is expired.");
507
- }
508
- this.logger.verbose("Did not find cloud discovery metadata in the cache... Attempting to get cloud discovery metadata from the network.");
509
- (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.setPreQueueTime(PerformanceEvents.AuthorityGetCloudDiscoveryMetadataFromNetwork, this.correlationId);
510
- return [4 /*yield*/, this.getCloudDiscoveryMetadataFromNetwork()];
511
- case 1:
512
- metadata = _c.sent();
513
- if (metadata) {
514
- this.logger.verbose("cloud discovery metadata was successfully returned from getCloudDiscoveryMetadataFromNetwork()");
515
- metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
516
- return [2 /*return*/, AuthorityMetadataSource.NETWORK];
517
- }
518
- this.logger.verbose("Did not find cloud discovery metadata from the network... Attempting to get cloud discovery metadata from hardcoded values.");
519
- harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
520
- if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
521
- this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
522
- metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
523
- return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
524
- }
525
- // Metadata could not be obtained from the config, cache, network or hardcoded values
526
- 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.");
527
- throw ClientConfigurationError.createUntrustedAuthorityError();
528
- }
529
- });
530
- });
531
- };
532
- /**
533
- * Parse cloudDiscoveryMetadata config or check knownAuthorities
534
- */
535
- Authority.prototype.getCloudDiscoveryMetadataFromConfig = function () {
536
- // CIAM does not support cloud discovery metadata
537
- if (this.authorityType === AuthorityType.Ciam) {
538
- this.logger.verbose("CIAM authorities do not support cloud discovery metadata, generate the aliases from authority host.");
539
- return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
540
- }
541
- // Check if network response was provided in config
542
- if (this.authorityOptions.cloudDiscoveryMetadata) {
543
- this.logger.verbose("The cloud discovery metadata has been provided as a network response, in the config.");
544
- try {
545
- this.logger.verbose("Attempting to parse the cloud discovery metadata.");
546
- var parsedResponse = JSON.parse(this.authorityOptions.cloudDiscoveryMetadata);
547
- var metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(parsedResponse.metadata, this.hostnameAndPort);
548
- this.logger.verbose("Parsed the cloud discovery metadata.");
549
- if (metadata) {
550
- this.logger.verbose("There is returnable metadata attached to the parsed cloud discovery metadata.");
551
- return metadata;
552
- }
553
- else {
554
- this.logger.verbose("There is no metadata attached to the parsed cloud discovery metadata.");
555
- }
556
- }
557
- catch (e) {
558
- this.logger.verbose("Unable to parse the cloud discovery metadata. Throwing Invalid Cloud Discovery Metadata Error.");
559
- throw ClientConfigurationError.createInvalidCloudDiscoveryMetadataError();
560
- }
561
- }
562
- // If cloudDiscoveryMetadata is empty or does not contain the host, check knownAuthorities
563
- if (this.isInKnownAuthorities()) {
564
- this.logger.verbose("The host is included in knownAuthorities. Creating new cloud discovery metadata from the host.");
565
- return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
566
- }
567
- return null;
568
- };
569
- /**
570
- * Called to get metadata from network if CloudDiscoveryMetadata was not populated by config
571
- *
572
- * @param hasHardcodedMetadata boolean
573
- */
574
- Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
575
- var _a;
576
- return __awaiter(this, void 0, void 0, function () {
577
- var instanceDiscoveryEndpoint, options, match, response, typedResponseBody, metadata, error_1, typedError;
578
- return __generator(this, function (_b) {
579
- switch (_b.label) {
580
- case 0:
581
- (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(PerformanceEvents.AuthorityGetCloudDiscoveryMetadataFromNetwork, this.correlationId);
582
- instanceDiscoveryEndpoint = "" + Constants.AAD_INSTANCE_DISCOVERY_ENDPT + this.canonicalAuthority + "oauth2/v2.0/authorize";
583
- options = {};
584
- match = null;
585
- _b.label = 1;
586
- case 1:
587
- _b.trys.push([1, 3, , 4]);
588
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options)];
589
- case 2:
590
- response = _b.sent();
591
- typedResponseBody = void 0;
592
- metadata = void 0;
593
- if (isCloudInstanceDiscoveryResponse(response.body)) {
594
- typedResponseBody = response.body;
595
- metadata = typedResponseBody.metadata;
596
- this.logger.verbosePii("tenant_discovery_endpoint is: " + typedResponseBody.tenant_discovery_endpoint);
597
- }
598
- else if (isCloudInstanceDiscoveryErrorResponse(response.body)) {
599
- this.logger.warning("A CloudInstanceDiscoveryErrorResponse was returned. The cloud instance discovery network request's status code is: " + response.status);
600
- typedResponseBody = response.body;
601
- if (typedResponseBody.error === Constants.INVALID_INSTANCE) {
602
- this.logger.error("The CloudInstanceDiscoveryErrorResponse error is invalid_instance.");
603
- return [2 /*return*/, null];
604
- }
605
- this.logger.warning("The CloudInstanceDiscoveryErrorResponse error is " + typedResponseBody.error);
606
- this.logger.warning("The CloudInstanceDiscoveryErrorResponse error description is " + typedResponseBody.error_description);
607
- this.logger.warning("Setting the value of the CloudInstanceDiscoveryMetadata (returned from the network) to []");
608
- metadata = [];
609
- }
610
- else {
611
- this.logger.error("AAD did not return a CloudInstanceDiscoveryResponse or CloudInstanceDiscoveryErrorResponse");
612
- return [2 /*return*/, null];
613
- }
614
- this.logger.verbose("Attempting to find a match between the developer's authority and the CloudInstanceDiscoveryMetadata returned from the network request.");
615
- match = Authority.getCloudDiscoveryMetadataFromNetworkResponse(metadata, this.hostnameAndPort);
616
- return [3 /*break*/, 4];
617
- case 3:
618
- error_1 = _b.sent();
619
- if (error_1 instanceof AuthError) {
620
- this.logger.error("There was a network error while attempting to get the cloud discovery instance metadata.\nError: " + error_1.errorCode + "\nError Description: " + error_1.errorMessage);
621
- }
622
- else {
623
- typedError = error_1;
624
- this.logger.error("A non-MSALJS error was thrown while attempting to get the cloud instance discovery metadata.\nError: " + typedError.name + "\nError Description: " + typedError.message);
625
- }
626
- return [2 /*return*/, null];
627
- case 4:
628
- // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
629
- if (!match) {
630
- this.logger.warning("The developer's authority was not found within the CloudInstanceDiscoveryMetadata returned from the network request.");
631
- this.logger.verbose("Creating custom Authority for custom domain scenario.");
632
- match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
633
- }
634
- return [2 /*return*/, match];
635
- }
636
- });
637
- });
638
- };
639
- /**
640
- * Get cloud discovery metadata for common authorities
641
- */
642
- Authority.prototype.getCloudDiscoveryMetadataFromHarcodedValues = function () {
643
- if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
644
- return InstanceDiscoveryMetadata[this.canonicalAuthority];
645
- }
646
- return null;
647
- };
648
- /**
649
- * Helper function to determine if this host is included in the knownAuthorities config option
650
- */
651
- Authority.prototype.isInKnownAuthorities = function () {
652
- var _this = this;
653
- var matches = this.authorityOptions.knownAuthorities.filter(function (authority) {
654
- return UrlString.getDomainFromUrl(authority).toLowerCase() === _this.hostnameAndPort;
655
- });
656
- return matches.length > 0;
657
- };
658
- /**
659
- * helper function to populate the authority based on azureCloudOptions
660
- * @param authorityString
661
- * @param azureCloudOptions
662
- */
663
- Authority.generateAuthority = function (authorityString, azureCloudOptions) {
664
- var authorityAzureCloudInstance;
665
- if (azureCloudOptions && azureCloudOptions.azureCloudInstance !== AzureCloudInstance.None) {
666
- var tenant = azureCloudOptions.tenant ? azureCloudOptions.tenant : Constants.DEFAULT_COMMON_TENANT;
667
- authorityAzureCloudInstance = azureCloudOptions.azureCloudInstance + "/" + tenant + "/";
668
- }
669
- return authorityAzureCloudInstance ? authorityAzureCloudInstance : authorityString;
670
- };
671
- /**
672
- * Creates cloud discovery metadata object from a given host
673
- * @param host
674
- */
675
- Authority.createCloudDiscoveryMetadataFromHost = function (host) {
676
- return {
677
- preferred_network: host,
678
- preferred_cache: host,
679
- aliases: [host]
680
- };
681
- };
682
- /**
683
- * Searches instance discovery network response for the entry that contains the host in the aliases list
684
- * @param response
685
- * @param authority
686
- */
687
- Authority.getCloudDiscoveryMetadataFromNetworkResponse = function (response, authority) {
688
- for (var i = 0; i < response.length; i++) {
689
- var metadata = response[i];
690
- if (metadata.aliases.indexOf(authority) > -1) {
691
- return metadata;
692
- }
693
- }
694
- return null;
695
- };
696
- /**
697
- * helper function to generate environment from authority object
698
- */
699
- Authority.prototype.getPreferredCache = function () {
700
- if (this.discoveryComplete()) {
701
- return this.metadata.preferred_cache;
702
- }
703
- else {
704
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
705
- }
706
- };
707
- /**
708
- * Returns whether or not the provided host is an alias of this authority instance
709
- * @param host
710
- */
711
- Authority.prototype.isAlias = function (host) {
712
- return this.metadata.aliases.indexOf(host) > -1;
713
- };
714
- /**
715
- * Checks whether the provided host is that of a public cloud authority
716
- *
717
- * @param authority string
718
- * @returns bool
719
- */
720
- Authority.isPublicCloudAuthority = function (host) {
721
- return Constants.KNOWN_PUBLIC_CLOUDS.indexOf(host) >= 0;
722
- };
723
- /**
724
- * Rebuild the authority string with the region
725
- *
726
- * @param host string
727
- * @param region string
728
- */
729
- Authority.buildRegionalAuthorityString = function (host, region, queryString) {
730
- // Create and validate a Url string object with the initial authority string
731
- var authorityUrlInstance = new UrlString(host);
732
- authorityUrlInstance.validateAsUri();
733
- var authorityUrlParts = authorityUrlInstance.getUrlComponents();
734
- var hostNameAndPort = region + "." + authorityUrlParts.HostNameAndPort;
735
- if (this.isPublicCloudAuthority(authorityUrlParts.HostNameAndPort)) {
736
- hostNameAndPort = region + "." + Constants.REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX;
737
- }
738
- // Include the query string portion of the url
739
- var url = UrlString.constructAuthorityUriFromObject(__assign(__assign({}, authorityUrlInstance.getUrlComponents()), { HostNameAndPort: hostNameAndPort })).urlString;
740
- // Add the query string if a query string was provided
741
- if (queryString)
742
- return url + "?" + queryString;
743
- return url;
744
- };
745
- /**
746
- * Replace the endpoints in the metadata object with their regional equivalents.
747
- *
748
- * @param metadata OpenIdConfigResponse
749
- * @param azureRegion string
750
- */
751
- Authority.replaceWithRegionalInformation = function (metadata, azureRegion) {
752
- metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
753
- // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
754
- metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
755
- if (metadata.end_session_endpoint) {
756
- metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
757
- }
758
- return metadata;
759
- };
760
- /**
761
- * Transform CIAM_AUTHORIY as per the below rules:
762
- * If no path segments found and it is a CIAM authority (hostname ends with .ciamlogin.com), then transform it
763
- *
764
- * NOTE: The transformation path should go away once STS supports CIAM with the format: `tenantIdorDomain.ciamlogin.com`
765
- * `ciamlogin.com` can also change in the future and we should accommodate the same
766
- *
767
- * @param authority
768
- */
769
- Authority.transformCIAMAuthority = function (authority) {
770
- var ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH) ? authority : "" + authority + Constants.FORWARD_SLASH;
771
- var authorityUrl = new UrlString(authority);
772
- var authorityUrlComponents = authorityUrl.getUrlComponents();
773
- // check if transformation is needed
774
- if (authorityUrlComponents.PathSegments.length === 0 && (authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL))) {
775
- var tenantIdOrDomain = authorityUrlComponents.HostNameAndPort.split(".")[0];
776
- ciamAuthority = "" + ciamAuthority + tenantIdOrDomain + Constants.AAD_TENANT_DOMAIN_SUFFIX;
777
- }
778
- return ciamAuthority;
779
- };
780
- return Authority;
781
- }());
19
+ /*
20
+ * Copyright (c) Microsoft Corporation. All rights reserved.
21
+ * Licensed under the MIT License.
22
+ */
23
+ /**
24
+ * The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the
25
+ * endpoint. It will store the pertinent config data in this object for use during token calls.
26
+ */
27
+ class Authority {
28
+ constructor(authority, networkInterface, cacheManager, authorityOptions, logger, performanceClient, correlationId) {
29
+ this.canonicalAuthority = authority;
30
+ this._canonicalAuthority.validateAsUri();
31
+ this.networkInterface = networkInterface;
32
+ this.cacheManager = cacheManager;
33
+ this.authorityOptions = authorityOptions;
34
+ this.regionDiscoveryMetadata = {
35
+ region_used: undefined,
36
+ region_source: undefined,
37
+ region_outcome: undefined,
38
+ };
39
+ this.logger = logger;
40
+ this.performanceClient = performanceClient;
41
+ this.correlationId = correlationId;
42
+ this.regionDiscovery = new RegionDiscovery(networkInterface, this.performanceClient, this.correlationId);
43
+ }
44
+ /**
45
+ * Get {@link AuthorityType}
46
+ * @param authorityUri {@link IUri}
47
+ * @private
48
+ */
49
+ getAuthorityType(authorityUri) {
50
+ // CIAM auth url pattern is being standardized as: <tenant>.ciamlogin.com
51
+ if (authorityUri.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL)) {
52
+ return AuthorityType.Ciam;
53
+ }
54
+ const pathSegments = authorityUri.PathSegments;
55
+ if (pathSegments.length) {
56
+ switch (pathSegments[0].toLowerCase()) {
57
+ case Constants.ADFS:
58
+ return AuthorityType.Adfs;
59
+ case Constants.DSTS:
60
+ return AuthorityType.Dsts;
61
+ }
62
+ }
63
+ return AuthorityType.Default;
64
+ }
65
+ // See above for AuthorityType
66
+ get authorityType() {
67
+ return this.getAuthorityType(this.canonicalAuthorityUrlComponents);
68
+ }
69
+ /**
70
+ * ProtocolMode enum representing the way endpoints are constructed.
71
+ */
72
+ get protocolMode() {
73
+ return this.authorityOptions.protocolMode;
74
+ }
75
+ /**
76
+ * Returns authorityOptions which can be used to reinstantiate a new authority instance
77
+ */
78
+ get options() {
79
+ return this.authorityOptions;
80
+ }
81
+ /**
82
+ * A URL that is the authority set by the developer
83
+ */
84
+ get canonicalAuthority() {
85
+ return this._canonicalAuthority.urlString;
86
+ }
87
+ /**
88
+ * Sets canonical authority.
89
+ */
90
+ set canonicalAuthority(url) {
91
+ this._canonicalAuthority = new UrlString(url);
92
+ this._canonicalAuthority.validateAsUri();
93
+ this._canonicalAuthorityUrlComponents = null;
94
+ }
95
+ /**
96
+ * Get authority components.
97
+ */
98
+ get canonicalAuthorityUrlComponents() {
99
+ if (!this._canonicalAuthorityUrlComponents) {
100
+ this._canonicalAuthorityUrlComponents =
101
+ this._canonicalAuthority.getUrlComponents();
102
+ }
103
+ return this._canonicalAuthorityUrlComponents;
104
+ }
105
+ /**
106
+ * Get hostname and port i.e. login.microsoftonline.com
107
+ */
108
+ get hostnameAndPort() {
109
+ return this.canonicalAuthorityUrlComponents.HostNameAndPort.toLowerCase();
110
+ }
111
+ /**
112
+ * Get tenant for authority.
113
+ */
114
+ get tenant() {
115
+ return this.canonicalAuthorityUrlComponents.PathSegments[0];
116
+ }
117
+ /**
118
+ * OAuth /authorize endpoint for requests
119
+ */
120
+ get authorizationEndpoint() {
121
+ if (this.discoveryComplete()) {
122
+ return this.replacePath(this.metadata.authorization_endpoint);
123
+ }
124
+ else {
125
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
126
+ }
127
+ }
128
+ /**
129
+ * OAuth /token endpoint for requests
130
+ */
131
+ get tokenEndpoint() {
132
+ if (this.discoveryComplete()) {
133
+ return this.replacePath(this.metadata.token_endpoint);
134
+ }
135
+ else {
136
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
137
+ }
138
+ }
139
+ get deviceCodeEndpoint() {
140
+ if (this.discoveryComplete()) {
141
+ return this.replacePath(this.metadata.token_endpoint.replace("/token", "/devicecode"));
142
+ }
143
+ else {
144
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
145
+ }
146
+ }
147
+ /**
148
+ * OAuth logout endpoint for requests
149
+ */
150
+ get endSessionEndpoint() {
151
+ if (this.discoveryComplete()) {
152
+ // ROPC policies may not have end_session_endpoint set
153
+ if (!this.metadata.end_session_endpoint) {
154
+ throw ClientAuthError.createLogoutNotSupportedError();
155
+ }
156
+ return this.replacePath(this.metadata.end_session_endpoint);
157
+ }
158
+ else {
159
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
160
+ }
161
+ }
162
+ /**
163
+ * OAuth issuer for requests
164
+ */
165
+ get selfSignedJwtAudience() {
166
+ if (this.discoveryComplete()) {
167
+ return this.replacePath(this.metadata.issuer);
168
+ }
169
+ else {
170
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
171
+ }
172
+ }
173
+ /**
174
+ * Jwks_uri for token signing keys
175
+ */
176
+ get jwksUri() {
177
+ if (this.discoveryComplete()) {
178
+ return this.replacePath(this.metadata.jwks_uri);
179
+ }
180
+ else {
181
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
182
+ }
183
+ }
184
+ /**
185
+ * Returns a flag indicating that tenant name can be replaced in authority {@link IUri}
186
+ * @param authorityUri {@link IUri}
187
+ * @private
188
+ */
189
+ canReplaceTenant(authorityUri) {
190
+ return authorityUri.PathSegments.length === 1
191
+ && !Authority.reservedTenantDomains.has(authorityUri.PathSegments[0])
192
+ && this.getAuthorityType(authorityUri) === AuthorityType.Default
193
+ && this.protocolMode === ProtocolMode.AAD;
194
+ }
195
+ /**
196
+ * Replaces tenant in url path with current tenant. Defaults to common.
197
+ * @param urlString
198
+ */
199
+ replaceTenant(urlString) {
200
+ return urlString.replace(/{tenant}|{tenantid}/g, this.tenant);
201
+ }
202
+ /**
203
+ * Replaces path such as tenant or policy with the current tenant or policy.
204
+ * @param urlString
205
+ */
206
+ replacePath(urlString) {
207
+ let endpoint = urlString;
208
+ const cachedAuthorityUrl = new UrlString(this.metadata.canonical_authority);
209
+ const cachedAuthorityUrlComponents = cachedAuthorityUrl.getUrlComponents();
210
+ const cachedAuthorityParts = cachedAuthorityUrlComponents.PathSegments;
211
+ const currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
212
+ currentAuthorityParts.forEach((currentPart, index) => {
213
+ let cachedPart = cachedAuthorityParts[index];
214
+ if (index === 0 && this.canReplaceTenant(cachedAuthorityUrlComponents)) {
215
+ const tenantId = (new UrlString(this.metadata.authorization_endpoint)).getUrlComponents().PathSegments[0];
216
+ /**
217
+ * Check if AAD canonical authority contains tenant domain name, for example "testdomain.onmicrosoft.com",
218
+ * by comparing its first path segment to the corresponding authorization endpoint path segment, which is
219
+ * always resolved with tenant id by OIDC.
220
+ */
221
+ if (cachedPart !== tenantId) {
222
+ this.logger.verbose(`Replacing tenant domain name ${cachedPart} with id ${tenantId}`);
223
+ cachedPart = tenantId;
224
+ }
225
+ }
226
+ if (currentPart !== cachedPart) {
227
+ endpoint = endpoint.replace(`/${cachedPart}/`, `/${currentPart}/`);
228
+ }
229
+ });
230
+ return this.replaceTenant(endpoint);
231
+ }
232
+ /**
233
+ * The default open id configuration endpoint for any canonical authority.
234
+ */
235
+ get defaultOpenIdConfigurationEndpoint() {
236
+ if (this.authorityType === AuthorityType.Adfs ||
237
+ this.protocolMode === ProtocolMode.OIDC) {
238
+ return `${this.canonicalAuthority}.well-known/openid-configuration`;
239
+ }
240
+ return `${this.canonicalAuthority}v2.0/.well-known/openid-configuration`;
241
+ }
242
+ /**
243
+ * Boolean that returns whethr or not tenant discovery has been completed.
244
+ */
245
+ discoveryComplete() {
246
+ return !!this.metadata;
247
+ }
248
+ /**
249
+ * Perform endpoint discovery to discover aliases, preferred_cache, preferred_network
250
+ * and the /authorize, /token and logout endpoints.
251
+ */
252
+ async resolveEndpointsAsync() {
253
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityResolveEndpointsAsync, this.correlationId);
254
+ let metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(this.hostnameAndPort);
255
+ if (!metadataEntity) {
256
+ metadataEntity = new AuthorityMetadataEntity();
257
+ metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
258
+ }
259
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
260
+ const cloudDiscoverySource = await this.updateCloudDiscoveryMetadata(metadataEntity);
261
+ this.canonicalAuthority = this.canonicalAuthority.replace(this.hostnameAndPort, metadataEntity.preferred_network);
262
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
263
+ const endpointSource = await this.updateEndpointMetadata(metadataEntity);
264
+ if (cloudDiscoverySource !== AuthorityMetadataSource.CACHE &&
265
+ endpointSource !== AuthorityMetadataSource.CACHE) {
266
+ // Reset the expiration time unless both values came from a successful cache lookup
267
+ metadataEntity.resetExpiresAt();
268
+ metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
269
+ }
270
+ const cacheKey = this.cacheManager.generateAuthorityMetadataCacheKey(metadataEntity.preferred_cache);
271
+ this.cacheManager.setAuthorityMetadata(cacheKey, metadataEntity);
272
+ this.metadata = metadataEntity;
273
+ }
274
+ /**
275
+ * Update AuthorityMetadataEntity with new endpoints and return where the information came from
276
+ * @param metadataEntity
277
+ */
278
+ async updateEndpointMetadata(metadataEntity) {
279
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateEndpointMetadata, this.correlationId);
280
+ let metadata = this.getEndpointMetadataFromConfig();
281
+ if (metadata) {
282
+ metadataEntity.updateEndpointMetadata(metadata, false);
283
+ return AuthorityMetadataSource.CONFIG;
284
+ }
285
+ if (this.isAuthoritySameType(metadataEntity) &&
286
+ metadataEntity.endpointsFromNetwork &&
287
+ !metadataEntity.isExpired()) {
288
+ // No need to update
289
+ return AuthorityMetadataSource.CACHE;
290
+ }
291
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
292
+ metadata = await this.getEndpointMetadataFromNetwork();
293
+ if (metadata) {
294
+ // If the user prefers to use an azure region replace the global endpoints with regional information.
295
+ if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
296
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
297
+ metadata = await this.updateMetadataWithRegionalInformation(metadata);
298
+ }
299
+ metadataEntity.updateEndpointMetadata(metadata, true);
300
+ return AuthorityMetadataSource.NETWORK;
301
+ }
302
+ let harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
303
+ if (harcodedMetadata &&
304
+ !this.authorityOptions.skipAuthorityMetadataCache) {
305
+ // If the user prefers to use an azure region replace the global endpoints with regional information.
306
+ if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
307
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
308
+ harcodedMetadata =
309
+ await this.updateMetadataWithRegionalInformation(harcodedMetadata);
310
+ }
311
+ metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
312
+ return AuthorityMetadataSource.HARDCODED_VALUES;
313
+ }
314
+ else {
315
+ throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
316
+ }
317
+ }
318
+ /**
319
+ * Compares the number of url components after the domain to determine if the cached
320
+ * authority metadata can be used for the requested authority. Protects against same domain different
321
+ * authority such as login.microsoftonline.com/tenant and login.microsoftonline.com/tfp/tenant/policy
322
+ * @param metadataEntity
323
+ */
324
+ isAuthoritySameType(metadataEntity) {
325
+ const cachedAuthorityUrl = new UrlString(metadataEntity.canonical_authority);
326
+ const cachedParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
327
+ return (cachedParts.length ===
328
+ this.canonicalAuthorityUrlComponents.PathSegments.length);
329
+ }
330
+ /**
331
+ * Parse authorityMetadata config option
332
+ */
333
+ getEndpointMetadataFromConfig() {
334
+ if (this.authorityOptions.authorityMetadata) {
335
+ try {
336
+ return JSON.parse(this.authorityOptions.authorityMetadata);
337
+ }
338
+ catch (e) {
339
+ throw ClientConfigurationError.createInvalidAuthorityMetadataError();
340
+ }
341
+ }
342
+ return null;
343
+ }
344
+ /**
345
+ * Gets OAuth endpoints from the given OpenID configuration endpoint.
346
+ *
347
+ * @param hasHardcodedMetadata boolean
348
+ */
349
+ async getEndpointMetadataFromNetwork() {
350
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
351
+ const perfEvent = this.performanceClient?.startMeasurement(PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
352
+ const options = {};
353
+ /*
354
+ * TODO: Add a timeout if the authority exists in our library's
355
+ * hardcoded list of metadata
356
+ */
357
+ const openIdConfigurationEndpoint = this.defaultOpenIdConfigurationEndpoint;
358
+ this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: attempting to retrieve OAuth endpoints from ${openIdConfigurationEndpoint}`);
359
+ try {
360
+ const response = await this.networkInterface.sendGetRequestAsync(openIdConfigurationEndpoint, options);
361
+ const isValidResponse = isOpenIdConfigResponse(response.body);
362
+ if (isValidResponse) {
363
+ perfEvent?.endMeasurement({ success: true });
364
+ return response.body;
365
+ }
366
+ else {
367
+ perfEvent?.endMeasurement({ success: false, errorCode: "invalid_response" });
368
+ this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: could not parse response as OpenID configuration`);
369
+ return null;
370
+ }
371
+ }
372
+ catch (e) {
373
+ perfEvent?.endMeasurement({ success: false, errorCode: "request_failure" });
374
+ this.logger.verbose(`Authority.getEndpointMetadataFromNetwork: ${e}`);
375
+ return null;
376
+ }
377
+ }
378
+ /**
379
+ * Get OAuth endpoints for common authorities.
380
+ */
381
+ getEndpointMetadataFromHardcodedValues() {
382
+ if (this.canonicalAuthority in EndpointMetadata) {
383
+ return EndpointMetadata[this.canonicalAuthority];
384
+ }
385
+ return null;
386
+ }
387
+ /**
388
+ * Update the retrieved metadata with regional information.
389
+ */
390
+ async updateMetadataWithRegionalInformation(metadata) {
391
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
392
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.RegionDiscoveryDetectRegion, this.correlationId);
393
+ const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration?.environmentRegion, this.regionDiscoveryMetadata);
394
+ const azureRegion = this.authorityOptions.azureRegionConfiguration?.azureRegion ===
395
+ Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
396
+ ? autodetectedRegionName
397
+ : this.authorityOptions.azureRegionConfiguration?.azureRegion;
398
+ if (this.authorityOptions.azureRegionConfiguration?.azureRegion ===
399
+ Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
400
+ this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName
401
+ ? RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL
402
+ : RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
403
+ }
404
+ else {
405
+ if (autodetectedRegionName) {
406
+ this.regionDiscoveryMetadata.region_outcome =
407
+ this.authorityOptions.azureRegionConfiguration
408
+ ?.azureRegion === autodetectedRegionName
409
+ ? RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED
410
+ : RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
411
+ }
412
+ else {
413
+ this.regionDiscoveryMetadata.region_outcome =
414
+ RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
415
+ }
416
+ }
417
+ if (azureRegion) {
418
+ this.regionDiscoveryMetadata.region_used = azureRegion;
419
+ return Authority.replaceWithRegionalInformation(metadata, azureRegion);
420
+ }
421
+ return metadata;
422
+ }
423
+ /**
424
+ * Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache
425
+ * and returns where the information was retrieved from
426
+ * @param metadataEntity
427
+ * @returns AuthorityMetadataSource
428
+ */
429
+ async updateCloudDiscoveryMetadata(metadataEntity) {
430
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
431
+ this.logger.verbose("Attempting to get cloud discovery metadata in the config");
432
+ this.logger.verbosePii(`Known Authorities: ${this.authorityOptions.knownAuthorities ||
433
+ Constants.NOT_APPLICABLE}`);
434
+ this.logger.verbosePii(`Authority Metadata: ${this.authorityOptions.authorityMetadata ||
435
+ Constants.NOT_APPLICABLE}`);
436
+ this.logger.verbosePii(`Canonical Authority: ${metadataEntity.canonical_authority || Constants.NOT_APPLICABLE}`);
437
+ let metadata = this.getCloudDiscoveryMetadataFromConfig();
438
+ if (metadata) {
439
+ this.logger.verbose("Found cloud discovery metadata in the config.");
440
+ metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
441
+ return AuthorityMetadataSource.CONFIG;
442
+ }
443
+ // If the cached metadata came from config but that config was not passed to this instance, we must go to the network
444
+ this.logger.verbose("Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the cache.");
445
+ const metadataEntityExpired = metadataEntity.isExpired();
446
+ if (this.isAuthoritySameType(metadataEntity) &&
447
+ metadataEntity.aliasesFromNetwork &&
448
+ !metadataEntityExpired) {
449
+ this.logger.verbose("Found metadata in the cache.");
450
+ // No need to update
451
+ return AuthorityMetadataSource.CACHE;
452
+ }
453
+ else if (metadataEntityExpired) {
454
+ this.logger.verbose("The metadata entity is expired.");
455
+ }
456
+ this.logger.verbose("Did not find cloud discovery metadata in the cache... Attempting to get cloud discovery metadata from the network.");
457
+ this.performanceClient?.setPreQueueTime(PerformanceEvents.AuthorityGetCloudDiscoveryMetadataFromNetwork, this.correlationId);
458
+ metadata = await this.getCloudDiscoveryMetadataFromNetwork();
459
+ if (metadata) {
460
+ this.logger.verbose("cloud discovery metadata was successfully returned from getCloudDiscoveryMetadataFromNetwork()");
461
+ metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
462
+ return AuthorityMetadataSource.NETWORK;
463
+ }
464
+ this.logger.verbose("Did not find cloud discovery metadata from the network... Attempting to get cloud discovery metadata from hardcoded values.");
465
+ const harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
466
+ if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
467
+ this.logger.verbose("Found cloud discovery metadata from hardcoded values.");
468
+ metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
469
+ return AuthorityMetadataSource.HARDCODED_VALUES;
470
+ }
471
+ // Metadata could not be obtained from the config, cache, network or hardcoded values
472
+ 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.");
473
+ throw ClientConfigurationError.createUntrustedAuthorityError();
474
+ }
475
+ /**
476
+ * Parse cloudDiscoveryMetadata config or check knownAuthorities
477
+ */
478
+ getCloudDiscoveryMetadataFromConfig() {
479
+ // CIAM does not support cloud discovery metadata
480
+ if (this.authorityType === AuthorityType.Ciam) {
481
+ this.logger.verbose("CIAM authorities do not support cloud discovery metadata, generate the aliases from authority host.");
482
+ return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
483
+ }
484
+ // Check if network response was provided in config
485
+ if (this.authorityOptions.cloudDiscoveryMetadata) {
486
+ this.logger.verbose("The cloud discovery metadata has been provided as a network response, in the config.");
487
+ try {
488
+ this.logger.verbose("Attempting to parse the cloud discovery metadata.");
489
+ const parsedResponse = JSON.parse(this.authorityOptions.cloudDiscoveryMetadata);
490
+ const metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(parsedResponse.metadata, this.hostnameAndPort);
491
+ this.logger.verbose("Parsed the cloud discovery metadata.");
492
+ if (metadata) {
493
+ this.logger.verbose("There is returnable metadata attached to the parsed cloud discovery metadata.");
494
+ return metadata;
495
+ }
496
+ else {
497
+ this.logger.verbose("There is no metadata attached to the parsed cloud discovery metadata.");
498
+ }
499
+ }
500
+ catch (e) {
501
+ this.logger.verbose("Unable to parse the cloud discovery metadata. Throwing Invalid Cloud Discovery Metadata Error.");
502
+ throw ClientConfigurationError.createInvalidCloudDiscoveryMetadataError();
503
+ }
504
+ }
505
+ // If cloudDiscoveryMetadata is empty or does not contain the host, check knownAuthorities
506
+ if (this.isInKnownAuthorities()) {
507
+ this.logger.verbose("The host is included in knownAuthorities. Creating new cloud discovery metadata from the host.");
508
+ return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
509
+ }
510
+ return null;
511
+ }
512
+ /**
513
+ * Called to get metadata from network if CloudDiscoveryMetadata was not populated by config
514
+ *
515
+ * @param hasHardcodedMetadata boolean
516
+ */
517
+ async getCloudDiscoveryMetadataFromNetwork() {
518
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.AuthorityGetCloudDiscoveryMetadataFromNetwork, this.correlationId);
519
+ const instanceDiscoveryEndpoint = `${Constants.AAD_INSTANCE_DISCOVERY_ENDPT}${this.canonicalAuthority}oauth2/v2.0/authorize`;
520
+ const options = {};
521
+ /*
522
+ * TODO: Add a timeout if the authority exists in our library's
523
+ * hardcoded list of metadata
524
+ */
525
+ let match = null;
526
+ try {
527
+ const response = await this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options);
528
+ let typedResponseBody;
529
+ let metadata;
530
+ if (isCloudInstanceDiscoveryResponse(response.body)) {
531
+ typedResponseBody =
532
+ response.body;
533
+ metadata = typedResponseBody.metadata;
534
+ this.logger.verbosePii(`tenant_discovery_endpoint is: ${typedResponseBody.tenant_discovery_endpoint}`);
535
+ }
536
+ else if (isCloudInstanceDiscoveryErrorResponse(response.body)) {
537
+ this.logger.warning(`A CloudInstanceDiscoveryErrorResponse was returned. The cloud instance discovery network request's status code is: ${response.status}`);
538
+ typedResponseBody =
539
+ response.body;
540
+ if (typedResponseBody.error === Constants.INVALID_INSTANCE) {
541
+ this.logger.error("The CloudInstanceDiscoveryErrorResponse error is invalid_instance.");
542
+ return null;
543
+ }
544
+ this.logger.warning(`The CloudInstanceDiscoveryErrorResponse error is ${typedResponseBody.error}`);
545
+ this.logger.warning(`The CloudInstanceDiscoveryErrorResponse error description is ${typedResponseBody.error_description}`);
546
+ this.logger.warning("Setting the value of the CloudInstanceDiscoveryMetadata (returned from the network) to []");
547
+ metadata = [];
548
+ }
549
+ else {
550
+ this.logger.error("AAD did not return a CloudInstanceDiscoveryResponse or CloudInstanceDiscoveryErrorResponse");
551
+ return null;
552
+ }
553
+ this.logger.verbose("Attempting to find a match between the developer's authority and the CloudInstanceDiscoveryMetadata returned from the network request.");
554
+ match = Authority.getCloudDiscoveryMetadataFromNetworkResponse(metadata, this.hostnameAndPort);
555
+ }
556
+ catch (error) {
557
+ if (error instanceof AuthError) {
558
+ this.logger.error(`There was a network error while attempting to get the cloud discovery instance metadata.\nError: ${error.errorCode}\nError Description: ${error.errorMessage}`);
559
+ }
560
+ else {
561
+ const typedError = error;
562
+ this.logger.error(`A non-MSALJS error was thrown while attempting to get the cloud instance discovery metadata.\nError: ${typedError.name}\nError Description: ${typedError.message}`);
563
+ }
564
+ return null;
565
+ }
566
+ // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
567
+ if (!match) {
568
+ this.logger.warning("The developer's authority was not found within the CloudInstanceDiscoveryMetadata returned from the network request.");
569
+ this.logger.verbose("Creating custom Authority for custom domain scenario.");
570
+ match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
571
+ }
572
+ return match;
573
+ }
574
+ /**
575
+ * Get cloud discovery metadata for common authorities
576
+ */
577
+ getCloudDiscoveryMetadataFromHarcodedValues() {
578
+ if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
579
+ return InstanceDiscoveryMetadata[this.canonicalAuthority];
580
+ }
581
+ return null;
582
+ }
583
+ /**
584
+ * Helper function to determine if this host is included in the knownAuthorities config option
585
+ */
586
+ isInKnownAuthorities() {
587
+ const matches = this.authorityOptions.knownAuthorities.filter((authority) => {
588
+ return (UrlString.getDomainFromUrl(authority).toLowerCase() ===
589
+ this.hostnameAndPort);
590
+ });
591
+ return matches.length > 0;
592
+ }
593
+ /**
594
+ * helper function to populate the authority based on azureCloudOptions
595
+ * @param authorityString
596
+ * @param azureCloudOptions
597
+ */
598
+ static generateAuthority(authorityString, azureCloudOptions) {
599
+ let authorityAzureCloudInstance;
600
+ if (azureCloudOptions &&
601
+ azureCloudOptions.azureCloudInstance !== AzureCloudInstance.None) {
602
+ const tenant = azureCloudOptions.tenant
603
+ ? azureCloudOptions.tenant
604
+ : Constants.DEFAULT_COMMON_TENANT;
605
+ authorityAzureCloudInstance = `${azureCloudOptions.azureCloudInstance}/${tenant}/`;
606
+ }
607
+ return authorityAzureCloudInstance
608
+ ? authorityAzureCloudInstance
609
+ : authorityString;
610
+ }
611
+ /**
612
+ * Creates cloud discovery metadata object from a given host
613
+ * @param host
614
+ */
615
+ static createCloudDiscoveryMetadataFromHost(host) {
616
+ return {
617
+ preferred_network: host,
618
+ preferred_cache: host,
619
+ aliases: [host],
620
+ };
621
+ }
622
+ /**
623
+ * Searches instance discovery network response for the entry that contains the host in the aliases list
624
+ * @param response
625
+ * @param authority
626
+ */
627
+ static getCloudDiscoveryMetadataFromNetworkResponse(response, authority) {
628
+ for (let i = 0; i < response.length; i++) {
629
+ const metadata = response[i];
630
+ if (metadata.aliases.indexOf(authority) > -1) {
631
+ return metadata;
632
+ }
633
+ }
634
+ return null;
635
+ }
636
+ /**
637
+ * helper function to generate environment from authority object
638
+ */
639
+ getPreferredCache() {
640
+ if (this.discoveryComplete()) {
641
+ return this.metadata.preferred_cache;
642
+ }
643
+ else {
644
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
645
+ }
646
+ }
647
+ /**
648
+ * Returns whether or not the provided host is an alias of this authority instance
649
+ * @param host
650
+ */
651
+ isAlias(host) {
652
+ return this.metadata.aliases.indexOf(host) > -1;
653
+ }
654
+ /**
655
+ * Checks whether the provided host is that of a public cloud authority
656
+ *
657
+ * @param authority string
658
+ * @returns bool
659
+ */
660
+ static isPublicCloudAuthority(host) {
661
+ return Constants.KNOWN_PUBLIC_CLOUDS.indexOf(host) >= 0;
662
+ }
663
+ /**
664
+ * Rebuild the authority string with the region
665
+ *
666
+ * @param host string
667
+ * @param region string
668
+ */
669
+ static buildRegionalAuthorityString(host, region, queryString) {
670
+ // Create and validate a Url string object with the initial authority string
671
+ const authorityUrlInstance = new UrlString(host);
672
+ authorityUrlInstance.validateAsUri();
673
+ const authorityUrlParts = authorityUrlInstance.getUrlComponents();
674
+ let hostNameAndPort = `${region}.${authorityUrlParts.HostNameAndPort}`;
675
+ if (this.isPublicCloudAuthority(authorityUrlParts.HostNameAndPort)) {
676
+ hostNameAndPort = `${region}.${Constants.REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX}`;
677
+ }
678
+ // Include the query string portion of the url
679
+ const url = UrlString.constructAuthorityUriFromObject({
680
+ ...authorityUrlInstance.getUrlComponents(),
681
+ HostNameAndPort: hostNameAndPort,
682
+ }).urlString;
683
+ // Add the query string if a query string was provided
684
+ if (queryString)
685
+ return `${url}?${queryString}`;
686
+ return url;
687
+ }
688
+ /**
689
+ * Replace the endpoints in the metadata object with their regional equivalents.
690
+ *
691
+ * @param metadata OpenIdConfigResponse
692
+ * @param azureRegion string
693
+ */
694
+ static replaceWithRegionalInformation(metadata, azureRegion) {
695
+ metadata.authorization_endpoint =
696
+ Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
697
+ // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
698
+ metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, Constants.REGIONAL_AUTH_NON_MSI_QUERY_STRING);
699
+ if (metadata.end_session_endpoint) {
700
+ metadata.end_session_endpoint =
701
+ Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
702
+ }
703
+ return metadata;
704
+ }
705
+ /**
706
+ * Transform CIAM_AUTHORIY as per the below rules:
707
+ * If no path segments found and it is a CIAM authority (hostname ends with .ciamlogin.com), then transform it
708
+ *
709
+ * NOTE: The transformation path should go away once STS supports CIAM with the format: `tenantIdorDomain.ciamlogin.com`
710
+ * `ciamlogin.com` can also change in the future and we should accommodate the same
711
+ *
712
+ * @param authority
713
+ */
714
+ static transformCIAMAuthority(authority) {
715
+ let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH) ? authority : `${authority}${Constants.FORWARD_SLASH}`;
716
+ const authorityUrl = new UrlString(authority);
717
+ const authorityUrlComponents = authorityUrl.getUrlComponents();
718
+ // check if transformation is needed
719
+ if (authorityUrlComponents.PathSegments.length === 0 && (authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL))) {
720
+ const tenantIdOrDomain = authorityUrlComponents.HostNameAndPort.split(".")[0];
721
+ ciamAuthority = `${ciamAuthority}${tenantIdOrDomain}${Constants.AAD_TENANT_DOMAIN_SUFFIX}`;
722
+ }
723
+ return ciamAuthority;
724
+ }
725
+ }
726
+ // Reserved tenant domain names that will not be replaced with tenant id
727
+ Authority.reservedTenantDomains = (new Set([
728
+ "{tenant}",
729
+ "{tenantid}",
730
+ AADAuthorityConstants.COMMON,
731
+ AADAuthorityConstants.CONSUMERS,
732
+ AADAuthorityConstants.ORGANIZATIONS
733
+ ]));
782
734
 
783
735
  export { Authority };
784
736
  //# sourceMappingURL=Authority.js.map