@azure/msal-common 14.0.1 → 14.0.3
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/dist/account/AuthToken.d.ts +14 -17
- package/dist/account/AuthToken.d.ts.map +1 -1
- package/dist/account/AuthToken.mjs +48 -39
- package/dist/account/AuthToken.mjs.map +1 -1
- package/dist/account/CcsCredential.mjs +1 -1
- package/dist/account/CcsCredential.mjs.map +1 -1
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.mjs +3 -4
- package/dist/account/ClientInfo.mjs.map +1 -1
- package/dist/authority/Authority.d.ts +1 -0
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +4 -2
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts +1 -0
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +3 -3
- package/dist/authority/AuthorityFactory.mjs.map +1 -1
- package/dist/authority/AuthorityMetadata.mjs +1 -1
- package/dist/authority/AuthorityMetadata.mjs.map +1 -1
- package/dist/authority/AuthorityOptions.mjs +1 -1
- package/dist/authority/AuthorityOptions.mjs.map +1 -1
- package/dist/authority/AuthorityType.mjs +1 -1
- package/dist/authority/AuthorityType.mjs.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
- package/dist/authority/ProtocolMode.mjs +1 -1
- package/dist/authority/ProtocolMode.mjs.map +1 -1
- package/dist/authority/RegionDiscovery.mjs +1 -1
- package/dist/authority/RegionDiscovery.mjs.map +1 -1
- package/dist/cache/CacheManager.d.ts +2 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +7 -5
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.mjs +4 -7
- package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts +1 -0
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +3 -4
- package/dist/cache/entities/AccountEntity.mjs.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -0
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +2 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
- package/dist/cache/entities/CacheRecord.d.ts +1 -0
- package/dist/cache/entities/CacheRecord.d.ts.map +1 -1
- package/dist/cache/entities/CacheRecord.mjs +2 -1
- package/dist/cache/entities/CacheRecord.mjs.map +1 -1
- package/dist/cache/entities/CredentialEntity.mjs +1 -1
- package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
- package/dist/cache/entities/IdTokenEntity.mjs +1 -1
- package/dist/cache/entities/IdTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +7 -0
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts +1 -0
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +11 -39
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +2 -1
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.mjs +9 -2
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts +1 -0
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +3 -11
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +1 -0
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +8 -7
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/ClientConfiguration.d.ts +2 -0
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.mjs +1 -1
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/crypto/ICrypto.mjs +1 -1
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/JoseHeader.d.ts +1 -0
- package/dist/crypto/JoseHeader.d.ts.map +1 -1
- package/dist/crypto/JoseHeader.mjs +2 -1
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +1 -0
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +2 -1
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/error/AuthError.mjs +1 -1
- package/dist/error/AuthError.mjs.map +1 -1
- package/dist/error/ClientAuthError.mjs +1 -1
- package/dist/error/ClientAuthError.mjs.map +1 -1
- package/dist/error/ClientConfigurationError.mjs +1 -1
- package/dist/error/ClientConfigurationError.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
- package/dist/error/JoseHeaderError.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs.map +1 -1
- package/dist/error/ServerError.mjs +1 -1
- package/dist/error/ServerError.mjs.map +1 -1
- package/dist/index.cjs +1926 -1826
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.mjs +2 -12
- package/dist/logger/Logger.mjs.map +1 -1
- package/dist/network/INetworkModule.mjs +1 -1
- package/dist/network/INetworkModule.mjs.map +1 -1
- package/dist/network/NetworkManager.d.ts +1 -0
- package/dist/network/NetworkManager.d.ts.map +1 -1
- package/dist/network/NetworkManager.mjs +2 -1
- package/dist/network/NetworkManager.mjs.map +1 -1
- package/dist/network/ThrottlingUtils.d.ts +1 -0
- package/dist/network/ThrottlingUtils.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.mjs +2 -1
- package/dist/network/ThrottlingUtils.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts +1 -0
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +7 -7
- package/dist/request/RequestParameterBuilder.mjs.map +1 -1
- package/dist/request/RequestValidator.d.ts.map +1 -1
- package/dist/request/RequestValidator.mjs +4 -6
- package/dist/request/RequestValidator.mjs.map +1 -1
- package/dist/request/ScopeSet.mjs +4 -4
- package/dist/request/ScopeSet.mjs.map +1 -1
- package/dist/response/AuthenticationResult.d.ts +3 -1
- package/dist/response/AuthenticationResult.d.ts.map +1 -1
- package/dist/response/ResponseHandler.d.ts +5 -3
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +58 -39
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +4 -4
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts +2 -2
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs +9 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +3 -3
- package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +23 -3
- package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +1 -0
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +4 -4
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.mjs +10 -12
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +10 -0
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +11 -2
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts +28 -0
- package/dist/utils/FunctionWrappers.d.ts.map +1 -0
- package/dist/utils/FunctionWrappers.mjs +90 -0
- package/dist/utils/FunctionWrappers.mjs.map +1 -0
- package/dist/utils/ProtocolUtils.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.mjs +4 -7
- package/dist/utils/ProtocolUtils.mjs.map +1 -1
- package/dist/utils/StringUtils.d.ts +0 -13
- package/dist/utils/StringUtils.d.ts.map +1 -1
- package/dist/utils/StringUtils.mjs +3 -34
- package/dist/utils/StringUtils.mjs.map +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs.map +1 -1
- package/package.json +6 -4
- package/src/account/AccountInfo.ts +44 -0
- package/src/account/AuthToken.ts +70 -0
- package/src/account/CcsCredential.ts +16 -0
- package/src/account/ClientCredentials.ts +20 -0
- package/src/account/ClientInfo.ts +64 -0
- package/src/account/TokenClaims.ts +70 -0
- package/src/authority/Authority.ts +1225 -0
- package/src/authority/AuthorityFactory.ts +106 -0
- package/src/authority/AuthorityMetadata.ts +953 -0
- package/src/authority/AuthorityOptions.ts +40 -0
- package/src/authority/AuthorityType.ts +15 -0
- package/src/authority/AzureRegion.ts +7 -0
- package/src/authority/AzureRegionConfiguration.ts +16 -0
- package/src/authority/CloudDiscoveryMetadata.ts +10 -0
- package/src/authority/CloudInstanceDiscoveryErrorResponse.ts +26 -0
- package/src/authority/CloudInstanceDiscoveryResponse.ts +21 -0
- package/src/authority/ImdsOptions.ts +10 -0
- package/src/authority/OIDCOptions.ts +14 -0
- package/src/authority/OpenIdConfigResponse.ts +24 -0
- package/src/authority/ProtocolMode.ts +13 -0
- package/src/authority/RegionDiscovery.ts +193 -0
- package/src/authority/RegionDiscoveryMetadata.ts +15 -0
- package/src/broker/nativeBroker/INativeBrokerPlugin.ts +29 -0
- package/src/cache/CacheManager.ts +1619 -0
- package/src/cache/entities/AccessTokenEntity.ts +162 -0
- package/src/cache/entities/AccountEntity.ts +309 -0
- package/src/cache/entities/AppMetadataEntity.ts +91 -0
- package/src/cache/entities/AuthorityMetadataEntity.ts +112 -0
- package/src/cache/entities/CacheRecord.ts +33 -0
- package/src/cache/entities/CredentialEntity.ts +215 -0
- package/src/cache/entities/IdTokenEntity.ts +74 -0
- package/src/cache/entities/RefreshTokenEntity.ts +78 -0
- package/src/cache/entities/ServerTelemetryEntity.ts +38 -0
- package/src/cache/entities/ThrottlingEntity.ts +36 -0
- package/src/cache/interface/ICacheManager.ts +218 -0
- package/src/cache/interface/ICachePlugin.ts +11 -0
- package/src/cache/interface/ISerializableTokenCache.ts +9 -0
- package/src/cache/persistence/TokenCacheContext.ts +39 -0
- package/src/cache/utils/CacheTypes.ts +93 -0
- package/src/client/AuthorizationCodeClient.ts +714 -0
- package/src/client/BaseClient.ts +205 -0
- package/src/client/RefreshTokenClient.ts +442 -0
- package/src/client/SilentFlowClient.ts +186 -0
- package/src/config/AppTokenProvider.ts +47 -0
- package/src/config/ClientConfiguration.ts +287 -0
- package/src/crypto/ICrypto.ts +127 -0
- package/src/crypto/IGuidGenerator.ts +9 -0
- package/src/crypto/JoseHeader.ts +55 -0
- package/src/crypto/PopTokenGenerator.ts +155 -0
- package/src/crypto/SignedHttpRequest.ts +16 -0
- package/src/error/AuthError.ts +85 -0
- package/src/error/ClientAuthError.ts +738 -0
- package/src/error/ClientConfigurationError.ts +396 -0
- package/src/error/InteractionRequiredAuthError.ts +134 -0
- package/src/error/JoseHeaderError.ts +52 -0
- package/src/error/ServerError.ts +18 -0
- package/src/index.ts +215 -0
- package/src/logger/Logger.ts +272 -0
- package/src/network/INetworkModule.ts +57 -0
- package/src/network/NetworkManager.ts +76 -0
- package/src/network/RequestThumbprint.ts +22 -0
- package/src/network/ThrottlingUtils.ts +156 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthenticationHeaderParser.ts +89 -0
- package/src/request/BaseAuthRequest.ts +46 -0
- package/src/request/CommonAuthorizationCodeRequest.ts +33 -0
- package/src/request/CommonAuthorizationUrlRequest.ts +56 -0
- package/src/request/CommonClientCredentialRequest.ts +23 -0
- package/src/request/CommonDeviceCodeRequest.ts +31 -0
- package/src/request/CommonEndSessionRequest.ts +27 -0
- package/src/request/CommonOnBehalfOfRequest.ts +19 -0
- package/src/request/CommonRefreshTokenRequest.ts +25 -0
- package/src/request/CommonSilentFlowRequest.ts +24 -0
- package/src/request/CommonUsernamePasswordRequest.ts +23 -0
- package/src/request/NativeRequest.ts +25 -0
- package/src/request/NativeSignOutRequest.ts +10 -0
- package/src/request/RequestParameterBuilder.ts +606 -0
- package/src/request/RequestValidator.ts +103 -0
- package/src/request/ScopeSet.ts +230 -0
- package/src/request/StoreInCache.ts +16 -0
- package/src/response/AuthenticationResult.ts +47 -0
- package/src/response/AuthorizationCodePayload.ts +18 -0
- package/src/response/DeviceCodeResponse.ts +31 -0
- package/src/response/ExternalTokenResponse.ts +24 -0
- package/src/response/IMDSBadResponse.ts +9 -0
- package/src/response/ResponseHandler.ts +614 -0
- package/src/response/ServerAuthorizationCodeResponse.ts +33 -0
- package/src/response/ServerAuthorizationTokenResponse.ts +54 -0
- package/src/telemetry/performance/IPerformanceClient.ts +71 -0
- package/src/telemetry/performance/IPerformanceMeasurement.ts +10 -0
- package/src/telemetry/performance/PerformanceClient.ts +635 -0
- package/src/telemetry/performance/PerformanceEvent.ts +542 -0
- package/src/telemetry/performance/StubPerformanceClient.ts +101 -0
- package/src/telemetry/server/ServerTelemetryManager.ts +274 -0
- package/src/telemetry/server/ServerTelemetryRequest.ts +13 -0
- package/src/url/IUri.ts +17 -0
- package/src/url/UrlString.ts +363 -0
- package/src/utils/Constants.ts +436 -0
- package/src/utils/FunctionWrappers.ts +105 -0
- package/src/utils/MsalTypes.ts +9 -0
- package/src/utils/ProtocolUtils.ts +124 -0
- package/src/utils/StringUtils.ts +106 -0
- package/src/utils/TimeUtils.ts +51 -0
- package/dist/account/DecodedAuthToken.d.ts +0 -9
- package/dist/account/DecodedAuthToken.d.ts.map +0 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BaseClient } from "./BaseClient";
|
|
7
|
+
import { ClientConfiguration } from "../config/ClientConfiguration";
|
|
8
|
+
import { CommonSilentFlowRequest } from "../request/CommonSilentFlowRequest";
|
|
9
|
+
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
10
|
+
import { TimeUtils } from "../utils/TimeUtils";
|
|
11
|
+
import { RefreshTokenClient } from "./RefreshTokenClient";
|
|
12
|
+
import {
|
|
13
|
+
ClientAuthError,
|
|
14
|
+
ClientAuthErrorMessage,
|
|
15
|
+
} from "../error/ClientAuthError";
|
|
16
|
+
import { ClientConfigurationError } from "../error/ClientConfigurationError";
|
|
17
|
+
import { ResponseHandler } from "../response/ResponseHandler";
|
|
18
|
+
import { CacheRecord } from "../cache/entities/CacheRecord";
|
|
19
|
+
import { CacheOutcome } from "../utils/Constants";
|
|
20
|
+
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
21
|
+
import { StringUtils } from "../utils/StringUtils";
|
|
22
|
+
import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
|
|
23
|
+
import { TokenClaims } from "../account/TokenClaims";
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export class SilentFlowClient extends BaseClient {
|
|
27
|
+
constructor(
|
|
28
|
+
configuration: ClientConfiguration,
|
|
29
|
+
performanceClient?: IPerformanceClient
|
|
30
|
+
) {
|
|
31
|
+
super(configuration, performanceClient);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves a token from cache if it is still valid, or uses the cached refresh token to renew
|
|
36
|
+
* the given token and returns the renewed token
|
|
37
|
+
* @param request
|
|
38
|
+
*/
|
|
39
|
+
async acquireToken(
|
|
40
|
+
request: CommonSilentFlowRequest
|
|
41
|
+
): Promise<AuthenticationResult> {
|
|
42
|
+
try {
|
|
43
|
+
return await this.acquireCachedToken(request);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (
|
|
46
|
+
e instanceof ClientAuthError &&
|
|
47
|
+
e.errorCode === ClientAuthErrorMessage.tokenRefreshRequired.code
|
|
48
|
+
) {
|
|
49
|
+
const refreshTokenClient = new RefreshTokenClient(
|
|
50
|
+
this.config,
|
|
51
|
+
this.performanceClient
|
|
52
|
+
);
|
|
53
|
+
return refreshTokenClient.acquireTokenByRefreshToken(request);
|
|
54
|
+
} else {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves token from cache or throws an error if it must be refreshed.
|
|
62
|
+
* @param request
|
|
63
|
+
*/
|
|
64
|
+
async acquireCachedToken(
|
|
65
|
+
request: CommonSilentFlowRequest
|
|
66
|
+
): Promise<AuthenticationResult> {
|
|
67
|
+
// Cannot renew token if no request object is given.
|
|
68
|
+
if (!request) {
|
|
69
|
+
throw ClientConfigurationError.createEmptyTokenRequestError();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (request.forceRefresh) {
|
|
73
|
+
// Must refresh due to present force_refresh flag.
|
|
74
|
+
this.serverTelemetryManager?.setCacheOutcome(
|
|
75
|
+
CacheOutcome.FORCE_REFRESH
|
|
76
|
+
);
|
|
77
|
+
this.logger.info(
|
|
78
|
+
"SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true."
|
|
79
|
+
);
|
|
80
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
81
|
+
} else if (
|
|
82
|
+
!this.config.cacheOptions.claimsBasedCachingEnabled &&
|
|
83
|
+
!StringUtils.isEmptyObj(request.claims)
|
|
84
|
+
) {
|
|
85
|
+
// Must refresh due to request parameters.
|
|
86
|
+
this.logger.info(
|
|
87
|
+
"SilentFlowClient:acquireCachedToken - Skipping cache because claims-based caching is disabled and claims were requested."
|
|
88
|
+
);
|
|
89
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
93
|
+
if (!request.account) {
|
|
94
|
+
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const environment =
|
|
98
|
+
request.authority || this.authority.getPreferredCache();
|
|
99
|
+
|
|
100
|
+
const cacheRecord = this.cacheManager.readCacheRecord(
|
|
101
|
+
request.account,
|
|
102
|
+
request,
|
|
103
|
+
environment
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (!cacheRecord.accessToken) {
|
|
107
|
+
// Must refresh due to non-existent access_token.
|
|
108
|
+
this.serverTelemetryManager?.setCacheOutcome(
|
|
109
|
+
CacheOutcome.NO_CACHED_ACCESS_TOKEN
|
|
110
|
+
);
|
|
111
|
+
this.logger.info(
|
|
112
|
+
"SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties."
|
|
113
|
+
);
|
|
114
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
115
|
+
} else if (
|
|
116
|
+
TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
|
|
117
|
+
TimeUtils.isTokenExpired(
|
|
118
|
+
cacheRecord.accessToken.expiresOn,
|
|
119
|
+
this.config.systemOptions.tokenRenewalOffsetSeconds
|
|
120
|
+
)
|
|
121
|
+
) {
|
|
122
|
+
// Must refresh due to expired access_token.
|
|
123
|
+
this.serverTelemetryManager?.setCacheOutcome(
|
|
124
|
+
CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED
|
|
125
|
+
);
|
|
126
|
+
this.logger.info(
|
|
127
|
+
`SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`
|
|
128
|
+
);
|
|
129
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
130
|
+
} else if (
|
|
131
|
+
cacheRecord.accessToken.refreshOn &&
|
|
132
|
+
TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)
|
|
133
|
+
) {
|
|
134
|
+
// Must refresh due to the refresh_in value.
|
|
135
|
+
this.serverTelemetryManager?.setCacheOutcome(
|
|
136
|
+
CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN
|
|
137
|
+
);
|
|
138
|
+
this.logger.info(
|
|
139
|
+
"SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'."
|
|
140
|
+
);
|
|
141
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (this.config.serverTelemetryManager) {
|
|
145
|
+
this.config.serverTelemetryManager.incrementCacheHits();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return await this.generateResultFromCacheRecord(cacheRecord, request);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Helper function to build response object from the CacheRecord
|
|
153
|
+
* @param cacheRecord
|
|
154
|
+
*/
|
|
155
|
+
private async generateResultFromCacheRecord(
|
|
156
|
+
cacheRecord: CacheRecord,
|
|
157
|
+
request: CommonSilentFlowRequest
|
|
158
|
+
): Promise<AuthenticationResult> {
|
|
159
|
+
let idTokenClaims: TokenClaims | undefined;
|
|
160
|
+
if (cacheRecord.idToken) {
|
|
161
|
+
idTokenClaims = extractTokenClaims(
|
|
162
|
+
cacheRecord.idToken.secret,
|
|
163
|
+
this.config.cryptoInterface.base64Decode
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// token max_age check
|
|
168
|
+
if (request.maxAge || request.maxAge === 0) {
|
|
169
|
+
const authTime = idTokenClaims?.auth_time;
|
|
170
|
+
if (!authTime) {
|
|
171
|
+
throw ClientAuthError.createAuthTimeNotFoundError();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
checkMaxAge(authTime, request.maxAge);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return await ResponseHandler.generateAuthenticationResult(
|
|
178
|
+
this.cryptoUtils,
|
|
179
|
+
this.authority,
|
|
180
|
+
cacheRecord,
|
|
181
|
+
true,
|
|
182
|
+
request,
|
|
183
|
+
idTokenClaims
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Extensibility interface, which allows the app developer to return a token, based on the passed-in parameters, instead of fetching tokens from
|
|
8
|
+
* the Identity Provider (AAD).
|
|
9
|
+
* Developers need to construct and return an AppTokenProviderResult object back to MSAL. MSAL will cache the token response
|
|
10
|
+
* in the same way it would do if the result were comming from AAD.
|
|
11
|
+
* This extensibility point is only defined for the client_credential flow, i.e. acquireTokenByClientCredential and
|
|
12
|
+
* meant for Azure SDK to enhance Managed Identity support.
|
|
13
|
+
*/
|
|
14
|
+
export interface IAppTokenProvider {
|
|
15
|
+
(
|
|
16
|
+
appTokenProviderParameters: AppTokenProviderParameters
|
|
17
|
+
): Promise<AppTokenProviderResult>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Input object for the IAppTokenProvider extensiblity. MSAL will create this object, which can be used
|
|
22
|
+
* to help create an AppTokenProviderResult.
|
|
23
|
+
*
|
|
24
|
+
* - correlationId - the correlation Id associated with the request
|
|
25
|
+
* - tenantId - the tenant Id for which the token must be provided
|
|
26
|
+
* - scopes - the scopes for which the token must be provided
|
|
27
|
+
* - claims - any extra claims that the token must satisfy
|
|
28
|
+
*/
|
|
29
|
+
export type AppTokenProviderParameters = {
|
|
30
|
+
readonly correlationId?: string;
|
|
31
|
+
readonly tenantId: string;
|
|
32
|
+
readonly scopes: Array<string>;
|
|
33
|
+
readonly claims?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Output object for IAppTokenProvider extensiblity.
|
|
38
|
+
*
|
|
39
|
+
* - accessToken - the actual access token, typically in JWT format, that satisfies the request data AppTokenProviderParameters
|
|
40
|
+
* - expiresInSeconds - how long the tokens has before expiry, in seconds. Similar to the "expires_in" field in an AAD token response.
|
|
41
|
+
* - refreshInSeconds - how long the token has before it should be proactively refreshed. Similar to the "refresh_in" field in an AAD token response.
|
|
42
|
+
*/
|
|
43
|
+
export type AppTokenProviderResult = {
|
|
44
|
+
accessToken: string;
|
|
45
|
+
expiresInSeconds: number;
|
|
46
|
+
refreshInSeconds?: number;
|
|
47
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { INetworkModule } from "../network/INetworkModule";
|
|
7
|
+
import { DEFAULT_CRYPTO_IMPLEMENTATION, ICrypto } from "../crypto/ICrypto";
|
|
8
|
+
import { AuthError } from "../error/AuthError";
|
|
9
|
+
import { ILoggerCallback, Logger, LogLevel } from "../logger/Logger";
|
|
10
|
+
import { Constants } from "../utils/Constants";
|
|
11
|
+
import { version } from "../packageMetadata";
|
|
12
|
+
import { Authority } from "../authority/Authority";
|
|
13
|
+
import { AzureCloudInstance } from "../authority/AuthorityOptions";
|
|
14
|
+
import { CacheManager, DefaultStorageClass } from "../cache/CacheManager";
|
|
15
|
+
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager";
|
|
16
|
+
import { ICachePlugin } from "../cache/interface/ICachePlugin";
|
|
17
|
+
import { ISerializableTokenCache } from "../cache/interface/ISerializableTokenCache";
|
|
18
|
+
import { ClientCredentials } from "../account/ClientCredentials";
|
|
19
|
+
import { ProtocolMode } from "../authority/ProtocolMode";
|
|
20
|
+
|
|
21
|
+
// Token renewal offset default in seconds
|
|
22
|
+
const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Use the configuration object to configure MSAL Modules and initialize the base interfaces for MSAL.
|
|
26
|
+
*
|
|
27
|
+
* This object allows you to configure important elements of MSAL functionality:
|
|
28
|
+
* - authOptions - Authentication for application
|
|
29
|
+
* - cryptoInterface - Implementation of crypto functions
|
|
30
|
+
* - libraryInfo - Library metadata
|
|
31
|
+
* - telemetry - Telemetry options and data
|
|
32
|
+
* - loggerOptions - Logging for application
|
|
33
|
+
* - networkInterface - Network implementation
|
|
34
|
+
* - storageInterface - Storage implementation
|
|
35
|
+
* - systemOptions - Additional library options
|
|
36
|
+
* - clientCredentials - Credentials options for confidential clients
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export type ClientConfiguration = {
|
|
40
|
+
authOptions: AuthOptions;
|
|
41
|
+
systemOptions?: SystemOptions;
|
|
42
|
+
loggerOptions?: LoggerOptions;
|
|
43
|
+
cacheOptions?: CacheOptions;
|
|
44
|
+
storageInterface?: CacheManager;
|
|
45
|
+
networkInterface?: INetworkModule;
|
|
46
|
+
cryptoInterface?: ICrypto;
|
|
47
|
+
clientCredentials?: ClientCredentials;
|
|
48
|
+
libraryInfo?: LibraryInfo;
|
|
49
|
+
telemetry?: TelemetryOptions;
|
|
50
|
+
serverTelemetryManager?: ServerTelemetryManager | null;
|
|
51
|
+
persistencePlugin?: ICachePlugin | null;
|
|
52
|
+
serializableCache?: ISerializableTokenCache | null;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type CommonClientConfiguration = {
|
|
56
|
+
authOptions: Required<AuthOptions>;
|
|
57
|
+
systemOptions: Required<SystemOptions>;
|
|
58
|
+
loggerOptions: Required<LoggerOptions>;
|
|
59
|
+
cacheOptions: Required<CacheOptions>;
|
|
60
|
+
storageInterface: CacheManager;
|
|
61
|
+
networkInterface: INetworkModule;
|
|
62
|
+
cryptoInterface: Required<ICrypto>;
|
|
63
|
+
libraryInfo: LibraryInfo;
|
|
64
|
+
telemetry: Required<TelemetryOptions>;
|
|
65
|
+
serverTelemetryManager: ServerTelemetryManager | null;
|
|
66
|
+
clientCredentials: ClientCredentials;
|
|
67
|
+
persistencePlugin: ICachePlugin | null;
|
|
68
|
+
serializableCache: ISerializableTokenCache | null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Use this to configure the auth options in the ClientConfiguration object
|
|
73
|
+
*
|
|
74
|
+
* - clientId - Client ID of your app registered with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview in Microsoft Identity Platform
|
|
75
|
+
* - authority - You can configure a specific authority, defaults to " " or "https://login.microsoftonline.com/common"
|
|
76
|
+
* - knownAuthorities - An array of URIs that are known to be valid. Used in B2C scenarios.
|
|
77
|
+
* - cloudDiscoveryMetadata - A string containing the cloud discovery response. Used in AAD scenarios.
|
|
78
|
+
* - clientCapabilities - Array of capabilities which will be added to the claims.access_token.xms_cc request property on every network request.
|
|
79
|
+
* - protocolMode - Enum that represents the protocol that msal follows. Used for configuring proper endpoints.
|
|
80
|
+
* - skipAuthorityMetadataCache - A flag to choose whether to use or not use the local metadata cache during authority initialization. Defaults to false.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export type AuthOptions = {
|
|
84
|
+
clientId: string;
|
|
85
|
+
authority: Authority;
|
|
86
|
+
clientCapabilities?: Array<string>;
|
|
87
|
+
azureCloudOptions?: AzureCloudOptions;
|
|
88
|
+
skipAuthorityMetadataCache?: boolean;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Use this to configure token renewal info in the Configuration object
|
|
93
|
+
*
|
|
94
|
+
* - tokenRenewalOffsetSeconds - Sets the window of offset needed to renew the token before expiry
|
|
95
|
+
*/
|
|
96
|
+
export type SystemOptions = {
|
|
97
|
+
tokenRenewalOffsetSeconds?: number;
|
|
98
|
+
preventCorsPreflight?: boolean;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Use this to configure the logging that MSAL does, by configuring logger options in the Configuration object
|
|
103
|
+
*
|
|
104
|
+
* - loggerCallback - Callback for logger
|
|
105
|
+
* - piiLoggingEnabled - Sets whether pii logging is enabled
|
|
106
|
+
* - logLevel - Sets the level at which logging happens
|
|
107
|
+
* - correlationId - Sets the correlationId printed by the logger
|
|
108
|
+
*/
|
|
109
|
+
export type LoggerOptions = {
|
|
110
|
+
loggerCallback?: ILoggerCallback;
|
|
111
|
+
piiLoggingEnabled?: boolean;
|
|
112
|
+
logLevel?: LogLevel;
|
|
113
|
+
correlationId?: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Use this to configure credential cache preferences in the ClientConfiguration object
|
|
118
|
+
*
|
|
119
|
+
* - claimsBasedCachingEnabled - Sets whether tokens should be cached based on the claims hash. Default is false.
|
|
120
|
+
*/
|
|
121
|
+
export type CacheOptions = {
|
|
122
|
+
claimsBasedCachingEnabled?: boolean;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Library-specific options
|
|
127
|
+
*/
|
|
128
|
+
export type LibraryInfo = {
|
|
129
|
+
sku: string;
|
|
130
|
+
version: string;
|
|
131
|
+
cpu: string;
|
|
132
|
+
os: string;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* AzureCloudInstance specific options
|
|
137
|
+
*
|
|
138
|
+
* - azureCloudInstance - string enum providing short notation for soverign and public cloud authorities
|
|
139
|
+
* - tenant - provision to provide the tenant info
|
|
140
|
+
*/
|
|
141
|
+
export type AzureCloudOptions = {
|
|
142
|
+
azureCloudInstance: AzureCloudInstance;
|
|
143
|
+
tenant?: string;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export type TelemetryOptions = {
|
|
147
|
+
application: ApplicationTelemetry;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Telemetry information sent on request
|
|
152
|
+
* - appName: Unique string name of an application
|
|
153
|
+
* - appVersion: Version of the application using MSAL
|
|
154
|
+
*/
|
|
155
|
+
export type ApplicationTelemetry = {
|
|
156
|
+
appName: string;
|
|
157
|
+
appVersion: string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const DEFAULT_SYSTEM_OPTIONS: Required<SystemOptions> = {
|
|
161
|
+
tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
|
|
162
|
+
preventCorsPreflight: false,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const DEFAULT_LOGGER_IMPLEMENTATION: Required<LoggerOptions> = {
|
|
166
|
+
loggerCallback: () => {
|
|
167
|
+
// allow users to not set loggerCallback
|
|
168
|
+
},
|
|
169
|
+
piiLoggingEnabled: false,
|
|
170
|
+
logLevel: LogLevel.Info,
|
|
171
|
+
correlationId: Constants.EMPTY_STRING,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const DEFAULT_CACHE_OPTIONS: Required<CacheOptions> = {
|
|
175
|
+
claimsBasedCachingEnabled: false,
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const DEFAULT_NETWORK_IMPLEMENTATION: INetworkModule = {
|
|
179
|
+
async sendGetRequestAsync<T>(): Promise<T> {
|
|
180
|
+
const notImplErr =
|
|
181
|
+
"Network interface - sendGetRequestAsync() has not been implemented";
|
|
182
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
183
|
+
},
|
|
184
|
+
async sendPostRequestAsync<T>(): Promise<T> {
|
|
185
|
+
const notImplErr =
|
|
186
|
+
"Network interface - sendPostRequestAsync() has not been implemented";
|
|
187
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const DEFAULT_LIBRARY_INFO: LibraryInfo = {
|
|
192
|
+
sku: Constants.SKU,
|
|
193
|
+
version: version,
|
|
194
|
+
cpu: Constants.EMPTY_STRING,
|
|
195
|
+
os: Constants.EMPTY_STRING,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const DEFAULT_CLIENT_CREDENTIALS: ClientCredentials = {
|
|
199
|
+
clientSecret: Constants.EMPTY_STRING,
|
|
200
|
+
clientAssertion: undefined,
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const DEFAULT_AZURE_CLOUD_OPTIONS: AzureCloudOptions = {
|
|
204
|
+
azureCloudInstance: AzureCloudInstance.None,
|
|
205
|
+
tenant: `${Constants.DEFAULT_COMMON_TENANT}`,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const DEFAULT_TELEMETRY_OPTIONS: Required<TelemetryOptions> = {
|
|
209
|
+
application: {
|
|
210
|
+
appName: "",
|
|
211
|
+
appVersion: "",
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Function that sets the default options when not explicitly configured from app developer
|
|
217
|
+
*
|
|
218
|
+
* @param Configuration
|
|
219
|
+
*
|
|
220
|
+
* @returns Configuration
|
|
221
|
+
*/
|
|
222
|
+
export function buildClientConfiguration({
|
|
223
|
+
authOptions: userAuthOptions,
|
|
224
|
+
systemOptions: userSystemOptions,
|
|
225
|
+
loggerOptions: userLoggerOption,
|
|
226
|
+
cacheOptions: userCacheOptions,
|
|
227
|
+
storageInterface: storageImplementation,
|
|
228
|
+
networkInterface: networkImplementation,
|
|
229
|
+
cryptoInterface: cryptoImplementation,
|
|
230
|
+
clientCredentials: clientCredentials,
|
|
231
|
+
libraryInfo: libraryInfo,
|
|
232
|
+
telemetry: telemetry,
|
|
233
|
+
serverTelemetryManager: serverTelemetryManager,
|
|
234
|
+
persistencePlugin: persistencePlugin,
|
|
235
|
+
serializableCache: serializableCache,
|
|
236
|
+
}: ClientConfiguration): CommonClientConfiguration {
|
|
237
|
+
const loggerOptions = {
|
|
238
|
+
...DEFAULT_LOGGER_IMPLEMENTATION,
|
|
239
|
+
...userLoggerOption,
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
authOptions: buildAuthOptions(userAuthOptions),
|
|
244
|
+
systemOptions: { ...DEFAULT_SYSTEM_OPTIONS, ...userSystemOptions },
|
|
245
|
+
loggerOptions: loggerOptions,
|
|
246
|
+
cacheOptions: { ...DEFAULT_CACHE_OPTIONS, ...userCacheOptions },
|
|
247
|
+
storageInterface:
|
|
248
|
+
storageImplementation ||
|
|
249
|
+
new DefaultStorageClass(
|
|
250
|
+
userAuthOptions.clientId,
|
|
251
|
+
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
252
|
+
new Logger(loggerOptions)
|
|
253
|
+
),
|
|
254
|
+
networkInterface:
|
|
255
|
+
networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,
|
|
256
|
+
cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
257
|
+
clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
|
|
258
|
+
libraryInfo: { ...DEFAULT_LIBRARY_INFO, ...libraryInfo },
|
|
259
|
+
telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...telemetry },
|
|
260
|
+
serverTelemetryManager: serverTelemetryManager || null,
|
|
261
|
+
persistencePlugin: persistencePlugin || null,
|
|
262
|
+
serializableCache: serializableCache || null,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Construct authoptions from the client and platform passed values
|
|
268
|
+
* @param authOptions
|
|
269
|
+
*/
|
|
270
|
+
function buildAuthOptions(authOptions: AuthOptions): Required<AuthOptions> {
|
|
271
|
+
return {
|
|
272
|
+
clientCapabilities: [],
|
|
273
|
+
azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS,
|
|
274
|
+
skipAuthorityMetadataCache: false,
|
|
275
|
+
...authOptions,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Returns true if config has protocolMode set to ProtocolMode.OIDC, false otherwise
|
|
281
|
+
* @param ClientConfiguration
|
|
282
|
+
*/
|
|
283
|
+
export function isOidcProtocolMode(config: ClientConfiguration): boolean {
|
|
284
|
+
return (
|
|
285
|
+
config.authOptions.authority.options.protocolMode === ProtocolMode.OIDC
|
|
286
|
+
);
|
|
287
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthError } from "../error/AuthError";
|
|
7
|
+
import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
8
|
+
import { SignedHttpRequest } from "./SignedHttpRequest";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The PkceCodes type describes the structure
|
|
12
|
+
* of objects that contain PKCE code
|
|
13
|
+
* challenge and verifier pairs
|
|
14
|
+
*/
|
|
15
|
+
export type PkceCodes = {
|
|
16
|
+
verifier: string;
|
|
17
|
+
challenge: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type SignedHttpRequestParameters = Pick<
|
|
21
|
+
BaseAuthRequest,
|
|
22
|
+
"resourceRequestMethod" | "resourceRequestUri" | "shrClaims" | "shrNonce"
|
|
23
|
+
> & {
|
|
24
|
+
correlationId?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Interface for crypto functions used by library
|
|
29
|
+
*/
|
|
30
|
+
export interface ICrypto {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a guid randomly.
|
|
33
|
+
*/
|
|
34
|
+
createNewGuid(): string;
|
|
35
|
+
/**
|
|
36
|
+
* base64 Encode string
|
|
37
|
+
* @param input
|
|
38
|
+
*/
|
|
39
|
+
base64Encode(input: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* base64 decode string
|
|
42
|
+
* @param input
|
|
43
|
+
*/
|
|
44
|
+
base64Decode(input: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Generate PKCE codes for OAuth. See RFC here: https://tools.ietf.org/html/rfc7636
|
|
47
|
+
*/
|
|
48
|
+
generatePkceCodes(): Promise<PkceCodes>;
|
|
49
|
+
/**
|
|
50
|
+
* Generates an JWK RSA S256 Thumbprint
|
|
51
|
+
* @param request
|
|
52
|
+
*/
|
|
53
|
+
getPublicKeyThumbprint(
|
|
54
|
+
request: SignedHttpRequestParameters
|
|
55
|
+
): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Removes cryptographic keypair from key store matching the keyId passed in
|
|
58
|
+
* @param kid
|
|
59
|
+
*/
|
|
60
|
+
removeTokenBindingKey(kid: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Removes all cryptographic keys from IndexedDB storage
|
|
63
|
+
*/
|
|
64
|
+
clearKeystore(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a signed proof-of-possession token with a given acces token that contains a cnf claim with the required kid.
|
|
67
|
+
* @param accessToken
|
|
68
|
+
*/
|
|
69
|
+
signJwt(
|
|
70
|
+
payload: SignedHttpRequest,
|
|
71
|
+
kid: string,
|
|
72
|
+
correlationId?: string
|
|
73
|
+
): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the SHA-256 hash of an input string
|
|
76
|
+
* @param plainText
|
|
77
|
+
*/
|
|
78
|
+
hashString(plainText: string): Promise<string>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const DEFAULT_CRYPTO_IMPLEMENTATION: ICrypto = {
|
|
82
|
+
createNewGuid: (): string => {
|
|
83
|
+
const notImplErr =
|
|
84
|
+
"Crypto interface - createNewGuid() has not been implemented";
|
|
85
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
86
|
+
},
|
|
87
|
+
base64Decode: (): string => {
|
|
88
|
+
const notImplErr =
|
|
89
|
+
"Crypto interface - base64Decode() has not been implemented";
|
|
90
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
91
|
+
},
|
|
92
|
+
base64Encode: (): string => {
|
|
93
|
+
const notImplErr =
|
|
94
|
+
"Crypto interface - base64Encode() has not been implemented";
|
|
95
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
96
|
+
},
|
|
97
|
+
async generatePkceCodes(): Promise<PkceCodes> {
|
|
98
|
+
const notImplErr =
|
|
99
|
+
"Crypto interface - generatePkceCodes() has not been implemented";
|
|
100
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
101
|
+
},
|
|
102
|
+
async getPublicKeyThumbprint(): Promise<string> {
|
|
103
|
+
const notImplErr =
|
|
104
|
+
"Crypto interface - getPublicKeyThumbprint() has not been implemented";
|
|
105
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
106
|
+
},
|
|
107
|
+
async removeTokenBindingKey(): Promise<boolean> {
|
|
108
|
+
const notImplErr =
|
|
109
|
+
"Crypto interface - removeTokenBindingKey() has not been implemented";
|
|
110
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
111
|
+
},
|
|
112
|
+
async clearKeystore(): Promise<boolean> {
|
|
113
|
+
const notImplErr =
|
|
114
|
+
"Crypto interface - clearKeystore() has not been implemented";
|
|
115
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
116
|
+
},
|
|
117
|
+
async signJwt(): Promise<string> {
|
|
118
|
+
const notImplErr =
|
|
119
|
+
"Crypto interface - signJwt() has not been implemented";
|
|
120
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
121
|
+
},
|
|
122
|
+
async hashString(): Promise<string> {
|
|
123
|
+
const notImplErr =
|
|
124
|
+
"Crypto interface - hashString() has not been implemented";
|
|
125
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
126
|
+
},
|
|
127
|
+
};
|