@azure/msal-common 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/_virtual/_tslib.js +90 -0
- package/dist/_virtual/_tslib.js.map +1 -0
- package/dist/account/AccountInfo.d.ts +30 -0
- package/dist/account/AccountInfo.d.ts.map +1 -0
- package/dist/account/AuthToken.d.ts +17 -0
- package/dist/account/AuthToken.d.ts.map +1 -0
- package/dist/account/AuthToken.js +43 -0
- package/dist/account/AuthToken.js.map +1 -0
- package/dist/account/CcsCredential.d.ts +9 -0
- package/dist/account/CcsCredential.d.ts.map +1 -0
- package/dist/account/CcsCredential.js +14 -0
- package/dist/account/CcsCredential.js.map +1 -0
- package/dist/account/ClientCredentials.d.ts +15 -0
- package/dist/account/ClientCredentials.d.ts.map +1 -0
- package/dist/account/ClientInfo.d.ts +20 -0
- package/dist/account/ClientInfo.d.ts.map +1 -0
- package/dist/account/ClientInfo.js +44 -0
- package/dist/account/ClientInfo.js.map +1 -0
- package/dist/account/DecodedAuthToken.d.ts +9 -0
- package/dist/account/DecodedAuthToken.d.ts.map +1 -0
- package/dist/account/TokenClaims.d.ts +60 -0
- package/dist/account/TokenClaims.d.ts.map +1 -0
- package/dist/authority/Authority.d.ts +200 -0
- package/dist/authority/Authority.d.ts.map +1 -0
- package/dist/authority/Authority.js +678 -0
- package/dist/authority/Authority.js.map +1 -0
- package/dist/authority/AuthorityFactory.d.ts +29 -0
- package/dist/authority/AuthorityFactory.d.ts.map +1 -0
- package/dist/authority/AuthorityFactory.js +69 -0
- package/dist/authority/AuthorityFactory.js.map +1 -0
- package/dist/authority/AuthorityMetadata.d.ts +623 -0
- package/dist/authority/AuthorityMetadata.d.ts.map +1 -0
- package/dist/authority/AuthorityMetadata.js +12 -0
- package/dist/authority/AuthorityMetadata.js.map +1 -0
- package/dist/authority/AuthorityOptions.d.ts +19 -0
- package/dist/authority/AuthorityOptions.d.ts.map +1 -0
- package/dist/authority/AuthorityOptions.js +24 -0
- package/dist/authority/AuthorityOptions.js.map +1 -0
- package/dist/authority/AuthorityType.d.ts +8 -0
- package/dist/authority/AuthorityType.d.ts.map +1 -0
- package/dist/authority/AuthorityType.js +17 -0
- package/dist/authority/AuthorityType.js.map +1 -0
- package/dist/authority/AzureRegion.d.ts +2 -0
- package/dist/authority/AzureRegion.d.ts.map +1 -0
- package/dist/authority/AzureRegionConfiguration.d.ts +6 -0
- package/dist/authority/AzureRegionConfiguration.d.ts.map +1 -0
- package/dist/authority/CloudDiscoveryMetadata.d.ts +6 -0
- package/dist/authority/CloudDiscoveryMetadata.d.ts.map +1 -0
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +10 -0
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts.map +1 -0
- package/dist/authority/CloudInstanceDiscoveryResponse.js +13 -0
- package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -0
- package/dist/authority/ImdsOptions.d.ts +7 -0
- package/dist/authority/ImdsOptions.d.ts.map +1 -0
- package/dist/authority/OpenIdConfigResponse.d.ts +12 -0
- package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -0
- package/dist/authority/OpenIdConfigResponse.js +15 -0
- package/dist/authority/OpenIdConfigResponse.js.map +1 -0
- package/dist/authority/ProtocolMode.d.ts +8 -0
- package/dist/authority/ProtocolMode.d.ts.map +1 -0
- package/dist/authority/ProtocolMode.js +17 -0
- package/dist/authority/ProtocolMode.js.map +1 -0
- package/dist/authority/RegionDiscovery.d.ts +28 -0
- package/dist/authority/RegionDiscovery.d.ts.map +1 -0
- package/dist/authority/RegionDiscovery.js +127 -0
- package/dist/authority/RegionDiscovery.js.map +1 -0
- package/dist/authority/RegionDiscoveryMetadata.d.ts +7 -0
- package/dist/authority/RegionDiscoveryMetadata.d.ts.map +1 -0
- package/dist/cache/CacheManager.d.ts +393 -0
- package/dist/cache/CacheManager.d.ts.map +1 -0
- package/dist/cache/CacheManager.js +885 -0
- package/dist/cache/CacheManager.js.map +1 -0
- package/dist/cache/entities/AccessTokenEntity.d.ts +57 -0
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -0
- package/dist/cache/entities/AccessTokenEntity.js +124 -0
- package/dist/cache/entities/AccessTokenEntity.js.map +1 -0
- package/dist/cache/entities/AccountEntity.d.ts +100 -0
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -0
- package/dist/cache/entities/AccountEntity.js +243 -0
- package/dist/cache/entities/AccountEntity.js.map +1 -0
- package/dist/cache/entities/AppMetadataEntity.d.ts +40 -0
- package/dist/cache/entities/AppMetadataEntity.d.ts.map +1 -0
- package/dist/cache/entities/AppMetadataEntity.js +74 -0
- package/dist/cache/entities/AppMetadataEntity.js.map +1 -0
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -0
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -0
- package/dist/cache/entities/AuthorityMetadataEntity.js +82 -0
- package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -0
- package/dist/cache/entities/CacheRecord.d.ts +14 -0
- package/dist/cache/entities/CacheRecord.d.ts.map +1 -0
- package/dist/cache/entities/CacheRecord.js +19 -0
- package/dist/cache/entities/CacheRecord.js.map +1 -0
- package/dist/cache/entities/CredentialEntity.d.ts +94 -0
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -0
- package/dist/cache/entities/CredentialEntity.js +164 -0
- package/dist/cache/entities/CredentialEntity.js.map +1 -0
- package/dist/cache/entities/IdTokenEntity.d.ts +35 -0
- package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -0
- package/dist/cache/entities/IdTokenEntity.js +70 -0
- package/dist/cache/entities/IdTokenEntity.js.map +1 -0
- package/dist/cache/entities/RefreshTokenEntity.d.ts +37 -0
- package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -0
- package/dist/cache/entities/RefreshTokenEntity.js +73 -0
- package/dist/cache/entities/RefreshTokenEntity.js.map +1 -0
- package/dist/cache/entities/ServerTelemetryEntity.d.ts +13 -0
- package/dist/cache/entities/ServerTelemetryEntity.d.ts.map +1 -0
- package/dist/cache/entities/ServerTelemetryEntity.js +35 -0
- package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -0
- package/dist/cache/entities/ThrottlingEntity.d.ts +14 -0
- package/dist/cache/entities/ThrottlingEntity.d.ts.map +1 -0
- package/dist/cache/entities/ThrottlingEntity.js +32 -0
- package/dist/cache/entities/ThrottlingEntity.js.map +1 -0
- package/dist/cache/interface/ICacheManager.d.ts +157 -0
- package/dist/cache/interface/ICacheManager.d.ts.map +1 -0
- package/dist/cache/interface/ICachePlugin.d.ts +6 -0
- package/dist/cache/interface/ICachePlugin.d.ts.map +1 -0
- package/dist/cache/interface/ISerializableTokenCache.d.ts +5 -0
- package/dist/cache/interface/ISerializableTokenCache.d.ts.map +1 -0
- package/dist/cache/persistence/TokenCacheContext.d.ts +24 -0
- package/dist/cache/persistence/TokenCacheContext.d.ts.map +1 -0
- package/dist/cache/persistence/TokenCacheContext.js +39 -0
- package/dist/cache/persistence/TokenCacheContext.js.map +1 -0
- package/dist/cache/utils/CacheTypes.d.ts +60 -0
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -0
- package/dist/client/AuthorizationCodeClient.d.ts +76 -0
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -0
- package/dist/client/AuthorizationCodeClient.js +468 -0
- package/dist/client/AuthorizationCodeClient.js.map +1 -0
- package/dist/client/BaseClient.d.ts +45 -0
- package/dist/client/BaseClient.d.ts.map +1 -0
- package/dist/client/BaseClient.js +103 -0
- package/dist/client/BaseClient.js.map +1 -0
- package/dist/client/ClientCredentialClient.d.ts +39 -0
- package/dist/client/ClientCredentialClient.d.ts.map +1 -0
- package/dist/client/ClientCredentialClient.js +202 -0
- package/dist/client/ClientCredentialClient.js.map +1 -0
- package/dist/client/DeviceCodeClient.d.ts +52 -0
- package/dist/client/DeviceCodeClient.d.ts.map +1 -0
- package/dist/client/DeviceCodeClient.js +232 -0
- package/dist/client/DeviceCodeClient.js.map +1 -0
- package/dist/client/OnBehalfOfClient.d.ts +51 -0
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -0
- package/dist/client/OnBehalfOfClient.js +244 -0
- package/dist/client/OnBehalfOfClient.js.map +1 -0
- package/dist/client/RefreshTokenClient.d.ts +40 -0
- package/dist/client/RefreshTokenClient.d.ts.map +1 -0
- package/dist/client/RefreshTokenClient.js +255 -0
- package/dist/client/RefreshTokenClient.js.map +1 -0
- package/dist/client/SilentFlowClient.d.ts +25 -0
- package/dist/client/SilentFlowClient.d.ts.map +1 -0
- package/dist/client/SilentFlowClient.js +128 -0
- package/dist/client/SilentFlowClient.js.map +1 -0
- package/dist/client/UsernamePasswordClient.d.ts +29 -0
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -0
- package/dist/client/UsernamePasswordClient.js +120 -0
- package/dist/client/UsernamePasswordClient.js.map +1 -0
- package/dist/config/AppTokenProvider.d.ts +39 -0
- package/dist/config/AppTokenProvider.d.ts.map +1 -0
- package/dist/config/ClientConfiguration.d.ts +135 -0
- package/dist/config/ClientConfiguration.d.ts.map +1 -0
- package/dist/config/ClientConfiguration.js +105 -0
- package/dist/config/ClientConfiguration.js.map +1 -0
- package/dist/crypto/ICrypto.d.ts +63 -0
- package/dist/crypto/ICrypto.d.ts.map +1 -0
- package/dist/crypto/ICrypto.js +80 -0
- package/dist/crypto/ICrypto.js.map +1 -0
- package/dist/crypto/IGuidGenerator.d.ts +5 -0
- package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
- package/dist/crypto/JoseHeader.d.ts +22 -0
- package/dist/crypto/JoseHeader.d.ts.map +1 -0
- package/dist/crypto/JoseHeader.js +45 -0
- package/dist/crypto/JoseHeader.js.map +1 -0
- package/dist/crypto/PopTokenGenerator.d.ts +56 -0
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -0
- package/dist/crypto/PopTokenGenerator.js +107 -0
- package/dist/crypto/PopTokenGenerator.js.map +1 -0
- package/dist/crypto/SignedHttpRequest.d.ts +12 -0
- package/dist/crypto/SignedHttpRequest.d.ts.map +1 -0
- package/dist/error/AuthError.d.ts +48 -0
- package/dist/error/AuthError.d.ts.map +1 -0
- package/dist/error/AuthError.js +61 -0
- package/dist/error/AuthError.js.map +1 -0
- package/dist/error/ClientAuthError.d.ts +372 -0
- package/dist/error/ClientAuthError.d.ts.map +1 -0
- package/dist/error/ClientAuthError.js +477 -0
- package/dist/error/ClientAuthError.js.map +1 -0
- package/dist/error/ClientConfigurationError.d.ts +199 -0
- package/dist/error/ClientConfigurationError.d.ts.map +1 -0
- package/dist/error/ClientConfigurationError.js +260 -0
- package/dist/error/ClientConfigurationError.js.map +1 -0
- package/dist/error/InteractionRequiredAuthError.d.ts +42 -0
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -0
- package/dist/error/InteractionRequiredAuthError.js +80 -0
- package/dist/error/InteractionRequiredAuthError.js.map +1 -0
- package/dist/error/JoseHeaderError.d.ts +29 -0
- package/dist/error/JoseHeaderError.d.ts.map +1 -0
- package/dist/error/JoseHeaderError.js +50 -0
- package/dist/error/JoseHeaderError.js.map +1 -0
- package/dist/error/ServerError.d.ts +8 -0
- package/dist/error/ServerError.d.ts.map +1 -0
- package/dist/error/ServerError.js +25 -0
- package/dist/error/ServerError.js.map +1 -0
- package/dist/index.cjs.js +8441 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/Logger.d.ts +95 -0
- package/dist/logger/Logger.d.ts.map +1 -0
- package/dist/logger/Logger.js +185 -0
- package/dist/logger/Logger.js.map +1 -0
- package/dist/network/INetworkModule.d.ts +31 -0
- package/dist/network/INetworkModule.d.ts.map +1 -0
- package/dist/network/INetworkModule.js +21 -0
- package/dist/network/INetworkModule.js.map +1 -0
- package/dist/network/NetworkManager.d.ts +21 -0
- package/dist/network/NetworkManager.d.ts.map +1 -0
- package/dist/network/NetworkManager.js +56 -0
- package/dist/network/NetworkManager.js.map +1 -0
- package/dist/network/RequestThumbprint.d.ts +17 -0
- package/dist/network/RequestThumbprint.d.ts.map +1 -0
- package/dist/network/ThrottlingUtils.d.ts +42 -0
- package/dist/network/ThrottlingUtils.d.ts.map +1 -0
- package/dist/network/ThrottlingUtils.js +101 -0
- package/dist/network/ThrottlingUtils.js.map +1 -0
- package/dist/packageMetadata.d.ts +3 -0
- package/dist/packageMetadata.d.ts.map +1 -0
- package/dist/packageMetadata.js +8 -0
- package/dist/packageMetadata.js.map +1 -0
- package/dist/request/AuthenticationHeaderParser.d.ts +20 -0
- package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -0
- package/dist/request/AuthenticationHeaderParser.js +64 -0
- package/dist/request/AuthenticationHeaderParser.js.map +1 -0
- package/dist/request/BaseAuthRequest.d.ts +34 -0
- package/dist/request/BaseAuthRequest.d.ts.map +1 -0
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +28 -0
- package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -0
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +51 -0
- package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -0
- package/dist/request/CommonClientCredentialRequest.d.ts +17 -0
- package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -0
- package/dist/request/CommonDeviceCodeRequest.d.ts +19 -0
- package/dist/request/CommonDeviceCodeRequest.d.ts.map +1 -0
- package/dist/request/CommonEndSessionRequest.d.ts +21 -0
- package/dist/request/CommonEndSessionRequest.d.ts.map +1 -0
- package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -0
- package/dist/request/CommonOnBehalfOfRequest.d.ts.map +1 -0
- package/dist/request/CommonRefreshTokenRequest.d.ts +21 -0
- package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -0
- package/dist/request/CommonSilentFlowRequest.d.ts +20 -0
- package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -0
- package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -0
- package/dist/request/CommonUsernamePasswordRequest.d.ts.map +1 -0
- package/dist/request/RequestParameterBuilder.d.ts +217 -0
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -0
- package/dist/request/RequestParameterBuilder.js +387 -0
- package/dist/request/RequestParameterBuilder.js.map +1 -0
- package/dist/request/RequestValidator.d.ts +34 -0
- package/dist/request/RequestValidator.d.ts.map +1 -0
- package/dist/request/RequestValidator.js +92 -0
- package/dist/request/RequestValidator.js.map +1 -0
- package/dist/request/ScopeSet.d.ts +83 -0
- package/dist/request/ScopeSet.d.ts.map +1 -0
- package/dist/request/ScopeSet.js +192 -0
- package/dist/request/ScopeSet.js.map +1 -0
- package/dist/response/AuthenticationResult.d.ts +38 -0
- package/dist/response/AuthenticationResult.d.ts.map +1 -0
- package/dist/response/AuthorizationCodePayload.d.ts +14 -0
- package/dist/response/AuthorizationCodePayload.d.ts.map +1 -0
- package/dist/response/DeviceCodeResponse.d.ts +26 -0
- package/dist/response/DeviceCodeResponse.d.ts.map +1 -0
- package/dist/response/ExternalTokenResponse.d.ts +15 -0
- package/dist/response/ExternalTokenResponse.d.ts.map +1 -0
- package/dist/response/IMDSBadResponse.d.ts +5 -0
- package/dist/response/IMDSBadResponse.d.ts.map +1 -0
- package/dist/response/ResponseHandler.d.ts +71 -0
- package/dist/response/ResponseHandler.d.ts.map +1 -0
- package/dist/response/ResponseHandler.js +293 -0
- package/dist/response/ResponseHandler.js.map +1 -0
- package/dist/response/ServerAuthorizationCodeResponse.d.ts +22 -0
- package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +1 -0
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +43 -0
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -0
- package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
- package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
- package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
- package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
- package/dist/telemetry/performance/PerformanceClient.js +281 -0
- package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
- package/dist/telemetry/performance/PerformanceEvent.d.ts +249 -0
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
- package/dist/telemetry/performance/PerformanceEvent.js +121 -0
- package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
- package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
- package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
- package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +67 -0
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -0
- package/dist/telemetry/server/ServerTelemetryManager.js +168 -0
- package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -0
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts +9 -0
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts.map +1 -0
- package/dist/url/IUri.d.ts +13 -0
- package/dist/url/IUri.d.ts.map +1 -0
- package/dist/url/UrlString.d.ts +62 -0
- package/dist/url/UrlString.d.ts.map +1 -0
- package/dist/url/UrlString.js +208 -0
- package/dist/url/UrlString.js.map +1 -0
- package/dist/utils/Constants.d.ts +340 -0
- package/dist/utils/Constants.d.ts.map +1 -0
- package/dist/utils/Constants.js +381 -0
- package/dist/utils/Constants.js.map +1 -0
- package/dist/utils/MsalTypes.d.ts +7 -0
- package/dist/utils/MsalTypes.d.ts.map +1 -0
- package/dist/utils/ProtocolUtils.d.ts +43 -0
- package/dist/utils/ProtocolUtils.d.ts.map +1 -0
- package/dist/utils/ProtocolUtils.js +77 -0
- package/dist/utils/ProtocolUtils.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +54 -0
- package/dist/utils/StringUtils.d.ts.map +1 -0
- package/dist/utils/StringUtils.js +129 -0
- package/dist/utils/StringUtils.js.map +1 -0
- package/dist/utils/TimeUtils.d.ts +28 -0
- package/dist/utils/TimeUtils.d.ts.map +1 -0
- package/dist/utils/TimeUtils.js +53 -0
- package/dist/utils/TimeUtils.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
/*! @azure/msal-common v0.0.1-alpha.0 2022-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 { EndpointMetadata, InstanceDiscoveryMetadata } from './AuthorityMetadata.js';
|
|
10
|
+
import { ClientConfigurationError } from '../error/ClientConfigurationError.js';
|
|
11
|
+
import { ProtocolMode } from './ProtocolMode.js';
|
|
12
|
+
import { AuthorityMetadataEntity } from '../cache/entities/AuthorityMetadataEntity.js';
|
|
13
|
+
import { AzureCloudInstance } from './AuthorityOptions.js';
|
|
14
|
+
import { isCloudInstanceDiscoveryResponse } from './CloudInstanceDiscoveryResponse.js';
|
|
15
|
+
import { RegionDiscovery } from './RegionDiscovery.js';
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
+
* Licensed under the MIT License.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the
|
|
23
|
+
* endpoint. It will store the pertinent config data in this object for use during token calls.
|
|
24
|
+
*/
|
|
25
|
+
var Authority = /** @class */ (function () {
|
|
26
|
+
function Authority(authority, networkInterface, cacheManager, authorityOptions, proxyUrl) {
|
|
27
|
+
this.canonicalAuthority = authority;
|
|
28
|
+
this._canonicalAuthority.validateAsUri();
|
|
29
|
+
this.networkInterface = networkInterface;
|
|
30
|
+
this.cacheManager = cacheManager;
|
|
31
|
+
this.authorityOptions = authorityOptions;
|
|
32
|
+
this.regionDiscovery = new RegionDiscovery(networkInterface);
|
|
33
|
+
this.regionDiscoveryMetadata = { region_used: undefined, region_source: undefined, region_outcome: undefined };
|
|
34
|
+
this.proxyUrl = proxyUrl || Constants.EMPTY_STRING;
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(Authority.prototype, "authorityType", {
|
|
37
|
+
// See above for AuthorityType
|
|
38
|
+
get: function () {
|
|
39
|
+
var pathSegments = this.canonicalAuthorityUrlComponents.PathSegments;
|
|
40
|
+
if (pathSegments.length && pathSegments[0].toLowerCase() === Constants.ADFS) {
|
|
41
|
+
return AuthorityType.Adfs;
|
|
42
|
+
}
|
|
43
|
+
return AuthorityType.Default;
|
|
44
|
+
},
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(Authority.prototype, "protocolMode", {
|
|
49
|
+
/**
|
|
50
|
+
* ProtocolMode enum representing the way endpoints are constructed.
|
|
51
|
+
*/
|
|
52
|
+
get: function () {
|
|
53
|
+
return this.authorityOptions.protocolMode;
|
|
54
|
+
},
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(Authority.prototype, "options", {
|
|
59
|
+
/**
|
|
60
|
+
* Returns authorityOptions which can be used to reinstantiate a new authority instance
|
|
61
|
+
*/
|
|
62
|
+
get: function () {
|
|
63
|
+
return this.authorityOptions;
|
|
64
|
+
},
|
|
65
|
+
enumerable: false,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(Authority.prototype, "canonicalAuthority", {
|
|
69
|
+
/**
|
|
70
|
+
* A URL that is the authority set by the developer
|
|
71
|
+
*/
|
|
72
|
+
get: function () {
|
|
73
|
+
return this._canonicalAuthority.urlString;
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Sets canonical authority.
|
|
77
|
+
*/
|
|
78
|
+
set: function (url) {
|
|
79
|
+
this._canonicalAuthority = new UrlString(url);
|
|
80
|
+
this._canonicalAuthority.validateAsUri();
|
|
81
|
+
this._canonicalAuthorityUrlComponents = null;
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(Authority.prototype, "canonicalAuthorityUrlComponents", {
|
|
87
|
+
/**
|
|
88
|
+
* Get authority components.
|
|
89
|
+
*/
|
|
90
|
+
get: function () {
|
|
91
|
+
if (!this._canonicalAuthorityUrlComponents) {
|
|
92
|
+
this._canonicalAuthorityUrlComponents = this._canonicalAuthority.getUrlComponents();
|
|
93
|
+
}
|
|
94
|
+
return this._canonicalAuthorityUrlComponents;
|
|
95
|
+
},
|
|
96
|
+
enumerable: false,
|
|
97
|
+
configurable: true
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(Authority.prototype, "hostnameAndPort", {
|
|
100
|
+
/**
|
|
101
|
+
* Get hostname and port i.e. login.microsoftonline.com
|
|
102
|
+
*/
|
|
103
|
+
get: function () {
|
|
104
|
+
return this.canonicalAuthorityUrlComponents.HostNameAndPort.toLowerCase();
|
|
105
|
+
},
|
|
106
|
+
enumerable: false,
|
|
107
|
+
configurable: true
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(Authority.prototype, "tenant", {
|
|
110
|
+
/**
|
|
111
|
+
* Get tenant for authority.
|
|
112
|
+
*/
|
|
113
|
+
get: function () {
|
|
114
|
+
return this.canonicalAuthorityUrlComponents.PathSegments[0];
|
|
115
|
+
},
|
|
116
|
+
enumerable: false,
|
|
117
|
+
configurable: true
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(Authority.prototype, "authorizationEndpoint", {
|
|
120
|
+
/**
|
|
121
|
+
* OAuth /authorize endpoint for requests
|
|
122
|
+
*/
|
|
123
|
+
get: function () {
|
|
124
|
+
if (this.discoveryComplete()) {
|
|
125
|
+
var endpoint = this.replacePath(this.metadata.authorization_endpoint);
|
|
126
|
+
return this.replaceTenant(endpoint);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
enumerable: false,
|
|
133
|
+
configurable: true
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(Authority.prototype, "tokenEndpoint", {
|
|
136
|
+
/**
|
|
137
|
+
* OAuth /token endpoint for requests
|
|
138
|
+
*/
|
|
139
|
+
get: function () {
|
|
140
|
+
if (this.discoveryComplete()) {
|
|
141
|
+
var endpoint = this.replacePath(this.metadata.token_endpoint);
|
|
142
|
+
return this.replaceTenant(endpoint);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
enumerable: false,
|
|
149
|
+
configurable: true
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(Authority.prototype, "deviceCodeEndpoint", {
|
|
152
|
+
get: function () {
|
|
153
|
+
if (this.discoveryComplete()) {
|
|
154
|
+
var endpoint = this.replacePath(this.metadata.token_endpoint.replace("/token", "/devicecode"));
|
|
155
|
+
return this.replaceTenant(endpoint);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
enumerable: false,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(Authority.prototype, "endSessionEndpoint", {
|
|
165
|
+
/**
|
|
166
|
+
* OAuth logout endpoint for requests
|
|
167
|
+
*/
|
|
168
|
+
get: function () {
|
|
169
|
+
if (this.discoveryComplete()) {
|
|
170
|
+
// ROPC policies may not have end_session_endpoint set
|
|
171
|
+
if (!this.metadata.end_session_endpoint) {
|
|
172
|
+
throw ClientAuthError.createLogoutNotSupportedError();
|
|
173
|
+
}
|
|
174
|
+
var endpoint = this.replacePath(this.metadata.end_session_endpoint);
|
|
175
|
+
return this.replaceTenant(endpoint);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
enumerable: false,
|
|
182
|
+
configurable: true
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(Authority.prototype, "selfSignedJwtAudience", {
|
|
185
|
+
/**
|
|
186
|
+
* OAuth issuer for requests
|
|
187
|
+
*/
|
|
188
|
+
get: function () {
|
|
189
|
+
if (this.discoveryComplete()) {
|
|
190
|
+
var endpoint = this.replacePath(this.metadata.issuer);
|
|
191
|
+
return this.replaceTenant(endpoint);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
enumerable: false,
|
|
198
|
+
configurable: true
|
|
199
|
+
});
|
|
200
|
+
Object.defineProperty(Authority.prototype, "jwksUri", {
|
|
201
|
+
/**
|
|
202
|
+
* Jwks_uri for token signing keys
|
|
203
|
+
*/
|
|
204
|
+
get: function () {
|
|
205
|
+
if (this.discoveryComplete()) {
|
|
206
|
+
var endpoint = this.replacePath(this.metadata.jwks_uri);
|
|
207
|
+
return this.replaceTenant(endpoint);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
enumerable: false,
|
|
214
|
+
configurable: true
|
|
215
|
+
});
|
|
216
|
+
/**
|
|
217
|
+
* Replaces tenant in url path with current tenant. Defaults to common.
|
|
218
|
+
* @param urlString
|
|
219
|
+
*/
|
|
220
|
+
Authority.prototype.replaceTenant = function (urlString) {
|
|
221
|
+
return urlString.replace(/{tenant}|{tenantid}/g, this.tenant);
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Replaces path such as tenant or policy with the current tenant or policy.
|
|
225
|
+
* @param urlString
|
|
226
|
+
*/
|
|
227
|
+
Authority.prototype.replacePath = function (urlString) {
|
|
228
|
+
var endpoint = urlString;
|
|
229
|
+
var cachedAuthorityUrl = new UrlString(this.metadata.canonical_authority);
|
|
230
|
+
var cachedAuthorityParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
|
|
231
|
+
var currentAuthorityParts = this.canonicalAuthorityUrlComponents.PathSegments;
|
|
232
|
+
currentAuthorityParts.forEach(function (currentPart, index) {
|
|
233
|
+
var cachedPart = cachedAuthorityParts[index];
|
|
234
|
+
if (currentPart !== cachedPart) {
|
|
235
|
+
endpoint = endpoint.replace("/" + cachedPart + "/", "/" + currentPart + "/");
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return endpoint;
|
|
239
|
+
};
|
|
240
|
+
Object.defineProperty(Authority.prototype, "defaultOpenIdConfigurationEndpoint", {
|
|
241
|
+
/**
|
|
242
|
+
* The default open id configuration endpoint for any canonical authority.
|
|
243
|
+
*/
|
|
244
|
+
get: function () {
|
|
245
|
+
if (this.authorityType === AuthorityType.Adfs || this.protocolMode === ProtocolMode.OIDC) {
|
|
246
|
+
return this.canonicalAuthority + ".well-known/openid-configuration";
|
|
247
|
+
}
|
|
248
|
+
return this.canonicalAuthority + "v2.0/.well-known/openid-configuration";
|
|
249
|
+
},
|
|
250
|
+
enumerable: false,
|
|
251
|
+
configurable: true
|
|
252
|
+
});
|
|
253
|
+
/**
|
|
254
|
+
* Boolean that returns whethr or not tenant discovery has been completed.
|
|
255
|
+
*/
|
|
256
|
+
Authority.prototype.discoveryComplete = function () {
|
|
257
|
+
return !!this.metadata;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Perform endpoint discovery to discover aliases, preferred_cache, preferred_network
|
|
261
|
+
* and the /authorize, /token and logout endpoints.
|
|
262
|
+
*/
|
|
263
|
+
Authority.prototype.resolveEndpointsAsync = function () {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
+
var metadataEntity, cloudDiscoverySource, endpointSource, cacheKey;
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
switch (_a.label) {
|
|
268
|
+
case 0:
|
|
269
|
+
metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(this.hostnameAndPort);
|
|
270
|
+
if (!metadataEntity) {
|
|
271
|
+
metadataEntity = new AuthorityMetadataEntity();
|
|
272
|
+
metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
|
|
273
|
+
}
|
|
274
|
+
return [4 /*yield*/, this.updateCloudDiscoveryMetadata(metadataEntity)];
|
|
275
|
+
case 1:
|
|
276
|
+
cloudDiscoverySource = _a.sent();
|
|
277
|
+
this.canonicalAuthority = this.canonicalAuthority.replace(this.hostnameAndPort, metadataEntity.preferred_network);
|
|
278
|
+
return [4 /*yield*/, this.updateEndpointMetadata(metadataEntity)];
|
|
279
|
+
case 2:
|
|
280
|
+
endpointSource = _a.sent();
|
|
281
|
+
if (cloudDiscoverySource !== AuthorityMetadataSource.CACHE && endpointSource !== AuthorityMetadataSource.CACHE) {
|
|
282
|
+
// Reset the expiration time unless both values came from a successful cache lookup
|
|
283
|
+
metadataEntity.resetExpiresAt();
|
|
284
|
+
metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
|
|
285
|
+
}
|
|
286
|
+
cacheKey = this.cacheManager.generateAuthorityMetadataCacheKey(metadataEntity.preferred_cache);
|
|
287
|
+
this.cacheManager.setAuthorityMetadata(cacheKey, metadataEntity);
|
|
288
|
+
this.metadata = metadataEntity;
|
|
289
|
+
return [2 /*return*/];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Update AuthorityMetadataEntity with new endpoints and return where the information came from
|
|
296
|
+
* @param metadataEntity
|
|
297
|
+
*/
|
|
298
|
+
Authority.prototype.updateEndpointMetadata = function (metadataEntity) {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var metadata, harcodedMetadata;
|
|
302
|
+
return __generator(this, function (_c) {
|
|
303
|
+
switch (_c.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
metadata = this.getEndpointMetadataFromConfig();
|
|
306
|
+
if (metadata) {
|
|
307
|
+
metadataEntity.updateEndpointMetadata(metadata, false);
|
|
308
|
+
return [2 /*return*/, AuthorityMetadataSource.CONFIG];
|
|
309
|
+
}
|
|
310
|
+
if (this.isAuthoritySameType(metadataEntity) && metadataEntity.endpointsFromNetwork && !metadataEntity.isExpired()) {
|
|
311
|
+
// No need to update
|
|
312
|
+
return [2 /*return*/, AuthorityMetadataSource.CACHE];
|
|
313
|
+
}
|
|
314
|
+
harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
|
|
315
|
+
return [4 /*yield*/, this.getEndpointMetadataFromNetwork()];
|
|
316
|
+
case 1:
|
|
317
|
+
metadata = _c.sent();
|
|
318
|
+
if (!metadata) return [3 /*break*/, 4];
|
|
319
|
+
if (!((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.azureRegion)) return [3 /*break*/, 3];
|
|
320
|
+
return [4 /*yield*/, this.updateMetadataWithRegionalInformation(metadata)];
|
|
321
|
+
case 2:
|
|
322
|
+
metadata = _c.sent();
|
|
323
|
+
_c.label = 3;
|
|
324
|
+
case 3:
|
|
325
|
+
metadataEntity.updateEndpointMetadata(metadata, true);
|
|
326
|
+
return [2 /*return*/, AuthorityMetadataSource.NETWORK];
|
|
327
|
+
case 4:
|
|
328
|
+
if (!(harcodedMetadata && !this.authorityOptions.skipAuthorityMetadataCache)) return [3 /*break*/, 7];
|
|
329
|
+
if (!((_b = this.authorityOptions.azureRegionConfiguration) === null || _b === void 0 ? void 0 : _b.azureRegion)) return [3 /*break*/, 6];
|
|
330
|
+
return [4 /*yield*/, this.updateMetadataWithRegionalInformation(harcodedMetadata)];
|
|
331
|
+
case 5:
|
|
332
|
+
harcodedMetadata = _c.sent();
|
|
333
|
+
_c.label = 6;
|
|
334
|
+
case 6:
|
|
335
|
+
metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
|
|
336
|
+
return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
|
|
337
|
+
case 7: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Compares the number of url components after the domain to determine if the cached authority metadata can be used for the requested authority
|
|
344
|
+
* Protects against same domain different authority such as login.microsoftonline.com/tenant and login.microsoftonline.com/tfp/tenant/policy
|
|
345
|
+
* @param metadataEntity
|
|
346
|
+
*/
|
|
347
|
+
Authority.prototype.isAuthoritySameType = function (metadataEntity) {
|
|
348
|
+
var cachedAuthorityUrl = new UrlString(metadataEntity.canonical_authority);
|
|
349
|
+
var cachedParts = cachedAuthorityUrl.getUrlComponents().PathSegments;
|
|
350
|
+
return cachedParts.length === this.canonicalAuthorityUrlComponents.PathSegments.length;
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* Parse authorityMetadata config option
|
|
354
|
+
*/
|
|
355
|
+
Authority.prototype.getEndpointMetadataFromConfig = function () {
|
|
356
|
+
if (this.authorityOptions.authorityMetadata) {
|
|
357
|
+
try {
|
|
358
|
+
return JSON.parse(this.authorityOptions.authorityMetadata);
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
throw ClientConfigurationError.createInvalidAuthorityMetadataError();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Gets OAuth endpoints from the given OpenID configuration endpoint.
|
|
368
|
+
*
|
|
369
|
+
* @param hasHardcodedMetadata boolean
|
|
370
|
+
*/
|
|
371
|
+
Authority.prototype.getEndpointMetadataFromNetwork = function () {
|
|
372
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
373
|
+
var options, response;
|
|
374
|
+
return __generator(this, function (_a) {
|
|
375
|
+
switch (_a.label) {
|
|
376
|
+
case 0:
|
|
377
|
+
options = {};
|
|
378
|
+
if (this.proxyUrl) {
|
|
379
|
+
options.proxyUrl = this.proxyUrl;
|
|
380
|
+
}
|
|
381
|
+
_a.label = 1;
|
|
382
|
+
case 1:
|
|
383
|
+
_a.trys.push([1, 3, , 4]);
|
|
384
|
+
return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint, options)];
|
|
385
|
+
case 2:
|
|
386
|
+
response = _a.sent();
|
|
387
|
+
return [2 /*return*/, isOpenIdConfigResponse(response.body) ? response.body : null];
|
|
388
|
+
case 3:
|
|
389
|
+
_a.sent();
|
|
390
|
+
return [2 /*return*/, null];
|
|
391
|
+
case 4: return [2 /*return*/];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Get OAuth endpoints for common authorities.
|
|
398
|
+
*/
|
|
399
|
+
Authority.prototype.getEndpointMetadataFromHardcodedValues = function () {
|
|
400
|
+
if (this.canonicalAuthority in EndpointMetadata) {
|
|
401
|
+
return EndpointMetadata[this.canonicalAuthority];
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Update the retrieved metadata with regional information.
|
|
407
|
+
*/
|
|
408
|
+
Authority.prototype.updateMetadataWithRegionalInformation = function (metadata) {
|
|
409
|
+
var _a, _b, _c, _d, _e;
|
|
410
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
411
|
+
var autodetectedRegionName, azureRegion;
|
|
412
|
+
return __generator(this, function (_f) {
|
|
413
|
+
switch (_f.label) {
|
|
414
|
+
case 0: return [4 /*yield*/, this.regionDiscovery.detectRegion((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
|
|
415
|
+
case 1:
|
|
416
|
+
autodetectedRegionName = _f.sent();
|
|
417
|
+
azureRegion = ((_b = this.authorityOptions.azureRegionConfiguration) === null || _b === void 0 ? void 0 : _b.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
|
|
418
|
+
? autodetectedRegionName
|
|
419
|
+
: (_c = this.authorityOptions.azureRegionConfiguration) === null || _c === void 0 ? void 0 : _c.azureRegion;
|
|
420
|
+
if (((_d = this.authorityOptions.azureRegionConfiguration) === null || _d === void 0 ? void 0 : _d.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
|
|
421
|
+
this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
|
|
422
|
+
RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
|
|
423
|
+
RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
if (autodetectedRegionName) {
|
|
427
|
+
this.regionDiscoveryMetadata.region_outcome = (((_e = this.authorityOptions.azureRegionConfiguration) === null || _e === void 0 ? void 0 : _e.azureRegion) === autodetectedRegionName) ?
|
|
428
|
+
RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
|
|
429
|
+
RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (azureRegion) {
|
|
436
|
+
this.regionDiscoveryMetadata.region_used = azureRegion;
|
|
437
|
+
return [2 /*return*/, Authority.replaceWithRegionalInformation(metadata, azureRegion)];
|
|
438
|
+
}
|
|
439
|
+
return [2 /*return*/, metadata];
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache and returns where the information was retrived from
|
|
446
|
+
* @param cachedMetadata
|
|
447
|
+
* @param newMetadata
|
|
448
|
+
*/
|
|
449
|
+
Authority.prototype.updateCloudDiscoveryMetadata = function (metadataEntity) {
|
|
450
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
451
|
+
var metadata, harcodedMetadata;
|
|
452
|
+
return __generator(this, function (_a) {
|
|
453
|
+
switch (_a.label) {
|
|
454
|
+
case 0:
|
|
455
|
+
metadata = this.getCloudDiscoveryMetadataFromConfig();
|
|
456
|
+
if (metadata) {
|
|
457
|
+
metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
|
|
458
|
+
return [2 /*return*/, AuthorityMetadataSource.CONFIG];
|
|
459
|
+
}
|
|
460
|
+
// If The cached metadata came from config but that config was not passed to this instance, we must go to the network
|
|
461
|
+
if (this.isAuthoritySameType(metadataEntity) && metadataEntity.aliasesFromNetwork && !metadataEntity.isExpired()) {
|
|
462
|
+
// No need to update
|
|
463
|
+
return [2 /*return*/, AuthorityMetadataSource.CACHE];
|
|
464
|
+
}
|
|
465
|
+
harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
|
|
466
|
+
return [4 /*yield*/, this.getCloudDiscoveryMetadataFromNetwork()];
|
|
467
|
+
case 1:
|
|
468
|
+
metadata = _a.sent();
|
|
469
|
+
if (metadata) {
|
|
470
|
+
metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
|
|
471
|
+
return [2 /*return*/, AuthorityMetadataSource.NETWORK];
|
|
472
|
+
}
|
|
473
|
+
if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
|
|
474
|
+
metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
|
|
475
|
+
return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
// Metadata could not be obtained from config, cache or network
|
|
479
|
+
throw ClientConfigurationError.createUntrustedAuthorityError();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* Parse cloudDiscoveryMetadata config or check knownAuthorities
|
|
487
|
+
*/
|
|
488
|
+
Authority.prototype.getCloudDiscoveryMetadataFromConfig = function () {
|
|
489
|
+
// Check if network response was provided in config
|
|
490
|
+
if (this.authorityOptions.cloudDiscoveryMetadata) {
|
|
491
|
+
try {
|
|
492
|
+
var parsedResponse = JSON.parse(this.authorityOptions.cloudDiscoveryMetadata);
|
|
493
|
+
var metadata = Authority.getCloudDiscoveryMetadataFromNetworkResponse(parsedResponse.metadata, this.hostnameAndPort);
|
|
494
|
+
if (metadata) {
|
|
495
|
+
return metadata;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
catch (e) {
|
|
499
|
+
throw ClientConfigurationError.createInvalidCloudDiscoveryMetadataError();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
// If cloudDiscoveryMetadata is empty or does not contain the host, check knownAuthorities
|
|
503
|
+
if (this.isInKnownAuthorities()) {
|
|
504
|
+
return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
|
|
505
|
+
}
|
|
506
|
+
return null;
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Called to get metadata from network if CloudDiscoveryMetadata was not populated by config
|
|
510
|
+
*
|
|
511
|
+
* @param hasHardcodedMetadata boolean
|
|
512
|
+
*/
|
|
513
|
+
Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
|
|
514
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
+
var instanceDiscoveryEndpoint, options, match, response, metadata;
|
|
516
|
+
return __generator(this, function (_a) {
|
|
517
|
+
switch (_a.label) {
|
|
518
|
+
case 0:
|
|
519
|
+
instanceDiscoveryEndpoint = "" + Constants.AAD_INSTANCE_DISCOVERY_ENDPT + this.canonicalAuthority + "oauth2/v2.0/authorize";
|
|
520
|
+
options = {};
|
|
521
|
+
if (this.proxyUrl) {
|
|
522
|
+
options.proxyUrl = this.proxyUrl;
|
|
523
|
+
}
|
|
524
|
+
match = null;
|
|
525
|
+
_a.label = 1;
|
|
526
|
+
case 1:
|
|
527
|
+
_a.trys.push([1, 3, , 4]);
|
|
528
|
+
return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options)];
|
|
529
|
+
case 2:
|
|
530
|
+
response = _a.sent();
|
|
531
|
+
metadata = isCloudInstanceDiscoveryResponse(response.body)
|
|
532
|
+
? response.body.metadata
|
|
533
|
+
: [];
|
|
534
|
+
if (metadata.length === 0) {
|
|
535
|
+
// If no metadata is returned, authority is untrusted
|
|
536
|
+
return [2 /*return*/, null];
|
|
537
|
+
}
|
|
538
|
+
match = Authority.getCloudDiscoveryMetadataFromNetworkResponse(metadata, this.hostnameAndPort);
|
|
539
|
+
return [3 /*break*/, 4];
|
|
540
|
+
case 3:
|
|
541
|
+
_a.sent();
|
|
542
|
+
return [2 /*return*/, null];
|
|
543
|
+
case 4:
|
|
544
|
+
if (!match) {
|
|
545
|
+
// Custom Domain scenario, host is trusted because Instance Discovery call succeeded
|
|
546
|
+
match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
|
|
547
|
+
}
|
|
548
|
+
return [2 /*return*/, match];
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* Get cloud discovery metadata for common authorities
|
|
555
|
+
*/
|
|
556
|
+
Authority.prototype.getCloudDiscoveryMetadataFromHarcodedValues = function () {
|
|
557
|
+
if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
|
|
558
|
+
return InstanceDiscoveryMetadata[this.canonicalAuthority];
|
|
559
|
+
}
|
|
560
|
+
return null;
|
|
561
|
+
};
|
|
562
|
+
/**
|
|
563
|
+
* Helper function to determine if this host is included in the knownAuthorities config option
|
|
564
|
+
*/
|
|
565
|
+
Authority.prototype.isInKnownAuthorities = function () {
|
|
566
|
+
var _this = this;
|
|
567
|
+
var matches = this.authorityOptions.knownAuthorities.filter(function (authority) {
|
|
568
|
+
return UrlString.getDomainFromUrl(authority).toLowerCase() === _this.hostnameAndPort;
|
|
569
|
+
});
|
|
570
|
+
return matches.length > 0;
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* helper function to populate the authority based on azureCloudOptions
|
|
574
|
+
* @param authorityString
|
|
575
|
+
* @param azureCloudOptions
|
|
576
|
+
*/
|
|
577
|
+
Authority.generateAuthority = function (authorityString, azureCloudOptions) {
|
|
578
|
+
var authorityAzureCloudInstance;
|
|
579
|
+
if (azureCloudOptions && azureCloudOptions.azureCloudInstance !== AzureCloudInstance.None) {
|
|
580
|
+
var tenant = azureCloudOptions.tenant ? azureCloudOptions.tenant : Constants.DEFAULT_COMMON_TENANT;
|
|
581
|
+
authorityAzureCloudInstance = azureCloudOptions.azureCloudInstance + "/" + tenant + "/";
|
|
582
|
+
}
|
|
583
|
+
return authorityAzureCloudInstance ? authorityAzureCloudInstance : authorityString;
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* Creates cloud discovery metadata object from a given host
|
|
587
|
+
* @param host
|
|
588
|
+
*/
|
|
589
|
+
Authority.createCloudDiscoveryMetadataFromHost = function (host) {
|
|
590
|
+
return {
|
|
591
|
+
preferred_network: host,
|
|
592
|
+
preferred_cache: host,
|
|
593
|
+
aliases: [host]
|
|
594
|
+
};
|
|
595
|
+
};
|
|
596
|
+
/**
|
|
597
|
+
* Searches instance discovery network response for the entry that contains the host in the aliases list
|
|
598
|
+
* @param response
|
|
599
|
+
* @param authority
|
|
600
|
+
*/
|
|
601
|
+
Authority.getCloudDiscoveryMetadataFromNetworkResponse = function (response, authority) {
|
|
602
|
+
for (var i = 0; i < response.length; i++) {
|
|
603
|
+
var metadata = response[i];
|
|
604
|
+
if (metadata.aliases.indexOf(authority) > -1) {
|
|
605
|
+
return metadata;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return null;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* helper function to generate environment from authority object
|
|
612
|
+
*/
|
|
613
|
+
Authority.prototype.getPreferredCache = function () {
|
|
614
|
+
if (this.discoveryComplete()) {
|
|
615
|
+
return this.metadata.preferred_cache;
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* Returns whether or not the provided host is an alias of this authority instance
|
|
623
|
+
* @param host
|
|
624
|
+
*/
|
|
625
|
+
Authority.prototype.isAlias = function (host) {
|
|
626
|
+
return this.metadata.aliases.indexOf(host) > -1;
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* Checks whether the provided host is that of a public cloud authority
|
|
630
|
+
*
|
|
631
|
+
* @param authority string
|
|
632
|
+
* @returns bool
|
|
633
|
+
*/
|
|
634
|
+
Authority.isPublicCloudAuthority = function (host) {
|
|
635
|
+
return Constants.KNOWN_PUBLIC_CLOUDS.indexOf(host) >= 0;
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Rebuild the authority string with the region
|
|
639
|
+
*
|
|
640
|
+
* @param host string
|
|
641
|
+
* @param region string
|
|
642
|
+
*/
|
|
643
|
+
Authority.buildRegionalAuthorityString = function (host, region, queryString) {
|
|
644
|
+
// Create and validate a Url string object with the initial authority string
|
|
645
|
+
var authorityUrlInstance = new UrlString(host);
|
|
646
|
+
authorityUrlInstance.validateAsUri();
|
|
647
|
+
var authorityUrlParts = authorityUrlInstance.getUrlComponents();
|
|
648
|
+
var hostNameAndPort = region + "." + authorityUrlParts.HostNameAndPort;
|
|
649
|
+
if (this.isPublicCloudAuthority(authorityUrlParts.HostNameAndPort)) {
|
|
650
|
+
hostNameAndPort = region + "." + Constants.REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX;
|
|
651
|
+
}
|
|
652
|
+
// Include the query string portion of the url
|
|
653
|
+
var url = UrlString.constructAuthorityUriFromObject(__assign(__assign({}, authorityUrlInstance.getUrlComponents()), { HostNameAndPort: hostNameAndPort })).urlString;
|
|
654
|
+
// Add the query string if a query string was provided
|
|
655
|
+
if (queryString)
|
|
656
|
+
return url + "?" + queryString;
|
|
657
|
+
return url;
|
|
658
|
+
};
|
|
659
|
+
/**
|
|
660
|
+
* Replace the endpoints in the metadata object with their regional equivalents.
|
|
661
|
+
*
|
|
662
|
+
* @param metadata OpenIdConfigResponse
|
|
663
|
+
* @param azureRegion string
|
|
664
|
+
*/
|
|
665
|
+
Authority.replaceWithRegionalInformation = function (metadata, azureRegion) {
|
|
666
|
+
metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
|
|
667
|
+
// TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
|
|
668
|
+
metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, "allowestsrnonmsi=true");
|
|
669
|
+
if (metadata.end_session_endpoint) {
|
|
670
|
+
metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
|
|
671
|
+
}
|
|
672
|
+
return metadata;
|
|
673
|
+
};
|
|
674
|
+
return Authority;
|
|
675
|
+
}());
|
|
676
|
+
|
|
677
|
+
export { Authority };
|
|
678
|
+
//# sourceMappingURL=Authority.js.map
|