@azure/msal-common 14.0.3 → 14.1.0-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/dist/account/AccountInfo.d.ts +32 -32
- package/dist/account/AuthToken.d.ts +17 -17
- package/dist/account/AuthToken.d.ts.map +1 -1
- package/dist/account/AuthToken.mjs +60 -59
- package/dist/account/AuthToken.mjs.map +1 -1
- package/dist/account/CcsCredential.d.ts +9 -9
- package/dist/account/CcsCredential.mjs +8 -8
- package/dist/account/ClientCredentials.d.ts +14 -14
- package/dist/account/ClientInfo.d.ts +19 -19
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.mjs +39 -38
- package/dist/account/ClientInfo.mjs.map +1 -1
- package/dist/account/TokenClaims.d.ts +65 -65
- package/dist/authority/Authority.d.ts +235 -235
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +743 -765
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts +31 -31
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +52 -50
- package/dist/authority/AuthorityFactory.mjs.map +1 -1
- package/dist/authority/AuthorityMetadata.d.ts +623 -623
- package/dist/authority/AuthorityMetadata.mjs +884 -884
- package/dist/authority/AuthorityOptions.d.ts +21 -21
- package/dist/authority/AuthorityOptions.mjs +18 -18
- package/dist/authority/AuthorityType.d.ts +10 -10
- package/dist/authority/AuthorityType.mjs +13 -13
- package/dist/authority/AzureRegion.d.ts +1 -1
- package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
- package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +8 -8
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +8 -8
- package/dist/authority/ImdsOptions.d.ts +5 -5
- package/dist/authority/OIDCOptions.d.ts +8 -8
- package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
- package/dist/authority/OpenIdConfigResponse.mjs +10 -10
- package/dist/authority/ProtocolMode.d.ts +8 -8
- package/dist/authority/ProtocolMode.mjs +11 -11
- package/dist/authority/RegionDiscovery.d.ts +32 -30
- package/dist/authority/RegionDiscovery.d.ts.map +1 -1
- package/dist/authority/RegionDiscovery.mjs +107 -108
- package/dist/authority/RegionDiscovery.mjs.map +1 -1
- package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
- package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
- package/dist/cache/CacheManager.d.ts +446 -446
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +1000 -1024
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts +56 -56
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.mjs +111 -110
- package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts +101 -101
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +222 -221
- package/dist/cache/entities/AccountEntity.mjs.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
- package/dist/cache/entities/AppMetadataEntity.mjs +66 -66
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -48
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +78 -78
- package/dist/cache/entities/CacheRecord.d.ts +14 -14
- package/dist/cache/entities/CacheRecord.mjs +14 -14
- package/dist/cache/entities/CredentialEntity.d.ts +88 -88
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/CredentialEntity.mjs +138 -137
- package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
- package/dist/cache/entities/IdTokenEntity.d.ts +34 -34
- package/dist/cache/entities/IdTokenEntity.mjs +56 -56
- package/dist/cache/entities/RefreshTokenEntity.d.ts +36 -36
- package/dist/cache/entities/RefreshTokenEntity.mjs +59 -59
- package/dist/cache/entities/ServerTelemetryEntity.d.ts +12 -12
- package/dist/cache/entities/ServerTelemetryEntity.mjs +27 -27
- package/dist/cache/entities/ThrottlingEntity.d.ts +13 -13
- package/dist/cache/entities/ThrottlingEntity.mjs +23 -23
- package/dist/cache/interface/ICacheManager.d.ts +166 -166
- package/dist/cache/interface/ICachePlugin.d.ts +5 -5
- package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
- package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
- package/dist/cache/persistence/TokenCacheContext.mjs +25 -25
- package/dist/cache/utils/CacheTypes.d.ts +69 -69
- package/dist/client/AuthorizationCodeClient.d.ts +73 -73
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +411 -410
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +51 -51
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.mjs +100 -99
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts +35 -35
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +185 -234
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +26 -25
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +127 -103
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/AppTokenProvider.d.ts +38 -38
- package/dist/config/ClientConfiguration.d.ts +150 -150
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.mjs +99 -100
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/crypto/ICrypto.d.ts +62 -62
- package/dist/crypto/ICrypto.d.ts.map +1 -1
- package/dist/crypto/ICrypto.mjs +35 -43
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/IGuidGenerator.d.ts +4 -4
- package/dist/crypto/JoseHeader.d.ts +22 -22
- package/dist/crypto/JoseHeader.d.ts.map +1 -1
- package/dist/crypto/JoseHeader.mjs +39 -38
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +60 -59
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +83 -83
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts +11 -11
- package/dist/error/AuthError.d.ts +44 -47
- package/dist/error/AuthError.d.ts.map +1 -1
- package/dist/error/AuthError.mjs +50 -52
- package/dist/error/AuthError.mjs.map +1 -1
- package/dist/error/AuthErrorCodes.d.ts +6 -0
- package/dist/error/AuthErrorCodes.d.ts.map +1 -0
- package/dist/error/AuthErrorCodes.mjs +14 -0
- package/dist/error/AuthErrorCodes.mjs.map +1 -0
- package/dist/error/ClientAuthError.d.ts +232 -412
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.mjs +248 -520
- package/dist/error/ClientAuthError.mjs.map +1 -1
- package/dist/error/ClientAuthErrorCodes.d.ts +44 -0
- package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/ClientAuthErrorCodes.mjs +52 -0
- package/dist/error/ClientAuthErrorCodes.mjs.map +1 -0
- package/dist/error/ClientConfigurationError.d.ts +128 -222
- package/dist/error/ClientConfigurationError.d.ts.map +1 -1
- package/dist/error/ClientConfigurationError.mjs +140 -281
- package/dist/error/ClientConfigurationError.mjs.map +1 -1
- package/dist/error/ClientConfigurationErrorCodes.d.ts +23 -0
- package/dist/error/ClientConfigurationErrorCodes.d.ts.map +1 -0
- package/dist/error/ClientConfigurationErrorCodes.mjs +31 -0
- package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -0
- package/dist/error/InteractionRequiredAuthError.d.ts +57 -59
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +80 -79
- package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +6 -0
- package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +16 -0
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -0
- package/dist/error/JoseHeaderError.d.ts +15 -28
- package/dist/error/JoseHeaderError.d.ts.map +1 -1
- package/dist/error/JoseHeaderError.mjs +24 -40
- package/dist/error/JoseHeaderError.mjs.map +1 -1
- package/dist/error/JoseHeaderErrorCodes.d.ts +3 -0
- package/dist/error/JoseHeaderErrorCodes.d.ts.map +1 -0
- package/dist/error/JoseHeaderErrorCodes.mjs +11 -0
- package/dist/error/JoseHeaderErrorCodes.mjs.map +1 -0
- package/dist/error/ServerError.d.ts +7 -7
- package/dist/error/ServerError.mjs +14 -14
- package/dist/index.cjs +8715 -9047
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +96 -96
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +13 -5
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.d.ts +95 -95
- package/dist/logger/Logger.mjs +188 -188
- package/dist/network/INetworkModule.d.ts +29 -29
- package/dist/network/INetworkModule.d.ts.map +1 -1
- package/dist/network/INetworkModule.mjs +14 -15
- package/dist/network/INetworkModule.mjs.map +1 -1
- package/dist/network/NetworkManager.d.ts +33 -33
- package/dist/network/NetworkManager.d.ts.map +1 -1
- package/dist/network/NetworkManager.mjs +36 -35
- package/dist/network/NetworkManager.mjs.map +1 -1
- package/dist/network/RequestThumbprint.d.ts +16 -16
- package/dist/network/ThrottlingUtils.d.ts +42 -42
- package/dist/network/ThrottlingUtils.mjs +95 -95
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +3 -3
- package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
- package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs +58 -57
- package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
- package/dist/request/BaseAuthRequest.d.ts +40 -40
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
- package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
- package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
- package/dist/request/CommonEndSessionRequest.d.ts +21 -21
- package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
- package/dist/request/CommonRefreshTokenRequest.d.ts +19 -19
- package/dist/request/CommonSilentFlowRequest.d.ts +18 -18
- package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
- package/dist/request/NativeRequest.d.ts +19 -19
- package/dist/request/NativeSignOutRequest.d.ts +5 -5
- package/dist/request/RequestParameterBuilder.d.ts +217 -217
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +383 -382
- package/dist/request/RequestParameterBuilder.mjs.map +1 -1
- package/dist/request/RequestValidator.d.ts +33 -33
- package/dist/request/RequestValidator.d.ts.map +1 -1
- package/dist/request/RequestValidator.mjs +83 -82
- package/dist/request/RequestValidator.mjs.map +1 -1
- package/dist/request/ScopeSet.d.ts +88 -88
- package/dist/request/ScopeSet.d.ts.map +1 -1
- package/dist/request/ScopeSet.mjs +201 -199
- package/dist/request/ScopeSet.mjs.map +1 -1
- package/dist/request/StoreInCache.d.ts +8 -8
- package/dist/response/AuthenticationResult.d.ts +41 -41
- package/dist/response/AuthorizationCodePayload.d.ts +13 -13
- package/dist/response/DeviceCodeResponse.d.ts +25 -25
- package/dist/response/ExternalTokenResponse.d.ts +15 -15
- package/dist/response/IMDSBadResponse.d.ts +4 -4
- package/dist/response/ResponseHandler.d.ts +67 -67
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +314 -313
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +46 -46
- package/dist/telemetry/performance/IPerformanceClient.d.ts +51 -51
- package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
- package/dist/telemetry/performance/PerformanceClient.d.ts +191 -191
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +409 -408
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +433 -433
- package/dist/telemetry/performance/PerformanceEvent.mjs +234 -234
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +24 -24
- package/dist/telemetry/performance/StubPerformanceClient.mjs +76 -76
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +66 -66
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +197 -197
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
- package/dist/url/IUri.d.ts +12 -12
- package/dist/url/UrlString.d.ts +83 -83
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.mjs +283 -281
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +366 -363
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +376 -368
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts +27 -27
- package/dist/utils/FunctionWrappers.mjs +85 -85
- package/dist/utils/MsalTypes.d.ts +6 -6
- package/dist/utils/ProtocolUtils.d.ts +42 -42
- package/dist/utils/ProtocolUtils.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.mjs +71 -70
- package/dist/utils/ProtocolUtils.mjs.map +1 -1
- package/dist/utils/StringUtils.d.ts +40 -40
- package/dist/utils/StringUtils.mjs +95 -95
- package/dist/utils/TimeUtils.d.ts +27 -27
- package/dist/utils/TimeUtils.mjs +45 -45
- package/package.json +1 -1
- package/src/account/AuthToken.ts +8 -7
- package/src/account/ClientInfo.ts +9 -6
- package/src/authority/Authority.ts +76 -94
- package/src/authority/AuthorityFactory.ts +21 -9
- package/src/authority/RegionDiscovery.ts +21 -18
- package/src/cache/CacheManager.ts +37 -77
- package/src/cache/entities/AccessTokenEntity.ts +7 -2
- package/src/cache/entities/AccountEntity.ts +7 -2
- package/src/cache/entities/CredentialEntity.ts +7 -2
- package/src/client/AuthorizationCodeClient.ts +32 -10
- package/src/client/BaseClient.ts +7 -4
- package/src/client/RefreshTokenClient.ts +81 -124
- package/src/client/SilentFlowClient.ts +72 -19
- package/src/config/ClientConfiguration.ts +6 -7
- package/src/crypto/ICrypto.ts +13 -28
- package/src/crypto/JoseHeader.ts +6 -3
- package/src/crypto/PopTokenGenerator.ts +10 -5
- package/src/error/AuthError.ts +24 -26
- package/src/error/AuthErrorCodes.ts +10 -0
- package/src/error/ClientAuthError.ts +227 -632
- package/src/error/ClientAuthErrorCodes.ts +51 -0
- package/src/error/ClientConfigurationError.ts +146 -332
- package/src/error/ClientConfigurationErrorCodes.ts +28 -0
- package/src/error/InteractionRequiredAuthError.ts +60 -55
- package/src/error/InteractionRequiredAuthErrorCodes.ts +13 -0
- package/src/error/JoseHeaderError.ts +11 -31
- package/src/error/JoseHeaderErrorCodes.ts +7 -0
- package/src/index.ts +12 -1
- package/src/network/INetworkModule.ts +10 -7
- package/src/network/NetworkManager.ts +5 -5
- package/src/request/AuthenticationHeaderParser.ts +11 -8
- package/src/request/RequestParameterBuilder.ts +10 -3
- package/src/request/RequestValidator.ts +19 -6
- package/src/request/ScopeSet.ts +23 -7
- package/src/response/ResponseHandler.ts +37 -17
- package/src/telemetry/performance/PerformanceClient.ts +2 -1
- package/src/telemetry/server/ServerTelemetryManager.ts +1 -1
- package/src/url/UrlString.ts +26 -16
- package/src/utils/Constants.ts +11 -3
- package/src/utils/ProtocolUtils.ts +8 -12
|
@@ -25,8 +25,14 @@ import { StringUtils } from "../utils/StringUtils";
|
|
|
25
25
|
import { RequestThumbprint } from "../network/RequestThumbprint";
|
|
26
26
|
import { NetworkResponse } from "../network/NetworkManager";
|
|
27
27
|
import { CommonSilentFlowRequest } from "../request/CommonSilentFlowRequest";
|
|
28
|
-
import {
|
|
29
|
-
|
|
28
|
+
import {
|
|
29
|
+
createClientConfigurationError,
|
|
30
|
+
ClientConfigurationErrorCodes,
|
|
31
|
+
} from "../error/ClientConfigurationError";
|
|
32
|
+
import {
|
|
33
|
+
createClientAuthError,
|
|
34
|
+
ClientAuthErrorCodes,
|
|
35
|
+
} from "../error/ClientAuthError";
|
|
30
36
|
import { ServerError } from "../error/ServerError";
|
|
31
37
|
import { TimeUtils } from "../utils/TimeUtils";
|
|
32
38
|
import { UrlString } from "../url/UrlString";
|
|
@@ -34,10 +40,12 @@ import { CcsCredentialType } from "../account/CcsCredential";
|
|
|
34
40
|
import { buildClientInfoFromHomeAccountId } from "../account/ClientInfo";
|
|
35
41
|
import {
|
|
36
42
|
InteractionRequiredAuthError,
|
|
37
|
-
|
|
43
|
+
InteractionRequiredAuthErrorCodes,
|
|
44
|
+
createInteractionRequiredAuthError,
|
|
38
45
|
} from "../error/InteractionRequiredAuthError";
|
|
39
46
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
40
47
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
48
|
+
import { invokeAsync } from "../utils/FunctionWrappers";
|
|
41
49
|
/**
|
|
42
50
|
* OAuth2.0 refresh token client
|
|
43
51
|
* @internal
|
|
@@ -57,23 +65,14 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
57
65
|
request.correlationId
|
|
58
66
|
);
|
|
59
67
|
|
|
60
|
-
const atsMeasurement = this.performanceClient?.startMeasurement(
|
|
61
|
-
PerformanceEvents.RefreshTokenClientAcquireToken,
|
|
62
|
-
request.correlationId
|
|
63
|
-
);
|
|
64
|
-
this.logger.verbose(
|
|
65
|
-
"RefreshTokenClientAcquireToken called",
|
|
66
|
-
request.correlationId
|
|
67
|
-
);
|
|
68
68
|
const reqTimestamp = TimeUtils.nowSeconds();
|
|
69
|
-
|
|
69
|
+
const response = await invokeAsync(
|
|
70
|
+
this.executeTokenRequest.bind(this),
|
|
70
71
|
PerformanceEvents.RefreshTokenClientExecuteTokenRequest,
|
|
72
|
+
this.logger,
|
|
73
|
+
this.performanceClient,
|
|
71
74
|
request.correlationId
|
|
72
|
-
);
|
|
73
|
-
const response = await this.executeTokenRequest(
|
|
74
|
-
request,
|
|
75
|
-
this.authority
|
|
76
|
-
);
|
|
75
|
+
)(request, this.authority);
|
|
77
76
|
|
|
78
77
|
// Retrieve requestId from response headers
|
|
79
78
|
const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
|
|
@@ -87,40 +86,23 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
87
86
|
);
|
|
88
87
|
responseHandler.validateTokenResponse(response.body);
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
return invokeAsync(
|
|
90
|
+
responseHandler.handleServerTokenResponse.bind(responseHandler),
|
|
91
91
|
PerformanceEvents.HandleServerTokenResponse,
|
|
92
|
+
this.logger,
|
|
93
|
+
this.performanceClient,
|
|
92
94
|
request.correlationId
|
|
95
|
+
)(
|
|
96
|
+
response.body,
|
|
97
|
+
this.authority,
|
|
98
|
+
reqTimestamp,
|
|
99
|
+
request,
|
|
100
|
+
undefined,
|
|
101
|
+
undefined,
|
|
102
|
+
true,
|
|
103
|
+
request.forceCache,
|
|
104
|
+
requestId
|
|
93
105
|
);
|
|
94
|
-
return responseHandler
|
|
95
|
-
.handleServerTokenResponse(
|
|
96
|
-
response.body,
|
|
97
|
-
this.authority,
|
|
98
|
-
reqTimestamp,
|
|
99
|
-
request,
|
|
100
|
-
undefined,
|
|
101
|
-
undefined,
|
|
102
|
-
true,
|
|
103
|
-
request.forceCache,
|
|
104
|
-
requestId
|
|
105
|
-
)
|
|
106
|
-
.then((result: AuthenticationResult) => {
|
|
107
|
-
atsMeasurement?.end({
|
|
108
|
-
success: true,
|
|
109
|
-
});
|
|
110
|
-
return result;
|
|
111
|
-
})
|
|
112
|
-
.catch((error) => {
|
|
113
|
-
this.logger.verbose(
|
|
114
|
-
"Error in fetching refresh token",
|
|
115
|
-
request.correlationId
|
|
116
|
-
);
|
|
117
|
-
atsMeasurement?.end({
|
|
118
|
-
errorCode: error.errorCode,
|
|
119
|
-
subErrorCode: error.subError,
|
|
120
|
-
success: false,
|
|
121
|
-
});
|
|
122
|
-
throw error;
|
|
123
|
-
});
|
|
124
106
|
}
|
|
125
107
|
|
|
126
108
|
/**
|
|
@@ -132,7 +114,9 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
132
114
|
): Promise<AuthenticationResult> {
|
|
133
115
|
// Cannot renew token if no request object is given.
|
|
134
116
|
if (!request) {
|
|
135
|
-
throw
|
|
117
|
+
throw createClientConfigurationError(
|
|
118
|
+
ClientConfigurationErrorCodes.tokenRequestEmpty
|
|
119
|
+
);
|
|
136
120
|
}
|
|
137
121
|
|
|
138
122
|
this.performanceClient?.addQueueMeasurement(
|
|
@@ -142,7 +126,9 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
142
126
|
|
|
143
127
|
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
144
128
|
if (!request.account) {
|
|
145
|
-
throw
|
|
129
|
+
throw createClientAuthError(
|
|
130
|
+
ClientAuthErrorCodes.noAccountInSilentRequest
|
|
131
|
+
);
|
|
146
132
|
}
|
|
147
133
|
|
|
148
134
|
// try checking if FOCI is enabled for the given application
|
|
@@ -153,17 +139,18 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
153
139
|
// if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest
|
|
154
140
|
if (isFOCI) {
|
|
155
141
|
try {
|
|
156
|
-
|
|
142
|
+
return invokeAsync(
|
|
143
|
+
this.acquireTokenWithCachedRefreshToken.bind(this),
|
|
157
144
|
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
145
|
+
this.logger,
|
|
146
|
+
this.performanceClient,
|
|
158
147
|
request.correlationId
|
|
159
|
-
);
|
|
160
|
-
return this.acquireTokenWithCachedRefreshToken(request, true);
|
|
148
|
+
)(request, true);
|
|
161
149
|
} catch (e) {
|
|
162
150
|
const noFamilyRTInCache =
|
|
163
151
|
e instanceof InteractionRequiredAuthError &&
|
|
164
152
|
e.errorCode ===
|
|
165
|
-
|
|
166
|
-
.code;
|
|
153
|
+
InteractionRequiredAuthErrorCodes.noTokensFound;
|
|
167
154
|
const clientMismatchErrorWithFamilyRT =
|
|
168
155
|
e instanceof ServerError &&
|
|
169
156
|
e.errorCode === Errors.INVALID_GRANT_ERROR &&
|
|
@@ -171,14 +158,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
171
158
|
|
|
172
159
|
// if family Refresh Token (FRT) cache acquisition fails or if client_mismatch error is seen with FRT, reattempt with application Refresh Token (ART)
|
|
173
160
|
if (noFamilyRTInCache || clientMismatchErrorWithFamilyRT) {
|
|
174
|
-
|
|
161
|
+
return invokeAsync(
|
|
162
|
+
this.acquireTokenWithCachedRefreshToken.bind(this),
|
|
175
163
|
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
164
|
+
this.logger,
|
|
165
|
+
this.performanceClient,
|
|
176
166
|
request.correlationId
|
|
177
|
-
);
|
|
178
|
-
return this.acquireTokenWithCachedRefreshToken(
|
|
179
|
-
request,
|
|
180
|
-
false
|
|
181
|
-
);
|
|
167
|
+
)(request, false);
|
|
182
168
|
// throw in all other cases
|
|
183
169
|
} else {
|
|
184
170
|
throw e;
|
|
@@ -186,11 +172,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
186
172
|
}
|
|
187
173
|
}
|
|
188
174
|
// fall back to application refresh token acquisition
|
|
189
|
-
|
|
175
|
+
return invokeAsync(
|
|
176
|
+
this.acquireTokenWithCachedRefreshToken.bind(this),
|
|
190
177
|
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
178
|
+
this.logger,
|
|
179
|
+
this.performanceClient,
|
|
191
180
|
request.correlationId
|
|
192
|
-
);
|
|
193
|
-
return this.acquireTokenWithCachedRefreshToken(request, false);
|
|
181
|
+
)(request, false);
|
|
194
182
|
}
|
|
195
183
|
|
|
196
184
|
/**
|
|
@@ -207,28 +195,17 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
207
195
|
);
|
|
208
196
|
|
|
209
197
|
// fetches family RT or application RT based on FOCI value
|
|
210
|
-
|
|
211
|
-
const atsMeasurement = this.performanceClient?.startMeasurement(
|
|
212
|
-
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
213
|
-
request.correlationId
|
|
214
|
-
);
|
|
215
|
-
this.logger.verbose(
|
|
216
|
-
"RefreshTokenClientAcquireTokenWithCachedRefreshToken called",
|
|
217
|
-
request.correlationId
|
|
218
|
-
);
|
|
219
198
|
const refreshToken = this.cacheManager.getRefreshToken(
|
|
220
199
|
request.account,
|
|
221
200
|
foci
|
|
222
201
|
);
|
|
223
202
|
|
|
224
203
|
if (!refreshToken) {
|
|
225
|
-
|
|
226
|
-
|
|
204
|
+
throw createInteractionRequiredAuthError(
|
|
205
|
+
InteractionRequiredAuthErrorCodes.noTokensFound
|
|
206
|
+
);
|
|
227
207
|
}
|
|
228
208
|
// attach cached RT size to the current measurement
|
|
229
|
-
atsMeasurement?.end({
|
|
230
|
-
success: true,
|
|
231
|
-
});
|
|
232
209
|
|
|
233
210
|
const refreshTokenRequest: CommonRefreshTokenRequest = {
|
|
234
211
|
...request,
|
|
@@ -241,11 +218,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
241
218
|
},
|
|
242
219
|
};
|
|
243
220
|
|
|
244
|
-
|
|
221
|
+
return invokeAsync(
|
|
222
|
+
this.acquireToken.bind(this),
|
|
245
223
|
PerformanceEvents.RefreshTokenClientAcquireToken,
|
|
224
|
+
this.logger,
|
|
225
|
+
this.performanceClient,
|
|
246
226
|
request.correlationId
|
|
247
|
-
);
|
|
248
|
-
return this.acquireToken(refreshTokenRequest);
|
|
227
|
+
)(refreshTokenRequest);
|
|
249
228
|
}
|
|
250
229
|
|
|
251
230
|
/**
|
|
@@ -261,15 +240,6 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
261
240
|
PerformanceEvents.RefreshTokenClientExecuteTokenRequest,
|
|
262
241
|
request.correlationId
|
|
263
242
|
);
|
|
264
|
-
const acquireTokenMeasurement =
|
|
265
|
-
this.performanceClient?.startMeasurement(
|
|
266
|
-
PerformanceEvents.RefreshTokenClientExecuteTokenRequest,
|
|
267
|
-
request.correlationId
|
|
268
|
-
);
|
|
269
|
-
this.performanceClient?.setPreQueueTime(
|
|
270
|
-
PerformanceEvents.RefreshTokenClientCreateTokenRequestBody,
|
|
271
|
-
request.correlationId
|
|
272
|
-
);
|
|
273
243
|
|
|
274
244
|
const queryParametersString = this.createTokenQueryParameters(request);
|
|
275
245
|
const endpoint = UrlString.appendQueryString(
|
|
@@ -277,7 +247,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
277
247
|
queryParametersString
|
|
278
248
|
);
|
|
279
249
|
|
|
280
|
-
const requestBody = await
|
|
250
|
+
const requestBody = await invokeAsync(
|
|
251
|
+
this.createTokenRequestBody.bind(this),
|
|
252
|
+
PerformanceEvents.RefreshTokenClientCreateTokenRequestBody,
|
|
253
|
+
this.logger,
|
|
254
|
+
this.performanceClient,
|
|
255
|
+
request.correlationId
|
|
256
|
+
)(request);
|
|
281
257
|
const headers: Record<string, string> = this.createTokenRequestHeaders(
|
|
282
258
|
request.ccsCredential
|
|
283
259
|
);
|
|
@@ -293,25 +269,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
293
269
|
sshKid: request.sshKid,
|
|
294
270
|
};
|
|
295
271
|
|
|
296
|
-
return
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
272
|
+
return invokeAsync(
|
|
273
|
+
this.executePostToTokenEndpoint.bind(this),
|
|
274
|
+
PerformanceEvents.BaseClientExecutePostToTokenEndpoint,
|
|
275
|
+
this.logger,
|
|
276
|
+
this.performanceClient,
|
|
301
277
|
request.correlationId
|
|
302
|
-
)
|
|
303
|
-
.then((result) => {
|
|
304
|
-
acquireTokenMeasurement?.end({
|
|
305
|
-
success: true,
|
|
306
|
-
});
|
|
307
|
-
return result;
|
|
308
|
-
})
|
|
309
|
-
.catch((error) => {
|
|
310
|
-
acquireTokenMeasurement?.end({
|
|
311
|
-
success: false,
|
|
312
|
-
});
|
|
313
|
-
throw error;
|
|
314
|
-
});
|
|
278
|
+
)(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
315
279
|
}
|
|
316
280
|
|
|
317
281
|
/**
|
|
@@ -327,11 +291,6 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
327
291
|
);
|
|
328
292
|
|
|
329
293
|
const correlationId = request.correlationId;
|
|
330
|
-
const acquireTokenMeasurement =
|
|
331
|
-
this.performanceClient?.startMeasurement(
|
|
332
|
-
PerformanceEvents.BaseClientCreateTokenRequestHeaders,
|
|
333
|
-
correlationId
|
|
334
|
-
);
|
|
335
294
|
const parameterBuilder = new RequestParameterBuilder();
|
|
336
295
|
|
|
337
296
|
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
@@ -380,21 +339,22 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
380
339
|
this.cryptoUtils,
|
|
381
340
|
this.performanceClient
|
|
382
341
|
);
|
|
383
|
-
|
|
342
|
+
const reqCnfData = await invokeAsync(
|
|
343
|
+
popTokenGenerator.generateCnf.bind(popTokenGenerator),
|
|
384
344
|
PerformanceEvents.PopTokenGenerateCnf,
|
|
345
|
+
this.logger,
|
|
346
|
+
this.performanceClient,
|
|
385
347
|
request.correlationId
|
|
386
|
-
);
|
|
387
|
-
const reqCnfData = await popTokenGenerator.generateCnf(request);
|
|
348
|
+
)(request, this.logger);
|
|
388
349
|
// SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
|
|
389
350
|
parameterBuilder.addPopToken(reqCnfData.reqCnfString);
|
|
390
351
|
} else if (request.authenticationScheme === AuthenticationScheme.SSH) {
|
|
391
352
|
if (request.sshJwk) {
|
|
392
353
|
parameterBuilder.addSshJwk(request.sshJwk);
|
|
393
354
|
} else {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
throw ClientConfigurationError.createMissingSshJwkError();
|
|
355
|
+
throw createClientConfigurationError(
|
|
356
|
+
ClientConfigurationErrorCodes.missingSshJwk
|
|
357
|
+
);
|
|
398
358
|
}
|
|
399
359
|
}
|
|
400
360
|
|
|
@@ -434,9 +394,6 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
434
394
|
break;
|
|
435
395
|
}
|
|
436
396
|
}
|
|
437
|
-
acquireTokenMeasurement?.end({
|
|
438
|
-
success: true,
|
|
439
|
-
});
|
|
440
397
|
return parameterBuilder.createQueryString();
|
|
441
398
|
}
|
|
442
399
|
}
|
|
@@ -11,9 +11,13 @@ import { TimeUtils } from "../utils/TimeUtils";
|
|
|
11
11
|
import { RefreshTokenClient } from "./RefreshTokenClient";
|
|
12
12
|
import {
|
|
13
13
|
ClientAuthError,
|
|
14
|
-
|
|
14
|
+
ClientAuthErrorCodes,
|
|
15
|
+
createClientAuthError,
|
|
15
16
|
} from "../error/ClientAuthError";
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
createClientConfigurationError,
|
|
19
|
+
ClientConfigurationErrorCodes,
|
|
20
|
+
} from "../error/ClientConfigurationError";
|
|
17
21
|
import { ResponseHandler } from "../response/ResponseHandler";
|
|
18
22
|
import { CacheRecord } from "../cache/entities/CacheRecord";
|
|
19
23
|
import { CacheOutcome } from "../utils/Constants";
|
|
@@ -40,11 +44,35 @@ export class SilentFlowClient extends BaseClient {
|
|
|
40
44
|
request: CommonSilentFlowRequest
|
|
41
45
|
): Promise<AuthenticationResult> {
|
|
42
46
|
try {
|
|
43
|
-
|
|
47
|
+
const [authResponse, cacheOutcome] = await this.acquireCachedToken(
|
|
48
|
+
request
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// if the token is not expired but must be refreshed; get a new one in the background
|
|
52
|
+
if (cacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
|
|
53
|
+
this.logger.info(
|
|
54
|
+
"SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed."
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// refresh the access token in the background
|
|
58
|
+
const refreshTokenClient = new RefreshTokenClient(
|
|
59
|
+
this.config,
|
|
60
|
+
this.performanceClient
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
refreshTokenClient
|
|
64
|
+
.acquireTokenByRefreshToken(request)
|
|
65
|
+
.catch(() => {
|
|
66
|
+
// do nothing, this is running in the background and no action is to be taken upon success or failure
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// return the cached token
|
|
71
|
+
return authResponse;
|
|
44
72
|
} catch (e) {
|
|
45
73
|
if (
|
|
46
74
|
e instanceof ClientAuthError &&
|
|
47
|
-
e.errorCode ===
|
|
75
|
+
e.errorCode === ClientAuthErrorCodes.tokenRefreshRequired
|
|
48
76
|
) {
|
|
49
77
|
const refreshTokenClient = new RefreshTokenClient(
|
|
50
78
|
this.config,
|
|
@@ -63,35 +91,47 @@ export class SilentFlowClient extends BaseClient {
|
|
|
63
91
|
*/
|
|
64
92
|
async acquireCachedToken(
|
|
65
93
|
request: CommonSilentFlowRequest
|
|
66
|
-
): Promise<AuthenticationResult> {
|
|
94
|
+
): Promise<[AuthenticationResult, CacheOutcome]> {
|
|
95
|
+
let lastCacheOutcome: CacheOutcome = CacheOutcome.NOT_APPLICABLE;
|
|
96
|
+
|
|
67
97
|
// Cannot renew token if no request object is given.
|
|
68
98
|
if (!request) {
|
|
69
|
-
throw
|
|
99
|
+
throw createClientConfigurationError(
|
|
100
|
+
ClientConfigurationErrorCodes.tokenRequestEmpty
|
|
101
|
+
);
|
|
70
102
|
}
|
|
71
103
|
|
|
72
104
|
if (request.forceRefresh) {
|
|
73
105
|
// Must refresh due to present force_refresh flag.
|
|
106
|
+
lastCacheOutcome = CacheOutcome.FORCE_REFRESH_OR_CLAIMS;
|
|
74
107
|
this.serverTelemetryManager?.setCacheOutcome(
|
|
75
|
-
CacheOutcome.
|
|
108
|
+
CacheOutcome.FORCE_REFRESH_OR_CLAIMS
|
|
76
109
|
);
|
|
77
110
|
this.logger.info(
|
|
78
111
|
"SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true."
|
|
79
112
|
);
|
|
80
|
-
throw
|
|
113
|
+
throw createClientAuthError(
|
|
114
|
+
ClientAuthErrorCodes.tokenRefreshRequired
|
|
115
|
+
);
|
|
81
116
|
} else if (
|
|
82
117
|
!this.config.cacheOptions.claimsBasedCachingEnabled &&
|
|
83
118
|
!StringUtils.isEmptyObj(request.claims)
|
|
84
119
|
) {
|
|
120
|
+
lastCacheOutcome = CacheOutcome.FORCE_REFRESH_OR_CLAIMS;
|
|
85
121
|
// Must refresh due to request parameters.
|
|
86
122
|
this.logger.info(
|
|
87
123
|
"SilentFlowClient:acquireCachedToken - Skipping cache because claims-based caching is disabled and claims were requested."
|
|
88
124
|
);
|
|
89
|
-
throw
|
|
125
|
+
throw createClientAuthError(
|
|
126
|
+
ClientAuthErrorCodes.tokenRefreshRequired
|
|
127
|
+
);
|
|
90
128
|
}
|
|
91
129
|
|
|
92
130
|
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
93
131
|
if (!request.account) {
|
|
94
|
-
throw
|
|
132
|
+
throw createClientAuthError(
|
|
133
|
+
ClientAuthErrorCodes.noAccountInSilentRequest
|
|
134
|
+
);
|
|
95
135
|
}
|
|
96
136
|
|
|
97
137
|
const environment =
|
|
@@ -104,14 +144,17 @@ export class SilentFlowClient extends BaseClient {
|
|
|
104
144
|
);
|
|
105
145
|
|
|
106
146
|
if (!cacheRecord.accessToken) {
|
|
107
|
-
//
|
|
147
|
+
// must refresh due to non-existent access_token
|
|
148
|
+
lastCacheOutcome = CacheOutcome.NO_CACHED_ACCESS_TOKEN;
|
|
108
149
|
this.serverTelemetryManager?.setCacheOutcome(
|
|
109
150
|
CacheOutcome.NO_CACHED_ACCESS_TOKEN
|
|
110
151
|
);
|
|
111
152
|
this.logger.info(
|
|
112
153
|
"SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties."
|
|
113
154
|
);
|
|
114
|
-
throw
|
|
155
|
+
throw createClientAuthError(
|
|
156
|
+
ClientAuthErrorCodes.tokenRefreshRequired
|
|
157
|
+
);
|
|
115
158
|
} else if (
|
|
116
159
|
TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
|
|
117
160
|
TimeUtils.isTokenExpired(
|
|
@@ -119,33 +162,41 @@ export class SilentFlowClient extends BaseClient {
|
|
|
119
162
|
this.config.systemOptions.tokenRenewalOffsetSeconds
|
|
120
163
|
)
|
|
121
164
|
) {
|
|
122
|
-
//
|
|
165
|
+
// must refresh due to the expires_in value
|
|
166
|
+
lastCacheOutcome = CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED;
|
|
123
167
|
this.serverTelemetryManager?.setCacheOutcome(
|
|
124
168
|
CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED
|
|
125
169
|
);
|
|
126
170
|
this.logger.info(
|
|
127
171
|
`SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`
|
|
128
172
|
);
|
|
129
|
-
throw
|
|
173
|
+
throw createClientAuthError(
|
|
174
|
+
ClientAuthErrorCodes.tokenRefreshRequired
|
|
175
|
+
);
|
|
130
176
|
} else if (
|
|
131
177
|
cacheRecord.accessToken.refreshOn &&
|
|
132
178
|
TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)
|
|
133
179
|
) {
|
|
134
|
-
//
|
|
180
|
+
// must refresh (in the background) due to the refresh_in value
|
|
181
|
+
lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
|
|
135
182
|
this.serverTelemetryManager?.setCacheOutcome(
|
|
136
|
-
CacheOutcome.
|
|
183
|
+
CacheOutcome.PROACTIVELY_REFRESHED
|
|
137
184
|
);
|
|
138
185
|
this.logger.info(
|
|
139
186
|
"SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'."
|
|
140
187
|
);
|
|
141
|
-
|
|
188
|
+
|
|
189
|
+
// don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead
|
|
142
190
|
}
|
|
143
191
|
|
|
144
192
|
if (this.config.serverTelemetryManager) {
|
|
145
193
|
this.config.serverTelemetryManager.incrementCacheHits();
|
|
146
194
|
}
|
|
147
195
|
|
|
148
|
-
return
|
|
196
|
+
return [
|
|
197
|
+
await this.generateResultFromCacheRecord(cacheRecord, request),
|
|
198
|
+
lastCacheOutcome,
|
|
199
|
+
];
|
|
149
200
|
}
|
|
150
201
|
|
|
151
202
|
/**
|
|
@@ -168,7 +219,9 @@ export class SilentFlowClient extends BaseClient {
|
|
|
168
219
|
if (request.maxAge || request.maxAge === 0) {
|
|
169
220
|
const authTime = idTokenClaims?.auth_time;
|
|
170
221
|
if (!authTime) {
|
|
171
|
-
throw
|
|
222
|
+
throw createClientAuthError(
|
|
223
|
+
ClientAuthErrorCodes.authTimeNotFound
|
|
224
|
+
);
|
|
172
225
|
}
|
|
173
226
|
|
|
174
227
|
checkMaxAge(authTime, request.maxAge);
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import { INetworkModule } from "../network/INetworkModule";
|
|
7
7
|
import { DEFAULT_CRYPTO_IMPLEMENTATION, ICrypto } from "../crypto/ICrypto";
|
|
8
|
-
import { AuthError } from "../error/AuthError";
|
|
9
8
|
import { ILoggerCallback, Logger, LogLevel } from "../logger/Logger";
|
|
10
9
|
import { Constants } from "../utils/Constants";
|
|
11
10
|
import { version } from "../packageMetadata";
|
|
@@ -17,6 +16,10 @@ import { ICachePlugin } from "../cache/interface/ICachePlugin";
|
|
|
17
16
|
import { ISerializableTokenCache } from "../cache/interface/ISerializableTokenCache";
|
|
18
17
|
import { ClientCredentials } from "../account/ClientCredentials";
|
|
19
18
|
import { ProtocolMode } from "../authority/ProtocolMode";
|
|
19
|
+
import {
|
|
20
|
+
ClientAuthErrorCodes,
|
|
21
|
+
createClientAuthError,
|
|
22
|
+
} from "../error/ClientAuthError";
|
|
20
23
|
|
|
21
24
|
// Token renewal offset default in seconds
|
|
22
25
|
const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
|
|
@@ -177,14 +180,10 @@ const DEFAULT_CACHE_OPTIONS: Required<CacheOptions> = {
|
|
|
177
180
|
|
|
178
181
|
const DEFAULT_NETWORK_IMPLEMENTATION: INetworkModule = {
|
|
179
182
|
async sendGetRequestAsync<T>(): Promise<T> {
|
|
180
|
-
|
|
181
|
-
"Network interface - sendGetRequestAsync() has not been implemented";
|
|
182
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
183
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
183
184
|
},
|
|
184
185
|
async sendPostRequestAsync<T>(): Promise<T> {
|
|
185
|
-
|
|
186
|
-
"Network interface - sendPostRequestAsync() has not been implemented";
|
|
187
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
186
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
188
187
|
},
|
|
189
188
|
};
|
|
190
189
|
|
package/src/crypto/ICrypto.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ClientAuthErrorCodes,
|
|
8
|
+
createClientAuthError,
|
|
9
|
+
} from "../error/ClientAuthError";
|
|
7
10
|
import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
8
11
|
import { SignedHttpRequest } from "./SignedHttpRequest";
|
|
9
12
|
|
|
@@ -80,48 +83,30 @@ export interface ICrypto {
|
|
|
80
83
|
|
|
81
84
|
export const DEFAULT_CRYPTO_IMPLEMENTATION: ICrypto = {
|
|
82
85
|
createNewGuid: (): string => {
|
|
83
|
-
|
|
84
|
-
"Crypto interface - createNewGuid() has not been implemented";
|
|
85
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
86
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
86
87
|
},
|
|
87
88
|
base64Decode: (): string => {
|
|
88
|
-
|
|
89
|
-
"Crypto interface - base64Decode() has not been implemented";
|
|
90
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
89
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
91
90
|
},
|
|
92
91
|
base64Encode: (): string => {
|
|
93
|
-
|
|
94
|
-
"Crypto interface - base64Encode() has not been implemented";
|
|
95
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
92
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
96
93
|
},
|
|
97
94
|
async generatePkceCodes(): Promise<PkceCodes> {
|
|
98
|
-
|
|
99
|
-
"Crypto interface - generatePkceCodes() has not been implemented";
|
|
100
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
95
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
101
96
|
},
|
|
102
97
|
async getPublicKeyThumbprint(): Promise<string> {
|
|
103
|
-
|
|
104
|
-
"Crypto interface - getPublicKeyThumbprint() has not been implemented";
|
|
105
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
98
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
106
99
|
},
|
|
107
100
|
async removeTokenBindingKey(): Promise<boolean> {
|
|
108
|
-
|
|
109
|
-
"Crypto interface - removeTokenBindingKey() has not been implemented";
|
|
110
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
101
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
111
102
|
},
|
|
112
103
|
async clearKeystore(): Promise<boolean> {
|
|
113
|
-
|
|
114
|
-
"Crypto interface - clearKeystore() has not been implemented";
|
|
115
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
104
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
116
105
|
},
|
|
117
106
|
async signJwt(): Promise<string> {
|
|
118
|
-
|
|
119
|
-
"Crypto interface - signJwt() has not been implemented";
|
|
120
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
107
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
121
108
|
},
|
|
122
109
|
async hashString(): Promise<string> {
|
|
123
|
-
|
|
124
|
-
"Crypto interface - hashString() has not been implemented";
|
|
125
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
110
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
126
111
|
},
|
|
127
112
|
};
|
package/src/crypto/JoseHeader.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
JoseHeaderErrorCodes,
|
|
8
|
+
createJoseHeaderError,
|
|
9
|
+
} from "../error/JoseHeaderError";
|
|
7
10
|
import { JsonTypes } from "../utils/Constants";
|
|
8
11
|
|
|
9
12
|
export type JoseHeaderOptions = {
|
|
@@ -35,12 +38,12 @@ export class JoseHeader {
|
|
|
35
38
|
static getShrHeaderString(shrHeaderOptions: JoseHeaderOptions): string {
|
|
36
39
|
// KeyID is required on the SHR header
|
|
37
40
|
if (!shrHeaderOptions.kid) {
|
|
38
|
-
throw
|
|
41
|
+
throw createJoseHeaderError(JoseHeaderErrorCodes.missingKidError);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
// Alg is required on the SHR header
|
|
42
45
|
if (!shrHeaderOptions.alg) {
|
|
43
|
-
throw
|
|
46
|
+
throw createJoseHeaderError(JoseHeaderErrorCodes.missingAlgError);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
const shrHeader = new JoseHeader({
|