@azure/msal-common 14.0.3 → 14.1.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 +0 -1
- package/dist/account/AccountInfo.d.ts.map +1 -1
- package/dist/account/AuthToken.d.ts.map +1 -1
- package/dist/account/AuthToken.mjs +7 -6
- package/dist/account/AuthToken.mjs.map +1 -1
- package/dist/account/CcsCredential.mjs +1 -1
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.mjs +6 -5
- package/dist/account/ClientInfo.mjs.map +1 -1
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +28 -50
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +9 -7
- package/dist/authority/AuthorityFactory.mjs.map +1 -1
- package/dist/authority/AuthorityMetadata.mjs +1 -1
- package/dist/authority/AuthorityOptions.mjs +1 -1
- package/dist/authority/AuthorityType.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +1 -1
- package/dist/authority/ProtocolMode.mjs +1 -1
- package/dist/authority/RegionDiscovery.d.ts +3 -1
- package/dist/authority/RegionDiscovery.d.ts.map +1 -1
- package/dist/authority/RegionDiscovery.mjs +7 -8
- package/dist/authority/RegionDiscovery.mjs.map +1 -1
- package/dist/cache/CacheManager.d.ts +25 -7
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +98 -71
- 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 -3
- package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +4 -3
- package/dist/cache/entities/AccountEntity.mjs.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
- package/dist/cache/entities/CacheRecord.mjs +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/CredentialEntity.mjs +4 -3
- package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
- package/dist/cache/entities/IdTokenEntity.mjs +1 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +3 -6
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +13 -11
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.mjs +5 -4
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +33 -74
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +2 -1
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +43 -19
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.mjs +5 -6
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/crypto/ICrypto.d.ts +0 -4
- package/dist/crypto/ICrypto.d.ts.map +1 -1
- package/dist/crypto/ICrypto.mjs +11 -22
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/JoseHeader.d.ts.map +1 -1
- package/dist/crypto/JoseHeader.mjs +5 -4
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +2 -1
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +4 -4
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/error/AuthError.d.ts +8 -11
- package/dist/error/AuthError.d.ts.map +1 -1
- package/dist/error/AuthError.mjs +19 -21
- 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 +54 -234
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.mjs +149 -421
- 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 +31 -125
- package/dist/error/ClientConfigurationError.d.ts.map +1 -1
- package/dist/error/ClientConfigurationError.mjs +81 -222
- 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 +14 -16
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +42 -41
- 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 +7 -20
- package/dist/error/JoseHeaderError.d.ts.map +1 -1
- package/dist/error/JoseHeaderError.mjs +10 -26
- 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.mjs +1 -1
- package/dist/index.cjs +942 -1210
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- 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.mjs +1 -1
- package/dist/network/INetworkModule.d.ts.map +1 -1
- package/dist/network/INetworkModule.mjs +5 -6
- package/dist/network/INetworkModule.mjs.map +1 -1
- package/dist/network/NetworkManager.d.ts.map +1 -1
- package/dist/network/NetworkManager.mjs +4 -3
- package/dist/network/NetworkManager.mjs.map +1 -1
- package/dist/network/ThrottlingUtils.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs +7 -6
- package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
- package/dist/request/CommonRefreshTokenRequest.d.ts +3 -0
- package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/CommonSilentFlowRequest.d.ts +2 -0
- package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +5 -4
- package/dist/request/RequestParameterBuilder.mjs.map +1 -1
- package/dist/request/RequestValidator.d.ts.map +1 -1
- package/dist/request/RequestValidator.mjs +8 -7
- package/dist/request/RequestValidator.mjs.map +1 -1
- package/dist/request/ScopeSet.d.ts.map +1 -1
- package/dist/request/ScopeSet.mjs +10 -8
- package/dist/request/ScopeSet.mjs.map +1 -1
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +15 -14
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +3 -2
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -0
- 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.mjs +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +2 -2
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.mjs +13 -11
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +6 -3
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +12 -4
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts.map +1 -1
- package/dist/utils/FunctionWrappers.mjs +1 -2
- package/dist/utils/FunctionWrappers.mjs.map +1 -1
- package/dist/utils/ProtocolUtils.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.mjs +7 -6
- package/dist/utils/ProtocolUtils.mjs.map +1 -1
- package/dist/utils/StringUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/package.json +1 -1
- package/src/account/AccountInfo.ts +0 -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 +133 -95
- 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/cache/utils/CacheTypes.ts +6 -6
- package/src/client/AuthorizationCodeClient.ts +35 -11
- package/src/client/BaseClient.ts +7 -4
- package/src/client/RefreshTokenClient.ts +100 -126
- package/src/client/SilentFlowClient.ts +72 -19
- package/src/config/ClientConfiguration.ts +6 -7
- package/src/crypto/ICrypto.ts +12 -34
- 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 +13 -1
- package/src/network/INetworkModule.ts +10 -7
- package/src/network/NetworkManager.ts +5 -5
- package/src/packageMetadata.ts +1 -1
- package/src/request/AuthenticationHeaderParser.ts +11 -8
- package/src/request/CommonRefreshTokenRequest.ts +3 -0
- package/src/request/CommonSilentFlowRequest.ts +2 -0
- 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/performance/PerformanceEvent.ts +9 -0
- 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/FunctionWrappers.ts +0 -1
- package/src/utils/ProtocolUtils.ts +8 -12
|
@@ -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
|
|
|
@@ -42,10 +45,6 @@ export interface ICrypto {
|
|
|
42
45
|
* @param input
|
|
43
46
|
*/
|
|
44
47
|
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
48
|
/**
|
|
50
49
|
* Generates an JWK RSA S256 Thumbprint
|
|
51
50
|
* @param request
|
|
@@ -80,48 +79,27 @@ export interface ICrypto {
|
|
|
80
79
|
|
|
81
80
|
export const DEFAULT_CRYPTO_IMPLEMENTATION: ICrypto = {
|
|
82
81
|
createNewGuid: (): string => {
|
|
83
|
-
|
|
84
|
-
"Crypto interface - createNewGuid() has not been implemented";
|
|
85
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
82
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
86
83
|
},
|
|
87
84
|
base64Decode: (): string => {
|
|
88
|
-
|
|
89
|
-
"Crypto interface - base64Decode() has not been implemented";
|
|
90
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
85
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
91
86
|
},
|
|
92
87
|
base64Encode: (): string => {
|
|
93
|
-
|
|
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);
|
|
88
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
101
89
|
},
|
|
102
90
|
async getPublicKeyThumbprint(): Promise<string> {
|
|
103
|
-
|
|
104
|
-
"Crypto interface - getPublicKeyThumbprint() has not been implemented";
|
|
105
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
91
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
106
92
|
},
|
|
107
93
|
async removeTokenBindingKey(): Promise<boolean> {
|
|
108
|
-
|
|
109
|
-
"Crypto interface - removeTokenBindingKey() has not been implemented";
|
|
110
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
94
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
111
95
|
},
|
|
112
96
|
async clearKeystore(): Promise<boolean> {
|
|
113
|
-
|
|
114
|
-
"Crypto interface - clearKeystore() has not been implemented";
|
|
115
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
97
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
116
98
|
},
|
|
117
99
|
async signJwt(): Promise<string> {
|
|
118
|
-
|
|
119
|
-
"Crypto interface - signJwt() has not been implemented";
|
|
120
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
100
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
121
101
|
},
|
|
122
102
|
async hashString(): Promise<string> {
|
|
123
|
-
|
|
124
|
-
"Crypto interface - hashString() has not been implemented";
|
|
125
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
103
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
126
104
|
},
|
|
127
105
|
};
|
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({
|
|
@@ -8,6 +8,8 @@ import { TimeUtils } from "../utils/TimeUtils";
|
|
|
8
8
|
import { UrlString } from "../url/UrlString";
|
|
9
9
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
10
10
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
11
|
+
import { invokeAsync } from "../utils/FunctionWrappers";
|
|
12
|
+
import { Logger } from "../logger/Logger";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* See eSTS docs for more info.
|
|
@@ -50,18 +52,21 @@ export class PopTokenGenerator {
|
|
|
50
52
|
* @returns
|
|
51
53
|
*/
|
|
52
54
|
async generateCnf(
|
|
53
|
-
request: SignedHttpRequestParameters
|
|
55
|
+
request: SignedHttpRequestParameters,
|
|
56
|
+
logger: Logger
|
|
54
57
|
): Promise<ReqCnfData> {
|
|
55
58
|
this.performanceClient?.addQueueMeasurement(
|
|
56
59
|
PerformanceEvents.PopTokenGenerateCnf,
|
|
57
60
|
request.correlationId
|
|
58
61
|
);
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const reqCnf = await invokeAsync(
|
|
64
|
+
this.generateKid.bind(this),
|
|
65
|
+
PerformanceEvents.PopTokenGenerateCnf,
|
|
66
|
+
logger,
|
|
67
|
+
this.performanceClient,
|
|
62
68
|
request.correlationId
|
|
63
|
-
);
|
|
64
|
-
const reqCnf = await this.generateKid(request);
|
|
69
|
+
)(request);
|
|
65
70
|
const reqCnfString: string = this.cryptoUtils.base64Encode(
|
|
66
71
|
JSON.stringify(reqCnf)
|
|
67
72
|
);
|
package/src/error/AuthError.ts
CHANGED
|
@@ -4,18 +4,27 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Constants } from "../utils/Constants";
|
|
7
|
+
import * as AuthErrorCodes from "./AuthErrorCodes";
|
|
8
|
+
export { AuthErrorCodes };
|
|
9
|
+
|
|
10
|
+
export const AuthErrorMessages = {
|
|
11
|
+
[AuthErrorCodes.unexpectedError]: "Unexpected error in authentication.",
|
|
12
|
+
[AuthErrorCodes.postRequestFailed]:
|
|
13
|
+
"Post request failed from the network, could be a 4xx/5xx or a network unavailability. Please check the exact error code for details.",
|
|
14
|
+
};
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* AuthErrorMessage class containing string constants used by error codes and messages.
|
|
18
|
+
* @deprecated Use AuthErrorCodes instead
|
|
10
19
|
*/
|
|
11
20
|
export const AuthErrorMessage = {
|
|
12
21
|
unexpectedError: {
|
|
13
|
-
code:
|
|
14
|
-
desc:
|
|
22
|
+
code: AuthErrorCodes.unexpectedError,
|
|
23
|
+
desc: AuthErrorMessages[AuthErrorCodes.unexpectedError],
|
|
15
24
|
},
|
|
16
25
|
postRequestFailed: {
|
|
17
|
-
code:
|
|
18
|
-
desc:
|
|
26
|
+
code: AuthErrorCodes.postRequestFailed,
|
|
27
|
+
desc: AuthErrorMessages[AuthErrorCodes.postRequestFailed],
|
|
19
28
|
},
|
|
20
29
|
};
|
|
21
30
|
|
|
@@ -59,27 +68,16 @@ export class AuthError extends Error {
|
|
|
59
68
|
setCorrelationId(correlationId: string): void {
|
|
60
69
|
this.correlationId = correlationId;
|
|
61
70
|
}
|
|
71
|
+
}
|
|
62
72
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`${
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Creates an error for post request failures.
|
|
76
|
-
* @param errDesc
|
|
77
|
-
* @returns
|
|
78
|
-
*/
|
|
79
|
-
static createPostRequestFailed(errDesc: string): AuthError {
|
|
80
|
-
return new AuthError(
|
|
81
|
-
AuthErrorMessage.postRequestFailed.code,
|
|
82
|
-
`${AuthErrorMessage.postRequestFailed.desc}: ${errDesc}`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
73
|
+
export function createAuthError(
|
|
74
|
+
code: string,
|
|
75
|
+
additionalMessage?: string
|
|
76
|
+
): AuthError {
|
|
77
|
+
return new AuthError(
|
|
78
|
+
code,
|
|
79
|
+
additionalMessage
|
|
80
|
+
? `${AuthErrorMessages[code]} ${additionalMessage}`
|
|
81
|
+
: AuthErrorMessages[code]
|
|
82
|
+
);
|
|
85
83
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* AuthErrorMessage class containing string constants used by error codes and messages.
|
|
8
|
+
*/
|
|
9
|
+
export const unexpectedError = "unexpected_error";
|
|
10
|
+
export const postRequestFailed = "post_request_failed";
|