@azure/msal-common 4.2.1 → 4.5.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 (190) hide show
  1. package/CHANGELOG.json +212 -1
  2. package/LICENSE +21 -21
  3. package/README.md +61 -58
  4. package/changelog.md +402 -344
  5. package/dist/_virtual/_tslib.js +90 -0
  6. package/dist/_virtual/_tslib.js.map +1 -0
  7. package/dist/account/AuthToken.js +43 -0
  8. package/dist/account/AuthToken.js.map +1 -0
  9. package/dist/account/CcsCredential.d.ts +9 -0
  10. package/dist/account/CcsCredential.d.ts.map +1 -0
  11. package/dist/account/CcsCredential.js +14 -0
  12. package/dist/account/CcsCredential.js.map +1 -0
  13. package/dist/account/ClientInfo.d.ts +6 -1
  14. package/dist/account/ClientInfo.d.ts.map +1 -1
  15. package/dist/account/ClientInfo.js +44 -0
  16. package/dist/account/ClientInfo.js.map +1 -0
  17. package/dist/account/TokenClaims.d.ts +1 -0
  18. package/dist/account/TokenClaims.d.ts.map +1 -1
  19. package/dist/authority/Authority.d.ts +25 -0
  20. package/dist/authority/Authority.d.ts.map +1 -1
  21. package/dist/authority/Authority.js +574 -0
  22. package/dist/authority/Authority.js.map +1 -0
  23. package/dist/authority/AuthorityFactory.js +69 -0
  24. package/dist/authority/AuthorityFactory.js.map +1 -0
  25. package/dist/authority/AuthorityOptions.d.ts +2 -0
  26. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  27. package/dist/authority/AuthorityType.js +17 -0
  28. package/dist/authority/AuthorityType.js.map +1 -0
  29. package/dist/authority/AzureRegion.d.ts +2 -0
  30. package/dist/authority/AzureRegion.d.ts.map +1 -0
  31. package/dist/authority/AzureRegionConfiguration.d.ts +6 -0
  32. package/dist/authority/AzureRegionConfiguration.d.ts.map +1 -0
  33. package/dist/authority/CloudInstanceDiscoveryResponse.js +13 -0
  34. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -0
  35. package/dist/authority/OpenIdConfigResponse.js +15 -0
  36. package/dist/authority/OpenIdConfigResponse.js.map +1 -0
  37. package/dist/authority/ProtocolMode.js +17 -0
  38. package/dist/authority/ProtocolMode.js.map +1 -0
  39. package/dist/authority/RegionDiscovery.d.ts +31 -0
  40. package/dist/authority/RegionDiscovery.d.ts.map +1 -0
  41. package/dist/authority/RegionDiscovery.js +119 -0
  42. package/dist/authority/RegionDiscovery.js.map +1 -0
  43. package/dist/authority/RegionDiscoveryMetadata.d.ts +7 -0
  44. package/dist/authority/RegionDiscoveryMetadata.d.ts.map +1 -0
  45. package/dist/cache/CacheManager.js +713 -0
  46. package/dist/cache/CacheManager.js.map +1 -0
  47. package/dist/cache/entities/AccessTokenEntity.js +111 -0
  48. package/dist/cache/entities/AccessTokenEntity.js.map +1 -0
  49. package/dist/cache/entities/AccountEntity.d.ts +5 -5
  50. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  51. package/dist/cache/entities/AccountEntity.js +242 -0
  52. package/dist/cache/entities/AccountEntity.js.map +1 -0
  53. package/dist/cache/entities/AppMetadataEntity.js +74 -0
  54. package/dist/cache/entities/AppMetadataEntity.js.map +1 -0
  55. package/dist/cache/entities/AuthorityMetadataEntity.js +81 -0
  56. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -0
  57. package/dist/cache/entities/CacheRecord.js +19 -0
  58. package/dist/cache/entities/CacheRecord.js.map +1 -0
  59. package/dist/cache/entities/CredentialEntity.js +142 -0
  60. package/dist/cache/entities/CredentialEntity.js.map +1 -0
  61. package/dist/cache/entities/IdTokenEntity.js +71 -0
  62. package/dist/cache/entities/IdTokenEntity.js.map +1 -0
  63. package/dist/cache/entities/RefreshTokenEntity.js +73 -0
  64. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -0
  65. package/dist/cache/entities/ServerTelemetryEntity.js +35 -0
  66. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -0
  67. package/dist/cache/entities/ThrottlingEntity.js +32 -0
  68. package/dist/cache/entities/ThrottlingEntity.js.map +1 -0
  69. package/dist/cache/persistence/TokenCacheContext.js +39 -0
  70. package/dist/cache/persistence/TokenCacheContext.js.map +1 -0
  71. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  72. package/dist/client/AuthorizationCodeClient.js +388 -0
  73. package/dist/client/AuthorizationCodeClient.js.map +1 -0
  74. package/dist/client/BaseClient.d.ts +2 -1
  75. package/dist/client/BaseClient.d.ts.map +1 -1
  76. package/dist/client/BaseClient.js +101 -0
  77. package/dist/client/BaseClient.js.map +1 -0
  78. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  79. package/dist/client/ClientCredentialClient.js +169 -0
  80. package/dist/client/ClientCredentialClient.js.map +1 -0
  81. package/dist/client/DeviceCodeClient.d.ts +6 -0
  82. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  83. package/dist/client/DeviceCodeClient.js +212 -0
  84. package/dist/client/DeviceCodeClient.js.map +1 -0
  85. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  86. package/dist/client/OnBehalfOfClient.js +209 -0
  87. package/dist/client/OnBehalfOfClient.js.map +1 -0
  88. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  89. package/dist/client/RefreshTokenClient.js +212 -0
  90. package/dist/client/RefreshTokenClient.js.map +1 -0
  91. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  92. package/dist/client/SilentFlowClient.js +132 -0
  93. package/dist/client/SilentFlowClient.js.map +1 -0
  94. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  95. package/dist/client/UsernamePasswordClient.js +112 -0
  96. package/dist/client/UsernamePasswordClient.js.map +1 -0
  97. package/dist/config/ClientConfiguration.d.ts +3 -0
  98. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  99. package/dist/config/ClientConfiguration.js +91 -0
  100. package/dist/config/ClientConfiguration.js.map +1 -0
  101. package/dist/crypto/ICrypto.js +53 -0
  102. package/dist/crypto/ICrypto.js.map +1 -0
  103. package/dist/crypto/PopTokenGenerator.js +72 -0
  104. package/dist/crypto/PopTokenGenerator.js.map +1 -0
  105. package/dist/error/AuthError.js +46 -0
  106. package/dist/error/AuthError.js.map +1 -0
  107. package/dist/error/ClientAuthError.d.ts +13 -6
  108. package/dist/error/ClientAuthError.d.ts.map +1 -1
  109. package/dist/error/ClientAuthError.js +456 -0
  110. package/dist/error/ClientAuthError.js.map +1 -0
  111. package/dist/error/ClientConfigurationError.d.ts +1 -6
  112. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  113. package/dist/error/ClientConfigurationError.js +210 -0
  114. package/dist/error/ClientConfigurationError.js.map +1 -0
  115. package/dist/error/InteractionRequiredAuthError.js +48 -0
  116. package/dist/error/InteractionRequiredAuthError.js.map +1 -0
  117. package/dist/error/ServerError.js +25 -0
  118. package/dist/error/ServerError.js.map +1 -0
  119. package/dist/index.cjs.js +7045 -0
  120. package/dist/index.cjs.js.map +1 -0
  121. package/dist/index.d.ts +4 -0
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +43 -6479
  124. package/dist/index.js.map +1 -0
  125. package/dist/logger/Logger.d.ts +12 -3
  126. package/dist/logger/Logger.d.ts.map +1 -1
  127. package/dist/logger/Logger.js +183 -0
  128. package/dist/logger/Logger.js.map +1 -0
  129. package/dist/network/INetworkModule.d.ts +1 -1
  130. package/dist/network/INetworkModule.d.ts.map +1 -1
  131. package/dist/network/INetworkModule.js +21 -0
  132. package/dist/network/INetworkModule.js.map +1 -0
  133. package/dist/network/NetworkManager.js +56 -0
  134. package/dist/network/NetworkManager.js.map +1 -0
  135. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  136. package/dist/network/ThrottlingUtils.js +95 -0
  137. package/dist/network/ThrottlingUtils.js.map +1 -0
  138. package/dist/packageMetadata.d.ts +1 -1
  139. package/dist/packageMetadata.js +8 -0
  140. package/dist/packageMetadata.js.map +1 -0
  141. package/dist/request/CommonAuthorizationCodeRequest.d.ts +3 -0
  142. package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
  143. package/dist/request/CommonAuthorizationUrlRequest.d.ts +1 -0
  144. package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
  145. package/dist/request/CommonClientCredentialRequest.d.ts +7 -4
  146. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  147. package/dist/request/CommonRefreshTokenRequest.d.ts +2 -0
  148. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  149. package/dist/request/RequestParameterBuilder.d.ts +11 -0
  150. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  151. package/dist/request/RequestParameterBuilder.js +340 -0
  152. package/dist/request/RequestParameterBuilder.js.map +1 -0
  153. package/dist/request/RequestValidator.d.ts.map +1 -1
  154. package/dist/request/RequestValidator.js +92 -0
  155. package/dist/request/RequestValidator.js.map +1 -0
  156. package/dist/request/ScopeSet.js +192 -0
  157. package/dist/request/ScopeSet.js.map +1 -0
  158. package/dist/response/AuthenticationResult.d.ts +1 -1
  159. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  160. package/dist/response/AuthorizationCodePayload.d.ts +1 -0
  161. package/dist/response/AuthorizationCodePayload.d.ts.map +1 -1
  162. package/dist/response/IMDSBadResponse.d.ts +5 -0
  163. package/dist/response/IMDSBadResponse.d.ts.map +1 -0
  164. package/dist/response/ResponseHandler.d.ts.map +1 -1
  165. package/dist/response/ResponseHandler.js +281 -0
  166. package/dist/response/ResponseHandler.js.map +1 -0
  167. package/dist/telemetry/server/ServerTelemetryManager.d.ts +23 -1
  168. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  169. package/dist/telemetry/server/ServerTelemetryManager.js +168 -0
  170. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -0
  171. package/dist/url/UrlString.d.ts +10 -0
  172. package/dist/url/UrlString.d.ts.map +1 -1
  173. package/dist/url/UrlString.js +223 -0
  174. package/dist/url/UrlString.js.map +1 -0
  175. package/dist/utils/Constants.d.ts +47 -4
  176. package/dist/utils/Constants.d.ts.map +1 -1
  177. package/dist/utils/Constants.js +362 -0
  178. package/dist/utils/Constants.js.map +1 -0
  179. package/dist/utils/ProtocolUtils.js +77 -0
  180. package/dist/utils/ProtocolUtils.js.map +1 -0
  181. package/dist/utils/StringUtils.d.ts +5 -0
  182. package/dist/utils/StringUtils.d.ts.map +1 -1
  183. package/dist/utils/StringUtils.js +128 -0
  184. package/dist/utils/StringUtils.js.map +1 -0
  185. package/dist/utils/TimeUtils.d.ts +13 -0
  186. package/dist/utils/TimeUtils.d.ts.map +1 -1
  187. package/dist/utils/TimeUtils.js +53 -0
  188. package/dist/utils/TimeUtils.js.map +1 -0
  189. package/package.json +10 -19
  190. package/dist/index.es.js +0 -6472
@@ -0,0 +1,574 @@
1
+ /*! @azure/msal-common v4.5.1 2021-08-02 */
2
+ 'use strict';
3
+ import { __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
4
+ import { AuthorityType } from './AuthorityType.js';
5
+ import { isOpenIdConfigResponse } from './OpenIdConfigResponse.js';
6
+ import { UrlString } from '../url/UrlString.js';
7
+ import { ClientAuthError } from '../error/ClientAuthError.js';
8
+ import { Constants, AuthorityMetadataSource, RegionDiscoveryOutcomes } from '../utils/Constants.js';
9
+ import { ClientConfigurationError } from '../error/ClientConfigurationError.js';
10
+ import { ProtocolMode } from './ProtocolMode.js';
11
+ import { AuthorityMetadataEntity } from '../cache/entities/AuthorityMetadataEntity.js';
12
+ import { isCloudInstanceDiscoveryResponse } from './CloudInstanceDiscoveryResponse.js';
13
+ import { RegionDiscovery } from './RegionDiscovery.js';
14
+
15
+ /*
16
+ * Copyright (c) Microsoft Corporation. All rights reserved.
17
+ * Licensed under the MIT License.
18
+ */
19
+ /**
20
+ * The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the
21
+ * endpoint. It will store the pertinent config data in this object for use during token calls.
22
+ */
23
+ var Authority = /** @class */ (function () {
24
+ function Authority(authority, networkInterface, cacheManager, authorityOptions) {
25
+ this.canonicalAuthority = authority;
26
+ this._canonicalAuthority.validateAsUri();
27
+ this.networkInterface = networkInterface;
28
+ this.cacheManager = cacheManager;
29
+ this.authorityOptions = authorityOptions;
30
+ this.regionDiscovery = new RegionDiscovery(networkInterface);
31
+ this.regionDiscoveryMetadata = { region_used: undefined, region_source: undefined, region_outcome: undefined };
32
+ }
33
+ Object.defineProperty(Authority.prototype, "authorityType", {
34
+ // See above for AuthorityType
35
+ get: function () {
36
+ var pathSegments = this.canonicalAuthorityUrlComponents.PathSegments;
37
+ if (pathSegments.length && pathSegments[0].toLowerCase() === Constants.ADFS) {
38
+ return AuthorityType.Adfs;
39
+ }
40
+ return AuthorityType.Default;
41
+ },
42
+ enumerable: false,
43
+ configurable: true
44
+ });
45
+ Object.defineProperty(Authority.prototype, "protocolMode", {
46
+ /**
47
+ * ProtocolMode enum representing the way endpoints are constructed.
48
+ */
49
+ get: function () {
50
+ return this.authorityOptions.protocolMode;
51
+ },
52
+ enumerable: false,
53
+ configurable: true
54
+ });
55
+ Object.defineProperty(Authority.prototype, "options", {
56
+ /**
57
+ * Returns authorityOptions which can be used to reinstantiate a new authority instance
58
+ */
59
+ get: function () {
60
+ return this.authorityOptions;
61
+ },
62
+ enumerable: false,
63
+ configurable: true
64
+ });
65
+ Object.defineProperty(Authority.prototype, "canonicalAuthority", {
66
+ /**
67
+ * A URL that is the authority set by the developer
68
+ */
69
+ get: function () {
70
+ return this._canonicalAuthority.urlString;
71
+ },
72
+ /**
73
+ * Sets canonical authority.
74
+ */
75
+ set: function (url) {
76
+ this._canonicalAuthority = new UrlString(url);
77
+ this._canonicalAuthority.validateAsUri();
78
+ this._canonicalAuthorityUrlComponents = null;
79
+ },
80
+ enumerable: false,
81
+ configurable: true
82
+ });
83
+ Object.defineProperty(Authority.prototype, "canonicalAuthorityUrlComponents", {
84
+ /**
85
+ * Get authority components.
86
+ */
87
+ get: function () {
88
+ if (!this._canonicalAuthorityUrlComponents) {
89
+ this._canonicalAuthorityUrlComponents = this._canonicalAuthority.getUrlComponents();
90
+ }
91
+ return this._canonicalAuthorityUrlComponents;
92
+ },
93
+ enumerable: false,
94
+ configurable: true
95
+ });
96
+ Object.defineProperty(Authority.prototype, "hostnameAndPort", {
97
+ /**
98
+ * Get hostname and port i.e. login.microsoftonline.com
99
+ */
100
+ get: function () {
101
+ return this.canonicalAuthorityUrlComponents.HostNameAndPort.toLowerCase();
102
+ },
103
+ enumerable: false,
104
+ configurable: true
105
+ });
106
+ Object.defineProperty(Authority.prototype, "tenant", {
107
+ /**
108
+ * Get tenant for authority.
109
+ */
110
+ get: function () {
111
+ return this.canonicalAuthorityUrlComponents.PathSegments[0];
112
+ },
113
+ enumerable: false,
114
+ configurable: true
115
+ });
116
+ Object.defineProperty(Authority.prototype, "authorizationEndpoint", {
117
+ /**
118
+ * OAuth /authorize endpoint for requests
119
+ */
120
+ get: function () {
121
+ if (this.discoveryComplete()) {
122
+ var endpoint = this.replacePath(this.metadata.authorization_endpoint);
123
+ return this.replaceTenant(endpoint);
124
+ }
125
+ else {
126
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
127
+ }
128
+ },
129
+ enumerable: false,
130
+ configurable: true
131
+ });
132
+ Object.defineProperty(Authority.prototype, "tokenEndpoint", {
133
+ /**
134
+ * OAuth /token endpoint for requests
135
+ */
136
+ get: function () {
137
+ if (this.discoveryComplete()) {
138
+ var endpoint = this.replacePath(this.metadata.token_endpoint);
139
+ return this.replaceTenant(endpoint);
140
+ }
141
+ else {
142
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
143
+ }
144
+ },
145
+ enumerable: false,
146
+ configurable: true
147
+ });
148
+ Object.defineProperty(Authority.prototype, "deviceCodeEndpoint", {
149
+ get: function () {
150
+ if (this.discoveryComplete()) {
151
+ var endpoint = this.replacePath(this.metadata.token_endpoint.replace("/token", "/devicecode"));
152
+ return this.replaceTenant(endpoint);
153
+ }
154
+ else {
155
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
156
+ }
157
+ },
158
+ enumerable: false,
159
+ configurable: true
160
+ });
161
+ Object.defineProperty(Authority.prototype, "endSessionEndpoint", {
162
+ /**
163
+ * OAuth logout endpoint for requests
164
+ */
165
+ get: function () {
166
+ if (this.discoveryComplete()) {
167
+ var endpoint = this.replacePath(this.metadata.end_session_endpoint);
168
+ return this.replaceTenant(endpoint);
169
+ }
170
+ else {
171
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
172
+ }
173
+ },
174
+ enumerable: false,
175
+ configurable: true
176
+ });
177
+ Object.defineProperty(Authority.prototype, "selfSignedJwtAudience", {
178
+ /**
179
+ * OAuth issuer for requests
180
+ */
181
+ get: function () {
182
+ if (this.discoveryComplete()) {
183
+ var endpoint = this.replacePath(this.metadata.issuer);
184
+ return this.replaceTenant(endpoint);
185
+ }
186
+ else {
187
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
188
+ }
189
+ },
190
+ enumerable: false,
191
+ configurable: true
192
+ });
193
+ /**
194
+ * Replaces tenant in url path with current tenant. Defaults to common.
195
+ * @param urlString
196
+ */
197
+ Authority.prototype.replaceTenant = function (urlString) {
198
+ return urlString.replace(/{tenant}|{tenantid}/g, this.tenant);
199
+ };
200
+ /**
201
+ * Replaces path such as tenant or policy with the current tenant or policy.
202
+ * @param urlString
203
+ */
204
+ Authority.prototype.replacePath = function (urlString) {
205
+ var endpoint = urlString;
206
+ var cachedAuthorityUrl = new UrlString(this.metadata.canonical_authority);
207
+ var cachedAuthorityParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
208
+ var currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
209
+ currentAuthorityParts.forEach(function (currentPart, index) {
210
+ var cachedPart = cachedAuthorityParts[index];
211
+ if (currentPart !== cachedPart) {
212
+ endpoint = endpoint.replace("/" + cachedPart + "/", "/" + currentPart + "/");
213
+ }
214
+ });
215
+ return endpoint;
216
+ };
217
+ Object.defineProperty(Authority.prototype, "defaultOpenIdConfigurationEndpoint", {
218
+ /**
219
+ * The default open id configuration endpoint for any canonical authority.
220
+ */
221
+ get: function () {
222
+ if (this.authorityType === AuthorityType.Adfs || this.protocolMode === ProtocolMode.OIDC) {
223
+ return this.canonicalAuthority + ".well-known/openid-configuration";
224
+ }
225
+ return this.canonicalAuthority + "v2.0/.well-known/openid-configuration";
226
+ },
227
+ enumerable: false,
228
+ configurable: true
229
+ });
230
+ /**
231
+ * Boolean that returns whethr or not tenant discovery has been completed.
232
+ */
233
+ Authority.prototype.discoveryComplete = function () {
234
+ return !!this.metadata;
235
+ };
236
+ /**
237
+ * Perform endpoint discovery to discover aliases, preferred_cache, preferred_network
238
+ * and the /authorize, /token and logout endpoints.
239
+ */
240
+ Authority.prototype.resolveEndpointsAsync = function () {
241
+ return __awaiter(this, void 0, void 0, function () {
242
+ var metadataEntity, cloudDiscoverySource, endpointSource, cacheKey;
243
+ return __generator(this, function (_a) {
244
+ switch (_a.label) {
245
+ case 0:
246
+ metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(this.hostnameAndPort);
247
+ if (!metadataEntity) {
248
+ metadataEntity = new AuthorityMetadataEntity();
249
+ metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
250
+ }
251
+ return [4 /*yield*/, this.updateCloudDiscoveryMetadata(metadataEntity)];
252
+ case 1:
253
+ cloudDiscoverySource = _a.sent();
254
+ this.canonicalAuthority = this.canonicalAuthority.replace(this.hostnameAndPort, metadataEntity.preferred_network);
255
+ return [4 /*yield*/, this.updateEndpointMetadata(metadataEntity)];
256
+ case 2:
257
+ endpointSource = _a.sent();
258
+ if (cloudDiscoverySource !== AuthorityMetadataSource.CACHE && endpointSource !== AuthorityMetadataSource.CACHE) {
259
+ // Reset the expiration time unless both values came from a successful cache lookup
260
+ metadataEntity.resetExpiresAt();
261
+ metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
262
+ }
263
+ cacheKey = this.cacheManager.generateAuthorityMetadataCacheKey(metadataEntity.preferred_cache);
264
+ this.cacheManager.setAuthorityMetadata(cacheKey, metadataEntity);
265
+ this.metadata = metadataEntity;
266
+ return [2 /*return*/];
267
+ }
268
+ });
269
+ });
270
+ };
271
+ /**
272
+ * Update AuthorityMetadataEntity with new endpoints and return where the information came from
273
+ * @param metadataEntity
274
+ */
275
+ Authority.prototype.updateEndpointMetadata = function (metadataEntity) {
276
+ var _a;
277
+ return __awaiter(this, void 0, void 0, function () {
278
+ var metadata, autodetectedRegionName, azureRegion;
279
+ return __generator(this, function (_b) {
280
+ switch (_b.label) {
281
+ case 0:
282
+ metadata = this.getEndpointMetadataFromConfig();
283
+ if (metadata) {
284
+ metadataEntity.updateEndpointMetadata(metadata, false);
285
+ return [2 /*return*/, AuthorityMetadataSource.CONFIG];
286
+ }
287
+ if (this.isAuthoritySameType(metadataEntity) && metadataEntity.endpointsFromNetwork && !metadataEntity.isExpired()) {
288
+ // No need to update
289
+ return [2 /*return*/, AuthorityMetadataSource.CACHE];
290
+ }
291
+ return [4 /*yield*/, this.getEndpointMetadataFromNetwork()];
292
+ case 1:
293
+ metadata = _b.sent();
294
+ if (!metadata) return [3 /*break*/, 4];
295
+ if (!((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.azureRegion)) return [3 /*break*/, 3];
296
+ return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata)];
297
+ case 2:
298
+ autodetectedRegionName = _b.sent();
299
+ azureRegion = this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
300
+ ? autodetectedRegionName
301
+ : this.authorityOptions.azureRegionConfiguration.azureRegion;
302
+ if (this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
303
+ this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
304
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
305
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
306
+ }
307
+ else {
308
+ if (autodetectedRegionName) {
309
+ this.regionDiscoveryMetadata.region_outcome = (this.authorityOptions.azureRegionConfiguration.azureRegion === autodetectedRegionName) ?
310
+ RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
311
+ RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
312
+ }
313
+ else {
314
+ this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
315
+ }
316
+ }
317
+ if (azureRegion) {
318
+ this.regionDiscoveryMetadata.region_used = azureRegion;
319
+ metadata = Authority.replaceWithRegionalInformation(metadata, azureRegion);
320
+ }
321
+ _b.label = 3;
322
+ case 3:
323
+ metadataEntity.updateEndpointMetadata(metadata, true);
324
+ return [2 /*return*/, AuthorityMetadataSource.NETWORK];
325
+ case 4: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
326
+ }
327
+ });
328
+ });
329
+ };
330
+ /**
331
+ * Compares the number of url components after the domain to determine if the cached authority metadata can be used for the requested authority
332
+ * Protects against same domain different authority such as login.microsoftonline.com/tenant and login.microsoftonline.com/tfp/tenant/policy
333
+ * @param metadataEntity
334
+ */
335
+ Authority.prototype.isAuthoritySameType = function (metadataEntity) {
336
+ var cachedAuthorityUrl = new UrlString(metadataEntity.canonical_authority);
337
+ var cachedParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
338
+ return cachedParts.length === this.canonicalAuthorityUrlComponents.PathSegments.length;
339
+ };
340
+ /**
341
+ * Parse authorityMetadata config option
342
+ */
343
+ Authority.prototype.getEndpointMetadataFromConfig = function () {
344
+ if (this.authorityOptions.authorityMetadata) {
345
+ try {
346
+ return JSON.parse(this.authorityOptions.authorityMetadata);
347
+ }
348
+ catch (e) {
349
+ throw ClientConfigurationError.createInvalidAuthorityMetadataError();
350
+ }
351
+ }
352
+ return null;
353
+ };
354
+ /**
355
+ * Gets OAuth endpoints from the given OpenID configuration endpoint.
356
+ */
357
+ Authority.prototype.getEndpointMetadataFromNetwork = function () {
358
+ return __awaiter(this, void 0, void 0, function () {
359
+ var response;
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0:
363
+ _a.trys.push([0, 2, , 3]);
364
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint)];
365
+ case 1:
366
+ response = _a.sent();
367
+ return [2 /*return*/, isOpenIdConfigResponse(response.body) ? response.body : null];
368
+ case 2:
369
+ _a.sent();
370
+ return [2 /*return*/, null];
371
+ case 3: return [2 /*return*/];
372
+ }
373
+ });
374
+ });
375
+ };
376
+ /**
377
+ * Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache and returns where the information was retrived from
378
+ * @param cachedMetadata
379
+ * @param newMetadata
380
+ */
381
+ Authority.prototype.updateCloudDiscoveryMetadata = function (metadataEntity) {
382
+ return __awaiter(this, void 0, void 0, function () {
383
+ var metadata;
384
+ return __generator(this, function (_a) {
385
+ switch (_a.label) {
386
+ case 0:
387
+ metadata = this.getCloudDiscoveryMetadataFromConfig();
388
+ if (metadata) {
389
+ metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
390
+ return [2 /*return*/, AuthorityMetadataSource.CONFIG];
391
+ }
392
+ // If The cached metadata came from config but that config was not passed to this instance, we must go to the network
393
+ if (this.isAuthoritySameType(metadataEntity) && metadataEntity.aliasesFromNetwork && !metadataEntity.isExpired()) {
394
+ // No need to update
395
+ return [2 /*return*/, AuthorityMetadataSource.CACHE];
396
+ }
397
+ return [4 /*yield*/, this.getCloudDiscoveryMetadataFromNetwork()];
398
+ case 1:
399
+ metadata = _a.sent();
400
+ if (metadata) {
401
+ metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
402
+ return [2 /*return*/, AuthorityMetadataSource.NETWORK];
403
+ }
404
+ else {
405
+ // Metadata could not be obtained from config, cache or network
406
+ throw ClientConfigurationError.createUntrustedAuthorityError();
407
+ }
408
+ }
409
+ });
410
+ });
411
+ };
412
+ /**
413
+ * Parse cloudDiscoveryMetadata config or check knownAuthorities
414
+ */
415
+ Authority.prototype.getCloudDiscoveryMetadataFromConfig = function () {
416
+ // Check if network response was provided in config
417
+ if (this.authorityOptions.cloudDiscoveryMetadata) {
418
+ try {
419
+ var parsedResponse = JSON.parse(this.authorityOptions.cloudDiscoveryMetadata);
420
+ var metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(parsedResponse.metadata, this.hostnameAndPort);
421
+ if (metadata) {
422
+ return metadata;
423
+ }
424
+ }
425
+ catch (e) {
426
+ throw ClientConfigurationError.createInvalidCloudDiscoveryMetadataError();
427
+ }
428
+ }
429
+ // If cloudDiscoveryMetadata is empty or does not contain the host, check knownAuthorities
430
+ if (this.isInKnownAuthorities()) {
431
+ return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
432
+ }
433
+ return null;
434
+ };
435
+ /**
436
+ * Called to get metadata from network if CloudDiscoveryMetadata was not populated by config
437
+ * @param networkInterface
438
+ */
439
+ Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
440
+ return __awaiter(this, void 0, void 0, function () {
441
+ var instanceDiscoveryEndpoint, match, response, metadata;
442
+ return __generator(this, function (_a) {
443
+ switch (_a.label) {
444
+ case 0:
445
+ instanceDiscoveryEndpoint = "" + Constants.AAD_INSTANCE_DISCOVERY_ENDPT + this.canonicalAuthority + "oauth2/v2.0/authorize";
446
+ match = null;
447
+ _a.label = 1;
448
+ case 1:
449
+ _a.trys.push([1, 3, , 4]);
450
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint)];
451
+ case 2:
452
+ response = _a.sent();
453
+ metadata = isCloudInstanceDiscoveryResponse(response.body) ? response.body.metadata : [];
454
+ if (metadata.length === 0) {
455
+ // If no metadata is returned, authority is untrusted
456
+ return [2 /*return*/, null];
457
+ }
458
+ match = Authority.getCloudDiscoveryMetadataFromNetworkResponse(metadata, this.hostnameAndPort);
459
+ return [3 /*break*/, 4];
460
+ case 3:
461
+ _a.sent();
462
+ return [2 /*return*/, null];
463
+ case 4:
464
+ if (!match) {
465
+ // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
466
+ match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
467
+ }
468
+ return [2 /*return*/, match];
469
+ }
470
+ });
471
+ });
472
+ };
473
+ /**
474
+ * Helper function to determine if this host is included in the knownAuthorities config option
475
+ */
476
+ Authority.prototype.isInKnownAuthorities = function () {
477
+ var _this = this;
478
+ var matches = this.authorityOptions.knownAuthorities.filter(function (authority) {
479
+ return UrlString.getDomainFromUrl(authority).toLowerCase() === _this.hostnameAndPort;
480
+ });
481
+ return matches.length > 0;
482
+ };
483
+ /**
484
+ * Creates cloud discovery metadata object from a given host
485
+ * @param host
486
+ */
487
+ Authority.createCloudDiscoveryMetadataFromHost = function (host) {
488
+ return {
489
+ preferred_network: host,
490
+ preferred_cache: host,
491
+ aliases: [host]
492
+ };
493
+ };
494
+ /**
495
+ * Searches instance discovery network response for the entry that contains the host in the aliases list
496
+ * @param response
497
+ * @param authority
498
+ */
499
+ Authority.getCloudDiscoveryMetadataFromNetworkResponse = function (response, authority) {
500
+ for (var i = 0; i < response.length; i++) {
501
+ var metadata = response[i];
502
+ if (metadata.aliases.indexOf(authority) > -1) {
503
+ return metadata;
504
+ }
505
+ }
506
+ return null;
507
+ };
508
+ /**
509
+ * helper function to generate environment from authority object
510
+ */
511
+ Authority.prototype.getPreferredCache = function () {
512
+ if (this.discoveryComplete()) {
513
+ return this.metadata.preferred_cache;
514
+ }
515
+ else {
516
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
517
+ }
518
+ };
519
+ /**
520
+ * Returns whether or not the provided host is an alias of this authority instance
521
+ * @param host
522
+ */
523
+ Authority.prototype.isAlias = function (host) {
524
+ return this.metadata.aliases.indexOf(host) > -1;
525
+ };
526
+ /**
527
+ * Checks whether the provided host is that of a public cloud authority
528
+ *
529
+ * @param authority string
530
+ * @returns bool
531
+ */
532
+ Authority.isPublicCloudAuthority = function (host) {
533
+ return Constants.KNOWN_PUBLIC_CLOUDS.indexOf(host) >= 0;
534
+ };
535
+ /**
536
+ * Rebuild the authority string with the region
537
+ *
538
+ * @param host string
539
+ * @param region string
540
+ */
541
+ Authority.buildRegionalAuthorityString = function (host, region, queryString) {
542
+ // Create and validate a Url string object with the initial authority string
543
+ var authorityUrlInstance = new UrlString(host);
544
+ authorityUrlInstance.validateAsUri();
545
+ var authorityUrlParts = authorityUrlInstance.getUrlComponents();
546
+ var hostNameAndPort = region + "." + authorityUrlParts.HostNameAndPort;
547
+ if (this.isPublicCloudAuthority(authorityUrlParts.HostNameAndPort)) {
548
+ hostNameAndPort = region + "." + Constants.REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX;
549
+ }
550
+ // Include the query string portion of the url
551
+ var url = UrlString.constructAuthorityUriFromObject(__assign(__assign({}, authorityUrlInstance.getUrlComponents()), { HostNameAndPort: hostNameAndPort })).urlString;
552
+ // Add the query string if a query string was provided
553
+ if (queryString)
554
+ return url + "?" + queryString;
555
+ return url;
556
+ };
557
+ /**
558
+ * Replace the endpoints in the metadata object with their regional equivalents.
559
+ *
560
+ * @param metadata OpenIdConfigResponse
561
+ * @param azureRegion string
562
+ */
563
+ Authority.replaceWithRegionalInformation = function (metadata, azureRegion) {
564
+ metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
565
+ // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
566
+ metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, "allowestsrnonmsi=true");
567
+ metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
568
+ return metadata;
569
+ };
570
+ return Authority;
571
+ }());
572
+
573
+ export { Authority };
574
+ //# sourceMappingURL=Authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authority.js","sources":["../../src/authority/Authority.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthorityType } from \"./AuthorityType\";\nimport { isOpenIdConfigResponse, OpenIdConfigResponse } from \"./OpenIdConfigResponse\";\nimport { UrlString } from \"../url/UrlString\";\nimport { IUri } from \"../url/IUri\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { INetworkModule } from \"../network/INetworkModule\";\nimport { AuthorityMetadataSource, Constants, RegionDiscoveryOutcomes } from \"../utils/Constants\";\nimport { ClientConfigurationError } from \"../error/ClientConfigurationError\";\nimport { ProtocolMode } from \"./ProtocolMode\";\nimport { ICacheManager } from \"../cache/interface/ICacheManager\";\nimport { AuthorityMetadataEntity } from \"../cache/entities/AuthorityMetadataEntity\";\nimport { AuthorityOptions } from \"./AuthorityOptions\";\nimport { CloudInstanceDiscoveryResponse, isCloudInstanceDiscoveryResponse } from \"./CloudInstanceDiscoveryResponse\";\nimport { CloudDiscoveryMetadata } from \"./CloudDiscoveryMetadata\";\nimport { RegionDiscovery } from \"./RegionDiscovery\";\nimport { RegionDiscoveryMetadata } from \"./RegionDiscoveryMetadata\";\n\n/**\n * The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the\n * endpoint. It will store the pertinent config data in this object for use during token calls.\n */\nexport class Authority {\n\n // Canonical authority url string\n private _canonicalAuthority: UrlString;\n // Canonicaly authority url components\n private _canonicalAuthorityUrlComponents: IUri | null;\n // Network interface to make requests with.\n protected networkInterface: INetworkModule;\n // Cache Manager to cache network responses\n protected cacheManager: ICacheManager;\n // Protocol mode to construct endpoints\n private authorityOptions: AuthorityOptions;\n // Authority metadata\n private metadata: AuthorityMetadataEntity;\n // Region discovery service\n private regionDiscovery: RegionDiscovery;\n // Region discovery metadata\n public regionDiscoveryMetadata: RegionDiscoveryMetadata;\n\n constructor(authority: string, networkInterface: INetworkModule, cacheManager: ICacheManager, authorityOptions: AuthorityOptions) {\n this.canonicalAuthority = authority;\n this._canonicalAuthority.validateAsUri();\n this.networkInterface = networkInterface;\n this.cacheManager = cacheManager;\n this.authorityOptions = authorityOptions;\n this.regionDiscovery = new RegionDiscovery(networkInterface);\n this.regionDiscoveryMetadata = { region_used: undefined, region_source: undefined, region_outcome: undefined };\n }\n\n // See above for AuthorityType\n public get authorityType(): AuthorityType {\n const pathSegments = this.canonicalAuthorityUrlComponents.PathSegments;\n\n if (pathSegments.length && pathSegments[0].toLowerCase() === Constants.ADFS) {\n return AuthorityType.Adfs;\n }\n\n return AuthorityType.Default;\n }\n\n /**\n * ProtocolMode enum representing the way endpoints are constructed.\n */\n public get protocolMode(): ProtocolMode {\n return this.authorityOptions.protocolMode;\n }\n\n /**\n * Returns authorityOptions which can be used to reinstantiate a new authority instance\n */\n public get options(): AuthorityOptions {\n return this.authorityOptions;\n }\n\n /**\n * A URL that is the authority set by the developer\n */\n public get canonicalAuthority(): string {\n return this._canonicalAuthority.urlString;\n }\n\n /**\n * Sets canonical authority.\n */\n public set canonicalAuthority(url: string) {\n this._canonicalAuthority = new UrlString(url);\n this._canonicalAuthority.validateAsUri();\n this._canonicalAuthorityUrlComponents = null;\n }\n\n /**\n * Get authority components.\n */\n public get canonicalAuthorityUrlComponents(): IUri {\n if (!this._canonicalAuthorityUrlComponents) {\n this._canonicalAuthorityUrlComponents = this._canonicalAuthority.getUrlComponents();\n }\n\n return this._canonicalAuthorityUrlComponents;\n }\n\n /**\n * Get hostname and port i.e. login.microsoftonline.com\n */\n public get hostnameAndPort(): string {\n return this.canonicalAuthorityUrlComponents.HostNameAndPort.toLowerCase();\n }\n\n /**\n * Get tenant for authority.\n */\n public get tenant(): string {\n return this.canonicalAuthorityUrlComponents.PathSegments[0];\n }\n\n /**\n * OAuth /authorize endpoint for requests\n */\n public get authorizationEndpoint(): string {\n if(this.discoveryComplete()) {\n const endpoint = this.replacePath(this.metadata.authorization_endpoint);\n return this.replaceTenant(endpoint);\n } else {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Discovery incomplete.\");\n }\n }\n\n /**\n * OAuth /token endpoint for requests\n */\n public get tokenEndpoint(): string {\n if(this.discoveryComplete()) {\n const endpoint = this.replacePath(this.metadata.token_endpoint);\n return this.replaceTenant(endpoint);\n } else {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Discovery incomplete.\");\n }\n }\n\n public get deviceCodeEndpoint(): string {\n if(this.discoveryComplete()) {\n const endpoint = this.replacePath(this.metadata.token_endpoint.replace(\"/token\", \"/devicecode\"));\n return this.replaceTenant(endpoint);\n } else {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Discovery incomplete.\");\n }\n }\n\n /**\n * OAuth logout endpoint for requests\n */\n public get endSessionEndpoint(): string {\n if(this.discoveryComplete()) {\n const endpoint = this.replacePath(this.metadata.end_session_endpoint);\n return this.replaceTenant(endpoint);\n } else {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Discovery incomplete.\");\n }\n }\n\n /**\n * OAuth issuer for requests\n */\n public get selfSignedJwtAudience(): string {\n if(this.discoveryComplete()) {\n const endpoint = this.replacePath(this.metadata.issuer);\n return this.replaceTenant(endpoint);\n } else {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Discovery incomplete.\");\n }\n }\n\n /**\n * Replaces tenant in url path with current tenant. Defaults to common.\n * @param urlString\n */\n private replaceTenant(urlString: string): string {\n return urlString.replace(/{tenant}|{tenantid}/g, this.tenant);\n }\n\n /**\n * Replaces path such as tenant or policy with the current tenant or policy.\n * @param urlString \n */\n private replacePath(urlString: string): string {\n let endpoint = urlString;\n const cachedAuthorityUrl = new UrlString(this.metadata.canonical_authority);\n const cachedAuthorityParts = cachedAuthorityUrl.getUrlComponents().PathSegments;\n const currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;\n\n currentAuthorityParts.forEach((currentPart, index) => {\n const cachedPart = cachedAuthorityParts[index];\n if (currentPart !== cachedPart) {\n endpoint = endpoint.replace(`/${cachedPart}/`, `/${currentPart}/`);\n }\n });\n\n return endpoint;\n }\n\n /**\n * The default open id configuration endpoint for any canonical authority.\n */\n protected get defaultOpenIdConfigurationEndpoint(): string {\n if (this.authorityType === AuthorityType.Adfs || this.protocolMode === ProtocolMode.OIDC) {\n return `${this.canonicalAuthority}.well-known/openid-configuration`;\n }\n return `${this.canonicalAuthority}v2.0/.well-known/openid-configuration`;\n }\n\n /**\n * Boolean that returns whethr or not tenant discovery has been completed.\n */\n discoveryComplete(): boolean {\n return !!this.metadata;\n }\n\n /**\n * Perform endpoint discovery to discover aliases, preferred_cache, preferred_network\n * and the /authorize, /token and logout endpoints.\n */\n public async resolveEndpointsAsync(): Promise<void> {\n let metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(this.hostnameAndPort);\n if (!metadataEntity) {\n metadataEntity = new AuthorityMetadataEntity();\n metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);\n }\n\n const cloudDiscoverySource = await this.updateCloudDiscoveryMetadata(metadataEntity);\n this.canonicalAuthority = this.canonicalAuthority.replace(this.hostnameAndPort, metadataEntity.preferred_network);\n const endpointSource = await this.updateEndpointMetadata(metadataEntity);\n\n if (cloudDiscoverySource !== AuthorityMetadataSource.CACHE && endpointSource !== AuthorityMetadataSource.CACHE) {\n // Reset the expiration time unless both values came from a successful cache lookup\n metadataEntity.resetExpiresAt();\n metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);\n } \n\n const cacheKey = this.cacheManager.generateAuthorityMetadataCacheKey(metadataEntity.preferred_cache);\n this.cacheManager.setAuthorityMetadata(cacheKey, metadataEntity);\n this.metadata = metadataEntity;\n }\n\n /**\n * Update AuthorityMetadataEntity with new endpoints and return where the information came from\n * @param metadataEntity \n */\n private async updateEndpointMetadata(metadataEntity: AuthorityMetadataEntity): Promise<AuthorityMetadataSource> {\n let metadata = this.getEndpointMetadataFromConfig();\n if (metadata) {\n metadataEntity.updateEndpointMetadata(metadata, false);\n return AuthorityMetadataSource.CONFIG;\n }\n\n if (this.isAuthoritySameType(metadataEntity) && metadataEntity.endpointsFromNetwork && !metadataEntity.isExpired()) {\n // No need to update\n return AuthorityMetadataSource.CACHE;\n }\n\n metadata = await this.getEndpointMetadataFromNetwork();\n if (metadata) {\n // If the user prefers to use an azure region replace the global endpoints with regional information.\n if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {\n const autodetectedRegionName = await this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata);\n\n const azureRegion = this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG \n ? autodetectedRegionName \n : this.authorityOptions.azureRegionConfiguration.azureRegion;\n\n if (this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {\n this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?\n RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :\n RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;\n } else {\n if (autodetectedRegionName) {\n this.regionDiscoveryMetadata.region_outcome = (this.authorityOptions.azureRegionConfiguration.azureRegion === autodetectedRegionName) ?\n RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :\n RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;\n } else {\n this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;\n }\n }\n\n if (azureRegion) {\n this.regionDiscoveryMetadata.region_used = azureRegion;\n metadata = Authority.replaceWithRegionalInformation(metadata, azureRegion);\n }\n }\n\n metadataEntity.updateEndpointMetadata(metadata, true);\n return AuthorityMetadataSource.NETWORK;\n } else {\n throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);\n }\n }\n\n /**\n * Compares the number of url components after the domain to determine if the cached authority metadata can be used for the requested authority\n * Protects against same domain different authority such as login.microsoftonline.com/tenant and login.microsoftonline.com/tfp/tenant/policy\n * @param metadataEntity\n */\n private isAuthoritySameType(metadataEntity: AuthorityMetadataEntity): boolean {\n const cachedAuthorityUrl = new UrlString(metadataEntity.canonical_authority);\n const cachedParts = cachedAuthorityUrl.getUrlComponents().PathSegments;\n \n return cachedParts.length === this.canonicalAuthorityUrlComponents.PathSegments.length;\n }\n\n /**\n * Parse authorityMetadata config option\n */\n private getEndpointMetadataFromConfig(): OpenIdConfigResponse | null {\n if (this.authorityOptions.authorityMetadata) {\n try {\n return JSON.parse(this.authorityOptions.authorityMetadata) as OpenIdConfigResponse;\n } catch (e) {\n throw ClientConfigurationError.createInvalidAuthorityMetadataError();\n }\n }\n\n return null;\n }\n\n /**\n * Gets OAuth endpoints from the given OpenID configuration endpoint.\n */\n private async getEndpointMetadataFromNetwork(): Promise<OpenIdConfigResponse | null> {\n try {\n const response = await this.networkInterface.sendGetRequestAsync<OpenIdConfigResponse>(this.defaultOpenIdConfigurationEndpoint);\n return isOpenIdConfigResponse(response.body) ? response.body : null;\n } catch (e) {\n return null;\n }\n }\n\n /**\n * Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache and returns where the information was retrived from\n * @param cachedMetadata \n * @param newMetadata \n */\n private async updateCloudDiscoveryMetadata(metadataEntity: AuthorityMetadataEntity): Promise<AuthorityMetadataSource> {\n let metadata = this.getCloudDiscoveryMetadataFromConfig();\n if (metadata) {\n metadataEntity.updateCloudDiscoveryMetadata(metadata, false);\n return AuthorityMetadataSource.CONFIG;\n }\n\n // If The cached metadata came from config but that config was not passed to this instance, we must go to the network\n if (this.isAuthoritySameType(metadataEntity) && metadataEntity.aliasesFromNetwork && !metadataEntity.isExpired()) {\n // No need to update\n return AuthorityMetadataSource.CACHE;\n }\n\n metadata = await this.getCloudDiscoveryMetadataFromNetwork();\n if (metadata) {\n metadataEntity.updateCloudDiscoveryMetadata(metadata, true);\n return AuthorityMetadataSource.NETWORK;\n } else {\n // Metadata could not be obtained from config, cache or network\n throw ClientConfigurationError.createUntrustedAuthorityError();\n }\n }\n\n /**\n * Parse cloudDiscoveryMetadata config or check knownAuthorities\n */\n private getCloudDiscoveryMetadataFromConfig(): CloudDiscoveryMetadata | null {\n // Check if network response was provided in config\n if (this.authorityOptions.cloudDiscoveryMetadata) {\n try {\n const parsedResponse = JSON.parse(this.authorityOptions.cloudDiscoveryMetadata) as CloudInstanceDiscoveryResponse;\n const metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(parsedResponse.metadata, this.hostnameAndPort);\n if (metadata) {\n return metadata;\n }\n } catch (e) {\n throw ClientConfigurationError.createInvalidCloudDiscoveryMetadataError();\n }\n }\n\n // If cloudDiscoveryMetadata is empty or does not contain the host, check knownAuthorities\n if (this.isInKnownAuthorities()) {\n return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);\n }\n\n return null;\n }\n\n /**\n * Called to get metadata from network if CloudDiscoveryMetadata was not populated by config\n * @param networkInterface \n */\n private async getCloudDiscoveryMetadataFromNetwork(): Promise<CloudDiscoveryMetadata | null> {\n const instanceDiscoveryEndpoint = `${Constants.AAD_INSTANCE_DISCOVERY_ENDPT}${this.canonicalAuthority}oauth2/v2.0/authorize`;\n let match = null;\n try {\n const response = await this.networkInterface.sendGetRequestAsync<CloudInstanceDiscoveryResponse>(instanceDiscoveryEndpoint);\n const metadata = isCloudInstanceDiscoveryResponse(response.body) ? response.body.metadata : [];\n if (metadata.length === 0) {\n // If no metadata is returned, authority is untrusted\n return null;\n }\n match = Authority.getCloudDiscoveryMetadataFromNetworkResponse(metadata, this.hostnameAndPort);\n } catch(e) {\n return null;\n }\n\n if (!match) {\n // Custom Domain scenario, host is trusted because Instance Discovery call succeeded \n match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);\n }\n return match;\n } \n\n /**\n * Helper function to determine if this host is included in the knownAuthorities config option\n */\n private isInKnownAuthorities(): boolean {\n const matches = this.authorityOptions.knownAuthorities.filter((authority) => {\n return UrlString.getDomainFromUrl(authority).toLowerCase() === this.hostnameAndPort;\n });\n\n return matches.length > 0;\n }\n\n /**\n * Creates cloud discovery metadata object from a given host\n * @param host \n */\n static createCloudDiscoveryMetadataFromHost(host: string): CloudDiscoveryMetadata {\n return {\n preferred_network: host,\n preferred_cache: host,\n aliases: [host]\n };\n }\n\n /**\n * Searches instance discovery network response for the entry that contains the host in the aliases list\n * @param response \n * @param authority \n */\n static getCloudDiscoveryMetadataFromNetworkResponse(response: CloudDiscoveryMetadata[], authority: string): CloudDiscoveryMetadata | null {\n for (let i = 0; i < response.length; i++) {\n const metadata = response[i];\n if (metadata.aliases.indexOf(authority) > -1) {\n return metadata;\n }\n }\n\n return null;\n }\n\n /**\n * helper function to generate environment from authority object\n */\n getPreferredCache(): string {\n if(this.discoveryComplete()) {\n return this.metadata.preferred_cache;\n } else {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Discovery incomplete.\");\n }\n }\n\n /**\n * Returns whether or not the provided host is an alias of this authority instance\n * @param host \n */\n isAlias(host: string): boolean {\n return this.metadata.aliases.indexOf(host) > -1;\n }\n\n /**\n * Checks whether the provided host is that of a public cloud authority\n * \n * @param authority string\n * @returns bool\n */\n static isPublicCloudAuthority(host: string): boolean {\n return Constants.KNOWN_PUBLIC_CLOUDS.indexOf(host) >= 0;\n }\n\n /**\n * Rebuild the authority string with the region\n * \n * @param host string\n * @param region string \n */\n static buildRegionalAuthorityString(host: string, region: string, queryString?: string): string {\n // Create and validate a Url string object with the initial authority string\n const authorityUrlInstance = new UrlString(host);\n authorityUrlInstance.validateAsUri();\n\n const authorityUrlParts = authorityUrlInstance.getUrlComponents();\n\n let hostNameAndPort= `${region}.${authorityUrlParts.HostNameAndPort}`;\n\n if (this.isPublicCloudAuthority(authorityUrlParts.HostNameAndPort)) {\n hostNameAndPort = `${region}.${Constants.REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX}`;\n }\n\n // Include the query string portion of the url\n const url = UrlString.constructAuthorityUriFromObject({\n ...authorityUrlInstance.getUrlComponents(),\n HostNameAndPort: hostNameAndPort\n }).urlString;\n\n // Add the query string if a query string was provided\n if (queryString) return `${url}?${queryString}`;\n\n return url;\n }\n\n /**\n * Replace the endpoints in the metadata object with their regional equivalents.\n * \n * @param metadata OpenIdConfigResponse\n * @param azureRegion string\n */\n static replaceWithRegionalInformation(metadata: OpenIdConfigResponse, azureRegion: string): OpenIdConfigResponse {\n metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);\n // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature\n metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, \"allowestsrnonmsi=true\");\n metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);\n \n return metadata;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;;;AAsBA;;;;;IAuBI,mBAAY,SAAiB,EAAE,gBAAgC,EAAE,YAA2B,EAAE,gBAAkC;QAC5H,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;QACpC,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,CAAC;QACzC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,gBAAgB,CAAC,CAAC;QAC7D,IAAI,CAAC,uBAAuB,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;KAClH;IAGD,sBAAW,oCAAa;;aAAxB;YACI,IAAM,YAAY,GAAG,IAAI,CAAC,+BAA+B,CAAC,YAAY,CAAC;YAEvE,IAAI,YAAY,CAAC,MAAM,IAAI,YAAY,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