@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
|
@@ -25,7 +25,10 @@ import { NetworkResponse } from "../network/NetworkManager";
|
|
|
25
25
|
import { ResponseHandler } from "../response/ResponseHandler";
|
|
26
26
|
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
27
27
|
import { StringUtils } from "../utils/StringUtils";
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
ClientAuthErrorCodes,
|
|
30
|
+
createClientAuthError,
|
|
31
|
+
} from "../error/ClientAuthError";
|
|
29
32
|
import { UrlString } from "../url/UrlString";
|
|
30
33
|
import { ServerAuthorizationCodeResponse } from "../response/ServerAuthorizationCodeResponse";
|
|
31
34
|
import { CommonEndSessionRequest } from "../request/CommonEndSessionRequest";
|
|
@@ -39,7 +42,10 @@ import {
|
|
|
39
42
|
buildClientInfo,
|
|
40
43
|
} from "../account/ClientInfo";
|
|
41
44
|
import { CcsCredentialType, CcsCredential } from "../account/CcsCredential";
|
|
42
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
createClientConfigurationError,
|
|
47
|
+
ClientConfigurationErrorCodes,
|
|
48
|
+
} from "../error/ClientConfigurationError";
|
|
43
49
|
import { RequestValidator } from "../request/RequestValidator";
|
|
44
50
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
45
51
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
@@ -110,7 +116,9 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
110
116
|
);
|
|
111
117
|
|
|
112
118
|
if (!request.code) {
|
|
113
|
-
throw
|
|
119
|
+
throw createClientAuthError(
|
|
120
|
+
ClientAuthErrorCodes.requestCannotBeMade
|
|
121
|
+
);
|
|
114
122
|
}
|
|
115
123
|
|
|
116
124
|
const reqTimestamp = TimeUtils.nowSeconds();
|
|
@@ -192,7 +200,9 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
192
200
|
|
|
193
201
|
// throw when there is no auth code in the response
|
|
194
202
|
if (!serverParams.code) {
|
|
195
|
-
throw
|
|
203
|
+
throw createClientAuthError(
|
|
204
|
+
ClientAuthErrorCodes.authorizationCodeMissingFromServerResponse
|
|
205
|
+
);
|
|
196
206
|
}
|
|
197
207
|
return {
|
|
198
208
|
...serverParams,
|
|
@@ -209,7 +219,9 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
209
219
|
getLogoutUri(logoutRequest: CommonEndSessionRequest): string {
|
|
210
220
|
// Throw error if logoutRequest is null/undefined
|
|
211
221
|
if (!logoutRequest) {
|
|
212
|
-
throw
|
|
222
|
+
throw createClientConfigurationError(
|
|
223
|
+
ClientConfigurationErrorCodes.logoutRequestEmpty
|
|
224
|
+
);
|
|
213
225
|
}
|
|
214
226
|
const queryString = this.createLogoutUrlQueryString(logoutRequest);
|
|
215
227
|
|
|
@@ -270,7 +282,9 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
270
282
|
);
|
|
271
283
|
|
|
272
284
|
const thumbprint: RequestThumbprint = {
|
|
273
|
-
clientId:
|
|
285
|
+
clientId:
|
|
286
|
+
request.tokenBodyParameters?.clientId ||
|
|
287
|
+
this.config.authOptions.clientId,
|
|
274
288
|
authority: authority.canonicalAuthority,
|
|
275
289
|
scopes: request.scopes,
|
|
276
290
|
claims: request.claims,
|
|
@@ -371,18 +385,22 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
371
385
|
this.performanceClient
|
|
372
386
|
);
|
|
373
387
|
|
|
374
|
-
|
|
388
|
+
const reqCnfData = await invokeAsync(
|
|
389
|
+
popTokenGenerator.generateCnf.bind(popTokenGenerator),
|
|
375
390
|
PerformanceEvents.PopTokenGenerateCnf,
|
|
391
|
+
this.logger,
|
|
392
|
+
this.performanceClient,
|
|
376
393
|
request.correlationId
|
|
377
|
-
);
|
|
378
|
-
const reqCnfData = await popTokenGenerator.generateCnf(request);
|
|
394
|
+
)(request, this.logger);
|
|
379
395
|
// SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
|
|
380
396
|
parameterBuilder.addPopToken(reqCnfData.reqCnfString);
|
|
381
397
|
} else if (request.authenticationScheme === AuthenticationScheme.SSH) {
|
|
382
398
|
if (request.sshJwk) {
|
|
383
399
|
parameterBuilder.addSshJwk(request.sshJwk);
|
|
384
400
|
} else {
|
|
385
|
-
throw
|
|
401
|
+
throw createClientConfigurationError(
|
|
402
|
+
ClientConfigurationErrorCodes.missingSshJwk
|
|
403
|
+
);
|
|
386
404
|
}
|
|
387
405
|
}
|
|
388
406
|
|
|
@@ -652,7 +670,13 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
652
670
|
this.cryptoUtils
|
|
653
671
|
);
|
|
654
672
|
// to reduce the URL length, it is recommended to send the hash of the req_cnf instead of the whole string
|
|
655
|
-
const reqCnfData = await
|
|
673
|
+
const reqCnfData = await invokeAsync(
|
|
674
|
+
popTokenGenerator.generateCnf.bind(popTokenGenerator),
|
|
675
|
+
PerformanceEvents.PopTokenGenerateCnf,
|
|
676
|
+
this.logger,
|
|
677
|
+
this.performanceClient,
|
|
678
|
+
request.correlationId
|
|
679
|
+
)(request, this.logger);
|
|
656
680
|
parameterBuilder.addPopToken(reqCnfData.reqCnfHash);
|
|
657
681
|
}
|
|
658
682
|
}
|
package/src/client/BaseClient.ts
CHANGED
|
@@ -19,7 +19,10 @@ import { CacheManager } from "../cache/CacheManager";
|
|
|
19
19
|
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager";
|
|
20
20
|
import { RequestThumbprint } from "../network/RequestThumbprint";
|
|
21
21
|
import { version, name } from "../packageMetadata";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
createClientAuthError,
|
|
24
|
+
ClientAuthErrorCodes,
|
|
25
|
+
} from "../error/ClientAuthError";
|
|
23
26
|
import { CcsCredential, CcsCredentialType } from "../account/CcsCredential";
|
|
24
27
|
import { buildClientInfoFromHomeAccountId } from "../account/ClientInfo";
|
|
25
28
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
@@ -144,7 +147,7 @@ export abstract class BaseClient {
|
|
|
144
147
|
correlationId: string
|
|
145
148
|
): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {
|
|
146
149
|
this.performanceClient?.addQueueMeasurement(
|
|
147
|
-
PerformanceEvents.
|
|
150
|
+
PerformanceEvents.BaseClientExecutePostToTokenEndpoint,
|
|
148
151
|
correlationId
|
|
149
152
|
);
|
|
150
153
|
const response =
|
|
@@ -180,8 +183,8 @@ export abstract class BaseClient {
|
|
|
180
183
|
*/
|
|
181
184
|
updateAuthority(updatedAuthority: Authority): void {
|
|
182
185
|
if (!updatedAuthority.discoveryComplete()) {
|
|
183
|
-
throw
|
|
184
|
-
|
|
186
|
+
throw createClientAuthError(
|
|
187
|
+
ClientAuthErrorCodes.endpointResolutionError
|
|
185
188
|
);
|
|
186
189
|
}
|
|
187
190
|
this.authority = updatedAuthority;
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
AuthenticationScheme,
|
|
18
18
|
Errors,
|
|
19
19
|
HeaderNames,
|
|
20
|
+
AADServerParamKeys,
|
|
20
21
|
} from "../utils/Constants";
|
|
21
22
|
import { ResponseHandler } from "../response/ResponseHandler";
|
|
22
23
|
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
@@ -25,8 +26,14 @@ import { StringUtils } from "../utils/StringUtils";
|
|
|
25
26
|
import { RequestThumbprint } from "../network/RequestThumbprint";
|
|
26
27
|
import { NetworkResponse } from "../network/NetworkManager";
|
|
27
28
|
import { CommonSilentFlowRequest } from "../request/CommonSilentFlowRequest";
|
|
28
|
-
import {
|
|
29
|
-
|
|
29
|
+
import {
|
|
30
|
+
createClientConfigurationError,
|
|
31
|
+
ClientConfigurationErrorCodes,
|
|
32
|
+
} from "../error/ClientConfigurationError";
|
|
33
|
+
import {
|
|
34
|
+
createClientAuthError,
|
|
35
|
+
ClientAuthErrorCodes,
|
|
36
|
+
} from "../error/ClientAuthError";
|
|
30
37
|
import { ServerError } from "../error/ServerError";
|
|
31
38
|
import { TimeUtils } from "../utils/TimeUtils";
|
|
32
39
|
import { UrlString } from "../url/UrlString";
|
|
@@ -34,10 +41,12 @@ import { CcsCredentialType } from "../account/CcsCredential";
|
|
|
34
41
|
import { buildClientInfoFromHomeAccountId } from "../account/ClientInfo";
|
|
35
42
|
import {
|
|
36
43
|
InteractionRequiredAuthError,
|
|
37
|
-
|
|
44
|
+
InteractionRequiredAuthErrorCodes,
|
|
45
|
+
createInteractionRequiredAuthError,
|
|
38
46
|
} from "../error/InteractionRequiredAuthError";
|
|
39
47
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
40
48
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
49
|
+
import { invokeAsync } from "../utils/FunctionWrappers";
|
|
41
50
|
/**
|
|
42
51
|
* OAuth2.0 refresh token client
|
|
43
52
|
* @internal
|
|
@@ -57,23 +66,14 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
57
66
|
request.correlationId
|
|
58
67
|
);
|
|
59
68
|
|
|
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
69
|
const reqTimestamp = TimeUtils.nowSeconds();
|
|
69
|
-
|
|
70
|
+
const response = await invokeAsync(
|
|
71
|
+
this.executeTokenRequest.bind(this),
|
|
70
72
|
PerformanceEvents.RefreshTokenClientExecuteTokenRequest,
|
|
73
|
+
this.logger,
|
|
74
|
+
this.performanceClient,
|
|
71
75
|
request.correlationId
|
|
72
|
-
);
|
|
73
|
-
const response = await this.executeTokenRequest(
|
|
74
|
-
request,
|
|
75
|
-
this.authority
|
|
76
|
-
);
|
|
76
|
+
)(request, this.authority);
|
|
77
77
|
|
|
78
78
|
// Retrieve requestId from response headers
|
|
79
79
|
const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
|
|
@@ -87,40 +87,23 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
87
87
|
);
|
|
88
88
|
responseHandler.validateTokenResponse(response.body);
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
return invokeAsync(
|
|
91
|
+
responseHandler.handleServerTokenResponse.bind(responseHandler),
|
|
91
92
|
PerformanceEvents.HandleServerTokenResponse,
|
|
93
|
+
this.logger,
|
|
94
|
+
this.performanceClient,
|
|
92
95
|
request.correlationId
|
|
96
|
+
)(
|
|
97
|
+
response.body,
|
|
98
|
+
this.authority,
|
|
99
|
+
reqTimestamp,
|
|
100
|
+
request,
|
|
101
|
+
undefined,
|
|
102
|
+
undefined,
|
|
103
|
+
true,
|
|
104
|
+
request.forceCache,
|
|
105
|
+
requestId
|
|
93
106
|
);
|
|
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
107
|
}
|
|
125
108
|
|
|
126
109
|
/**
|
|
@@ -132,7 +115,9 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
132
115
|
): Promise<AuthenticationResult> {
|
|
133
116
|
// Cannot renew token if no request object is given.
|
|
134
117
|
if (!request) {
|
|
135
|
-
throw
|
|
118
|
+
throw createClientConfigurationError(
|
|
119
|
+
ClientConfigurationErrorCodes.tokenRequestEmpty
|
|
120
|
+
);
|
|
136
121
|
}
|
|
137
122
|
|
|
138
123
|
this.performanceClient?.addQueueMeasurement(
|
|
@@ -142,7 +127,9 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
142
127
|
|
|
143
128
|
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
144
129
|
if (!request.account) {
|
|
145
|
-
throw
|
|
130
|
+
throw createClientAuthError(
|
|
131
|
+
ClientAuthErrorCodes.noAccountInSilentRequest
|
|
132
|
+
);
|
|
146
133
|
}
|
|
147
134
|
|
|
148
135
|
// try checking if FOCI is enabled for the given application
|
|
@@ -153,17 +140,18 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
153
140
|
// if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest
|
|
154
141
|
if (isFOCI) {
|
|
155
142
|
try {
|
|
156
|
-
|
|
143
|
+
return invokeAsync(
|
|
144
|
+
this.acquireTokenWithCachedRefreshToken.bind(this),
|
|
157
145
|
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
146
|
+
this.logger,
|
|
147
|
+
this.performanceClient,
|
|
158
148
|
request.correlationId
|
|
159
|
-
);
|
|
160
|
-
return this.acquireTokenWithCachedRefreshToken(request, true);
|
|
149
|
+
)(request, true);
|
|
161
150
|
} catch (e) {
|
|
162
151
|
const noFamilyRTInCache =
|
|
163
152
|
e instanceof InteractionRequiredAuthError &&
|
|
164
153
|
e.errorCode ===
|
|
165
|
-
|
|
166
|
-
.code;
|
|
154
|
+
InteractionRequiredAuthErrorCodes.noTokensFound;
|
|
167
155
|
const clientMismatchErrorWithFamilyRT =
|
|
168
156
|
e instanceof ServerError &&
|
|
169
157
|
e.errorCode === Errors.INVALID_GRANT_ERROR &&
|
|
@@ -171,14 +159,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
171
159
|
|
|
172
160
|
// if family Refresh Token (FRT) cache acquisition fails or if client_mismatch error is seen with FRT, reattempt with application Refresh Token (ART)
|
|
173
161
|
if (noFamilyRTInCache || clientMismatchErrorWithFamilyRT) {
|
|
174
|
-
|
|
162
|
+
return invokeAsync(
|
|
163
|
+
this.acquireTokenWithCachedRefreshToken.bind(this),
|
|
175
164
|
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
165
|
+
this.logger,
|
|
166
|
+
this.performanceClient,
|
|
176
167
|
request.correlationId
|
|
177
|
-
);
|
|
178
|
-
return this.acquireTokenWithCachedRefreshToken(
|
|
179
|
-
request,
|
|
180
|
-
false
|
|
181
|
-
);
|
|
168
|
+
)(request, false);
|
|
182
169
|
// throw in all other cases
|
|
183
170
|
} else {
|
|
184
171
|
throw e;
|
|
@@ -186,11 +173,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
186
173
|
}
|
|
187
174
|
}
|
|
188
175
|
// fall back to application refresh token acquisition
|
|
189
|
-
|
|
176
|
+
return invokeAsync(
|
|
177
|
+
this.acquireTokenWithCachedRefreshToken.bind(this),
|
|
190
178
|
PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken,
|
|
179
|
+
this.logger,
|
|
180
|
+
this.performanceClient,
|
|
191
181
|
request.correlationId
|
|
192
|
-
);
|
|
193
|
-
return this.acquireTokenWithCachedRefreshToken(request, false);
|
|
182
|
+
)(request, false);
|
|
194
183
|
}
|
|
195
184
|
|
|
196
185
|
/**
|
|
@@ -207,28 +196,17 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
207
196
|
);
|
|
208
197
|
|
|
209
198
|
// 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
199
|
const refreshToken = this.cacheManager.getRefreshToken(
|
|
220
200
|
request.account,
|
|
221
201
|
foci
|
|
222
202
|
);
|
|
223
203
|
|
|
224
204
|
if (!refreshToken) {
|
|
225
|
-
|
|
226
|
-
|
|
205
|
+
throw createInteractionRequiredAuthError(
|
|
206
|
+
InteractionRequiredAuthErrorCodes.noTokensFound
|
|
207
|
+
);
|
|
227
208
|
}
|
|
228
209
|
// attach cached RT size to the current measurement
|
|
229
|
-
atsMeasurement?.end({
|
|
230
|
-
success: true,
|
|
231
|
-
});
|
|
232
210
|
|
|
233
211
|
const refreshTokenRequest: CommonRefreshTokenRequest = {
|
|
234
212
|
...request,
|
|
@@ -241,11 +219,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
241
219
|
},
|
|
242
220
|
};
|
|
243
221
|
|
|
244
|
-
|
|
222
|
+
return invokeAsync(
|
|
223
|
+
this.acquireToken.bind(this),
|
|
245
224
|
PerformanceEvents.RefreshTokenClientAcquireToken,
|
|
225
|
+
this.logger,
|
|
226
|
+
this.performanceClient,
|
|
246
227
|
request.correlationId
|
|
247
|
-
);
|
|
248
|
-
return this.acquireToken(refreshTokenRequest);
|
|
228
|
+
)(refreshTokenRequest);
|
|
249
229
|
}
|
|
250
230
|
|
|
251
231
|
/**
|
|
@@ -261,15 +241,6 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
261
241
|
PerformanceEvents.RefreshTokenClientExecuteTokenRequest,
|
|
262
242
|
request.correlationId
|
|
263
243
|
);
|
|
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
244
|
|
|
274
245
|
const queryParametersString = this.createTokenQueryParameters(request);
|
|
275
246
|
const endpoint = UrlString.appendQueryString(
|
|
@@ -277,12 +248,20 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
277
248
|
queryParametersString
|
|
278
249
|
);
|
|
279
250
|
|
|
280
|
-
const requestBody = await
|
|
251
|
+
const requestBody = await invokeAsync(
|
|
252
|
+
this.createTokenRequestBody.bind(this),
|
|
253
|
+
PerformanceEvents.RefreshTokenClientCreateTokenRequestBody,
|
|
254
|
+
this.logger,
|
|
255
|
+
this.performanceClient,
|
|
256
|
+
request.correlationId
|
|
257
|
+
)(request);
|
|
281
258
|
const headers: Record<string, string> = this.createTokenRequestHeaders(
|
|
282
259
|
request.ccsCredential
|
|
283
260
|
);
|
|
284
261
|
const thumbprint: RequestThumbprint = {
|
|
285
|
-
clientId:
|
|
262
|
+
clientId:
|
|
263
|
+
request.tokenBodyParameters?.clientId ||
|
|
264
|
+
this.config.authOptions.clientId,
|
|
286
265
|
authority: authority.canonicalAuthority,
|
|
287
266
|
scopes: request.scopes,
|
|
288
267
|
claims: request.claims,
|
|
@@ -293,25 +272,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
293
272
|
sshKid: request.sshKid,
|
|
294
273
|
};
|
|
295
274
|
|
|
296
|
-
return
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
275
|
+
return invokeAsync(
|
|
276
|
+
this.executePostToTokenEndpoint.bind(this),
|
|
277
|
+
PerformanceEvents.BaseClientExecutePostToTokenEndpoint,
|
|
278
|
+
this.logger,
|
|
279
|
+
this.performanceClient,
|
|
301
280
|
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
|
-
});
|
|
281
|
+
)(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
315
282
|
}
|
|
316
283
|
|
|
317
284
|
/**
|
|
@@ -327,14 +294,16 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
327
294
|
);
|
|
328
295
|
|
|
329
296
|
const correlationId = request.correlationId;
|
|
330
|
-
const acquireTokenMeasurement =
|
|
331
|
-
this.performanceClient?.startMeasurement(
|
|
332
|
-
PerformanceEvents.BaseClientCreateTokenRequestHeaders,
|
|
333
|
-
correlationId
|
|
334
|
-
);
|
|
335
297
|
const parameterBuilder = new RequestParameterBuilder();
|
|
336
298
|
|
|
337
|
-
parameterBuilder.addClientId(
|
|
299
|
+
parameterBuilder.addClientId(
|
|
300
|
+
request.tokenBodyParameters?.[AADServerParamKeys.CLIENT_ID] ||
|
|
301
|
+
this.config.authOptions.clientId
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
if (request.redirectUri) {
|
|
305
|
+
parameterBuilder.addRedirectUri(request.redirectUri);
|
|
306
|
+
}
|
|
338
307
|
|
|
339
308
|
parameterBuilder.addScopes(
|
|
340
309
|
request.scopes,
|
|
@@ -380,21 +349,22 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
380
349
|
this.cryptoUtils,
|
|
381
350
|
this.performanceClient
|
|
382
351
|
);
|
|
383
|
-
|
|
352
|
+
const reqCnfData = await invokeAsync(
|
|
353
|
+
popTokenGenerator.generateCnf.bind(popTokenGenerator),
|
|
384
354
|
PerformanceEvents.PopTokenGenerateCnf,
|
|
355
|
+
this.logger,
|
|
356
|
+
this.performanceClient,
|
|
385
357
|
request.correlationId
|
|
386
|
-
);
|
|
387
|
-
const reqCnfData = await popTokenGenerator.generateCnf(request);
|
|
358
|
+
)(request, this.logger);
|
|
388
359
|
// SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
|
|
389
360
|
parameterBuilder.addPopToken(reqCnfData.reqCnfString);
|
|
390
361
|
} else if (request.authenticationScheme === AuthenticationScheme.SSH) {
|
|
391
362
|
if (request.sshJwk) {
|
|
392
363
|
parameterBuilder.addSshJwk(request.sshJwk);
|
|
393
364
|
} else {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
throw ClientConfigurationError.createMissingSshJwkError();
|
|
365
|
+
throw createClientConfigurationError(
|
|
366
|
+
ClientConfigurationErrorCodes.missingSshJwk
|
|
367
|
+
);
|
|
398
368
|
}
|
|
399
369
|
}
|
|
400
370
|
|
|
@@ -434,9 +404,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
434
404
|
break;
|
|
435
405
|
}
|
|
436
406
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
407
|
+
|
|
408
|
+
if (request.tokenBodyParameters) {
|
|
409
|
+
parameterBuilder.addExtraQueryParameters(
|
|
410
|
+
request.tokenBodyParameters
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
440
414
|
return parameterBuilder.createQueryString();
|
|
441
415
|
}
|
|
442
416
|
}
|