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