@azure/msal-node 2.0.2 → 2.2.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/README.md +3 -1
- package/dist/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +401 -401
- package/dist/cache/NodeStorage.cjs.map +1 -1
- package/dist/cache/NodeStorage.d.ts +182 -182
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/NodeStorage.mjs +401 -401
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.cjs +265 -269
- package/dist/cache/TokenCache.cjs.map +1 -1
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +266 -270
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
- package/dist/cache/distributed/ICacheClient.d.ts +17 -17
- package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
- package/dist/cache/serializer/Deserializer.cjs +173 -175
- package/dist/cache/serializer/Deserializer.cjs.map +1 -1
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
- package/dist/cache/serializer/Deserializer.mjs +174 -176
- package/dist/cache/serializer/Deserializer.mjs.map +1 -1
- package/dist/cache/serializer/Serializer.cjs +134 -134
- package/dist/cache/serializer/Serializer.cjs.map +1 -1
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.d.ts.map +1 -1
- package/dist/cache/serializer/Serializer.mjs +134 -134
- package/dist/cache/serializer/Serializer.mjs.map +1 -1
- package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
- package/dist/client/ClientApplication.cjs +333 -333
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +142 -142
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +334 -334
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.cjs +116 -116
- package/dist/client/ClientAssertion.cjs.map +1 -1
- package/dist/client/ClientAssertion.d.ts +46 -46
- package/dist/client/ClientAssertion.d.ts.map +1 -1
- package/dist/client/ClientAssertion.mjs +117 -117
- package/dist/client/ClientAssertion.mjs.map +1 -1
- package/dist/client/ClientCredentialClient.cjs +189 -168
- package/dist/client/ClientCredentialClient.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +190 -169
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.cjs +163 -164
- package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +164 -165
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.cjs +207 -207
- package/dist/client/DeviceCodeClient.cjs.map +1 -1
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.d.ts.map +1 -1
- package/dist/client/DeviceCodeClient.mjs +208 -208
- package/dist/client/DeviceCodeClient.mjs.map +1 -1
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/IPublicClientApplication.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.cjs +203 -204
- package/dist/client/OnBehalfOfClient.cjs.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.mjs +204 -205
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- package/dist/client/PublicClientApplication.cjs +229 -175
- package/dist/client/PublicClientApplication.cjs.map +1 -1
- package/dist/client/PublicClientApplication.d.ts +71 -65
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.mjs +232 -178
- package/dist/client/PublicClientApplication.mjs.map +1 -1
- package/dist/client/UsernamePasswordClient.cjs +95 -95
- package/dist/client/UsernamePasswordClient.cjs.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/client/UsernamePasswordClient.mjs.map +1 -1
- package/dist/config/Configuration.cjs +72 -72
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +107 -107
- package/dist/config/Configuration.mjs +72 -72
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/crypto/CryptoProvider.cjs +75 -75
- package/dist/crypto/CryptoProvider.cjs.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +52 -52
- package/dist/crypto/CryptoProvider.mjs +75 -75
- package/dist/crypto/CryptoProvider.mjs.map +1 -1
- package/dist/crypto/GuidGenerator.cjs +22 -22
- package/dist/crypto/GuidGenerator.cjs.map +1 -1
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/GuidGenerator.mjs.map +1 -1
- package/dist/crypto/HashUtils.cjs +13 -13
- package/dist/crypto/HashUtils.cjs.map +1 -1
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/HashUtils.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.cjs +49 -49
- package/dist/crypto/PkceGenerator.cjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/error/NodeAuthError.cjs +85 -85
- package/dist/error/NodeAuthError.cjs.map +1 -1
- package/dist/error/NodeAuthError.d.ts +65 -65
- package/dist/error/NodeAuthError.mjs +85 -85
- package/dist/error/NodeAuthError.mjs.map +1 -1
- package/dist/index.cjs +17 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/internals.cjs +8 -8
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.d.ts +6 -6
- package/dist/internals.d.ts.map +1 -1
- package/dist/internals.mjs +8 -8
- package/dist/internals.mjs.map +1 -1
- package/dist/network/HttpClient.cjs +277 -276
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +25 -25
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +278 -277
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.cjs +75 -84
- package/dist/network/LoopbackClient.cjs.map +1 -1
- package/dist/network/LoopbackClient.d.ts +21 -21
- package/dist/network/LoopbackClient.d.ts.map +1 -1
- package/dist/network/LoopbackClient.mjs +77 -86
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +4 -4
- package/dist/packageMetadata.cjs.map +1 -1
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +4 -4
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
- package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
- package/dist/request/ClientCredentialRequest.d.ts +14 -14
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- package/dist/request/InteractiveRequest.d.ts.map +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts +14 -14
- package/dist/request/RefreshTokenRequest.d.ts +17 -17
- package/dist/request/SignOutRequest.d.ts +5 -5
- package/dist/request/SilentFlowRequest.d.ts +16 -16
- package/dist/request/UsernamePasswordRequest.d.ts +19 -19
- package/dist/utils/Constants.cjs +80 -90
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +86 -96
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +81 -90
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +44 -44
- package/dist/utils/EncodingUtils.cjs.map +1 -1
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/EncodingUtils.mjs.map +1 -1
- package/dist/utils/NetworkUtils.cjs +38 -38
- package/dist/utils/NetworkUtils.cjs.map +1 -1
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/dist/utils/NetworkUtils.mjs.map +1 -1
- package/package.json +8 -5
- package/src/cache/ITokenCache.ts +24 -0
- package/src/cache/NodeStorage.ts +533 -0
- package/src/cache/TokenCache.ts +358 -0
- package/src/cache/distributed/DistributedCachePlugin.ts +56 -0
- package/src/cache/distributed/ICacheClient.ts +23 -0
- package/src/cache/distributed/IPartitionManager.ts +35 -0
- package/src/cache/serializer/Deserializer.ts +218 -0
- package/src/cache/serializer/Serializer.ts +173 -0
- package/src/cache/serializer/SerializerTypes.ts +121 -0
- package/src/client/ClientApplication.ts +596 -0
- package/src/client/ClientAssertion.ts +165 -0
- package/src/client/ClientCredentialClient.ts +346 -0
- package/src/client/ConfidentialClientApplication.ts +268 -0
- package/src/client/DeviceCodeClient.ts +369 -0
- package/src/client/IConfidentialClientApplication.ts +72 -0
- package/src/client/IPublicClientApplication.ts +72 -0
- package/src/client/OnBehalfOfClient.ts +368 -0
- package/src/client/PublicClientApplication.ts +339 -0
- package/src/client/UsernamePasswordClient.ts +180 -0
- package/src/config/Configuration.ts +201 -0
- package/src/crypto/CryptoProvider.ts +98 -0
- package/src/crypto/GuidGenerator.ts +28 -0
- package/src/crypto/HashUtils.ts +17 -0
- package/src/crypto/PkceGenerator.ts +63 -0
- package/src/error/NodeAuthError.ts +117 -0
- package/src/index.ts +125 -0
- package/src/internals.ts +12 -0
- package/src/network/HttpClient.ts +425 -0
- package/src/network/ILoopbackClient.ts +19 -0
- package/src/network/LoopbackClient.ts +110 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthorizationCodeRequest.ts +39 -0
- package/src/request/AuthorizationUrlRequest.ts +50 -0
- package/src/request/ClientCredentialRequest.ts +29 -0
- package/src/request/DeviceCodeRequest.ts +34 -0
- package/src/request/InteractiveRequest.ts +39 -0
- package/src/request/OnBehalfOfRequest.ts +30 -0
- package/src/request/RefreshTokenRequest.ts +34 -0
- package/src/request/SignOutRequest.ts +11 -0
- package/src/request/SilentFlowRequest.ts +32 -0
- package/src/request/UsernamePasswordRequest.ts +36 -0
- package/src/utils/Constants.ts +103 -0
- package/src/utils/EncodingUtils.ts +50 -0
- package/src/utils/NetworkUtils.ts +49 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientCredentialClient.cjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":["BaseClient","
|
|
1
|
+
{"version":3,"file":"ClientCredentialClient.cjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":["BaseClient","CacheOutcome"],"mappings":";;;;;;AAKA;AA2BA;;AAEG;;AAGC;AAGI;AAOJ,MAAA,sBAAA,SAAAA,qBAAA,CAAA;;;AAGG,QAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA,CAAA;KACsB;AAmCzB;;AAEG;;AA4EH,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;;AAEG,QAAA,IAAA,OAAA,CAAA,SAAA,EAAA;AACH,YAAQ,OAAwB,MAAA,IAAA,CAAA,mBAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,CAAA;AAuBhC,SAAA;;;;AAIG,YAAA,IAAA,gBAAA,KAAAC,uBAAA,CAAA,qBAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,OAAA,0BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { AuthenticationResult, BaseClient, ClientConfiguration, CommonClientCredentialRequest, IAppTokenProvider } from "@azure/msal-common";
|
|
2
|
-
/**
|
|
3
|
-
* OAuth2.0 client credential grant
|
|
4
|
-
*/
|
|
5
|
-
export declare class ClientCredentialClient extends BaseClient {
|
|
6
|
-
private scopeSet;
|
|
7
|
-
private readonly appTokenProvider?;
|
|
8
|
-
constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
|
|
9
|
-
/**
|
|
10
|
-
* Public API to acquire a token with ClientCredential Flow for Confidential clients
|
|
11
|
-
* @param request
|
|
12
|
-
*/
|
|
13
|
-
acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
|
|
14
|
-
/**
|
|
15
|
-
* looks up cache if the tokens are cached already
|
|
16
|
-
*/
|
|
17
|
-
private getCachedAuthenticationResult;
|
|
18
|
-
/**
|
|
19
|
-
* Reads access token from the cache
|
|
20
|
-
*/
|
|
21
|
-
private readAccessTokenFromCache;
|
|
22
|
-
/**
|
|
23
|
-
* Makes a network call to request the token from the service
|
|
24
|
-
* @param request
|
|
25
|
-
* @param authority
|
|
26
|
-
*/
|
|
27
|
-
private executeTokenRequest;
|
|
28
|
-
/**
|
|
29
|
-
* generate the request to the server in the acceptable format
|
|
30
|
-
* @param request
|
|
31
|
-
*/
|
|
32
|
-
private createTokenRequestBody;
|
|
33
|
-
}
|
|
1
|
+
import { AuthenticationResult, BaseClient, ClientConfiguration, CommonClientCredentialRequest, IAppTokenProvider } from "@azure/msal-common";
|
|
2
|
+
/**
|
|
3
|
+
* OAuth2.0 client credential grant
|
|
4
|
+
*/
|
|
5
|
+
export declare class ClientCredentialClient extends BaseClient {
|
|
6
|
+
private scopeSet;
|
|
7
|
+
private readonly appTokenProvider?;
|
|
8
|
+
constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
|
|
9
|
+
/**
|
|
10
|
+
* Public API to acquire a token with ClientCredential Flow for Confidential clients
|
|
11
|
+
* @param request
|
|
12
|
+
*/
|
|
13
|
+
acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
|
|
14
|
+
/**
|
|
15
|
+
* looks up cache if the tokens are cached already
|
|
16
|
+
*/
|
|
17
|
+
private getCachedAuthenticationResult;
|
|
18
|
+
/**
|
|
19
|
+
* Reads access token from the cache
|
|
20
|
+
*/
|
|
21
|
+
private readAccessTokenFromCache;
|
|
22
|
+
/**
|
|
23
|
+
* Makes a network call to request the token from the service
|
|
24
|
+
* @param request
|
|
25
|
+
* @param authority
|
|
26
|
+
*/
|
|
27
|
+
private executeTokenRequest;
|
|
28
|
+
/**
|
|
29
|
+
* generate the request to the server in the acceptable format
|
|
30
|
+
* @param request
|
|
31
|
+
*/
|
|
32
|
+
private createTokenRequestBody;
|
|
33
|
+
}
|
|
34
34
|
//# sourceMappingURL=ClientCredentialClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,oBAAoB,EAGpB,UAAU,EAGV,mBAAmB,EACnB,6BAA6B,EAK7B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,oBAAoB,EAGpB,UAAU,EAGV,mBAAmB,EACnB,6BAA6B,EAK7B,iBAAiB,EAWpB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;gBAGlD,aAAa,EAAE,mBAAmB,EAClC,gBAAgB,CAAC,EAAE,iBAAiB;IAMxC;;;OAGG;IACU,YAAY,CACrB,OAAO,EAAE,6BAA6B,GACvC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAiCvC;;OAEG;YACW,6BAA6B;IA2E3C;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAuBhC;;;;OAIG;YACW,mBAAmB;IAwFjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CA0DjC"}
|
|
@@ -1,174 +1,195 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.0.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { BaseClient, ScopeSet,
|
|
3
|
+
import { BaseClient, ScopeSet, CacheOutcome, TokenCacheContext, TimeUtils, ResponseHandler, Constants, CredentialType, createClientAuthError, ClientAuthErrorCodes, UrlString, RequestParameterBuilder, GrantType, StringUtils, AuthenticationScheme } from '@azure/msal-common';
|
|
4
4
|
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
* Licensed under the MIT License.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* OAuth2.0 client credential grant
|
|
11
|
-
*/
|
|
12
|
-
class ClientCredentialClient extends BaseClient {
|
|
13
|
-
constructor(configuration, appTokenProvider) {
|
|
14
|
-
super(configuration);
|
|
15
|
-
this.appTokenProvider = appTokenProvider;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Public API to acquire a token with ClientCredential Flow for Confidential clients
|
|
19
|
-
* @param request
|
|
20
|
-
*/
|
|
21
|
-
async acquireToken(request) {
|
|
22
|
-
this.scopeSet = new ScopeSet(request.scopes || []);
|
|
23
|
-
if (request.skipCache) {
|
|
24
|
-
return await this.executeTokenRequest(request, this.authority);
|
|
25
|
-
}
|
|
26
|
-
const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);
|
|
27
|
-
if (cachedAuthenticationResult) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
scopes: request.scopes,
|
|
121
|
-
claims: request.claims,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
* Licensed under the MIT License.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* OAuth2.0 client credential grant
|
|
11
|
+
*/
|
|
12
|
+
class ClientCredentialClient extends BaseClient {
|
|
13
|
+
constructor(configuration, appTokenProvider) {
|
|
14
|
+
super(configuration);
|
|
15
|
+
this.appTokenProvider = appTokenProvider;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Public API to acquire a token with ClientCredential Flow for Confidential clients
|
|
19
|
+
* @param request
|
|
20
|
+
*/
|
|
21
|
+
async acquireToken(request) {
|
|
22
|
+
this.scopeSet = new ScopeSet(request.scopes || []);
|
|
23
|
+
if (request.skipCache) {
|
|
24
|
+
return await this.executeTokenRequest(request, this.authority);
|
|
25
|
+
}
|
|
26
|
+
const [cachedAuthenticationResult, lastCacheOutcome] = await this.getCachedAuthenticationResult(request);
|
|
27
|
+
if (cachedAuthenticationResult) {
|
|
28
|
+
// if the token is not expired but must be refreshed; get a new one in the background
|
|
29
|
+
if (lastCacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
|
|
30
|
+
this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
|
|
31
|
+
// refresh the access token in the background
|
|
32
|
+
const refreshAccessToken = true;
|
|
33
|
+
await this.executeTokenRequest(request, this.authority, refreshAccessToken);
|
|
34
|
+
}
|
|
35
|
+
// return the cached token
|
|
36
|
+
return cachedAuthenticationResult;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return await this.executeTokenRequest(request, this.authority);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* looks up cache if the tokens are cached already
|
|
44
|
+
*/
|
|
45
|
+
async getCachedAuthenticationResult(request) {
|
|
46
|
+
let lastCacheOutcome = CacheOutcome.NOT_APPLICABLE;
|
|
47
|
+
// read the user-supplied cache into memory, if applicable
|
|
48
|
+
let cacheContext;
|
|
49
|
+
if (this.config.serializableCache && this.config.persistencePlugin) {
|
|
50
|
+
cacheContext = new TokenCacheContext(this.config.serializableCache, false);
|
|
51
|
+
await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
|
|
52
|
+
}
|
|
53
|
+
const cachedAccessToken = this.readAccessTokenFromCache();
|
|
54
|
+
if (this.config.serializableCache &&
|
|
55
|
+
this.config.persistencePlugin &&
|
|
56
|
+
cacheContext) {
|
|
57
|
+
await this.config.persistencePlugin.afterCacheAccess(cacheContext);
|
|
58
|
+
}
|
|
59
|
+
// must refresh due to non-existent access_token
|
|
60
|
+
if (!cachedAccessToken) {
|
|
61
|
+
this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
62
|
+
return [null, CacheOutcome.NO_CACHED_ACCESS_TOKEN];
|
|
63
|
+
}
|
|
64
|
+
// must refresh due to the expires_in value
|
|
65
|
+
if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
66
|
+
this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
67
|
+
return [null, CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
|
|
68
|
+
}
|
|
69
|
+
// must refresh (in the background) due to the refresh_in value
|
|
70
|
+
if (cachedAccessToken.refreshOn &&
|
|
71
|
+
TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
|
|
72
|
+
lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
|
|
73
|
+
this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.PROACTIVELY_REFRESHED);
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
await ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
|
|
77
|
+
account: null,
|
|
78
|
+
idToken: null,
|
|
79
|
+
accessToken: cachedAccessToken,
|
|
80
|
+
refreshToken: null,
|
|
81
|
+
appMetadata: null,
|
|
82
|
+
}, true, request),
|
|
83
|
+
lastCacheOutcome,
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Reads access token from the cache
|
|
88
|
+
*/
|
|
89
|
+
readAccessTokenFromCache() {
|
|
90
|
+
const accessTokenFilter = {
|
|
91
|
+
homeAccountId: Constants.EMPTY_STRING,
|
|
92
|
+
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
93
|
+
credentialType: CredentialType.ACCESS_TOKEN,
|
|
94
|
+
clientId: this.config.authOptions.clientId,
|
|
95
|
+
realm: this.authority.tenant,
|
|
96
|
+
target: ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
97
|
+
};
|
|
98
|
+
const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
99
|
+
if (accessTokens.length < 1) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
else if (accessTokens.length > 1) {
|
|
103
|
+
throw createClientAuthError(ClientAuthErrorCodes.multipleMatchingTokens);
|
|
104
|
+
}
|
|
105
|
+
return accessTokens[0];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Makes a network call to request the token from the service
|
|
109
|
+
* @param request
|
|
110
|
+
* @param authority
|
|
111
|
+
*/
|
|
112
|
+
async executeTokenRequest(request, authority, refreshAccessToken) {
|
|
113
|
+
let serverTokenResponse;
|
|
114
|
+
let reqTimestamp;
|
|
115
|
+
if (this.appTokenProvider) {
|
|
116
|
+
this.logger.info("Using appTokenProvider extensibility.");
|
|
117
|
+
const appTokenPropviderParameters = {
|
|
118
|
+
correlationId: request.correlationId,
|
|
119
|
+
tenantId: this.config.authOptions.authority.tenant,
|
|
120
|
+
scopes: request.scopes,
|
|
121
|
+
claims: request.claims,
|
|
122
|
+
};
|
|
123
|
+
reqTimestamp = TimeUtils.nowSeconds();
|
|
124
|
+
const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
|
|
125
|
+
serverTokenResponse = {
|
|
126
|
+
access_token: appTokenProviderResult.accessToken,
|
|
127
|
+
expires_in: appTokenProviderResult.expiresInSeconds,
|
|
128
|
+
refresh_in: appTokenProviderResult.refreshInSeconds,
|
|
129
|
+
token_type: AuthenticationScheme.BEARER,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const queryParametersString = this.createTokenQueryParameters(request);
|
|
134
|
+
const endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
135
|
+
const requestBody = this.createTokenRequestBody(request);
|
|
136
|
+
const headers = this.createTokenRequestHeaders();
|
|
137
|
+
const thumbprint = {
|
|
138
|
+
clientId: this.config.authOptions.clientId,
|
|
139
|
+
authority: request.authority,
|
|
140
|
+
scopes: request.scopes,
|
|
141
|
+
claims: request.claims,
|
|
142
|
+
authenticationScheme: request.authenticationScheme,
|
|
143
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
144
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
145
|
+
shrClaims: request.shrClaims,
|
|
146
|
+
sshKid: request.sshKid,
|
|
147
|
+
};
|
|
148
|
+
reqTimestamp = TimeUtils.nowSeconds();
|
|
149
|
+
const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
150
|
+
serverTokenResponse = response.body;
|
|
151
|
+
serverTokenResponse.status = response.status;
|
|
152
|
+
}
|
|
153
|
+
const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
154
|
+
responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
|
|
155
|
+
const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
|
|
156
|
+
return tokenResponse;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* generate the request to the server in the acceptable format
|
|
160
|
+
* @param request
|
|
161
|
+
*/
|
|
162
|
+
createTokenRequestBody(request) {
|
|
163
|
+
const parameterBuilder = new RequestParameterBuilder();
|
|
164
|
+
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
165
|
+
parameterBuilder.addScopes(request.scopes, false);
|
|
166
|
+
parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
|
|
167
|
+
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
168
|
+
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
169
|
+
parameterBuilder.addThrottling();
|
|
170
|
+
if (this.serverTelemetryManager) {
|
|
171
|
+
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
172
|
+
}
|
|
173
|
+
const correlationId = request.correlationId ||
|
|
174
|
+
this.config.cryptoInterface.createNewGuid();
|
|
175
|
+
parameterBuilder.addCorrelationId(correlationId);
|
|
176
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
177
|
+
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
178
|
+
}
|
|
179
|
+
// Use clientAssertion from request, fallback to client assertion in base configuration
|
|
180
|
+
const clientAssertion = request.clientAssertion ||
|
|
181
|
+
this.config.clientCredentials.clientAssertion;
|
|
182
|
+
if (clientAssertion) {
|
|
183
|
+
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
184
|
+
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
185
|
+
}
|
|
186
|
+
if (!StringUtils.isEmptyObj(request.claims) ||
|
|
187
|
+
(this.config.authOptions.clientCapabilities &&
|
|
188
|
+
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
189
|
+
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
190
|
+
}
|
|
191
|
+
return parameterBuilder.createQueryString();
|
|
192
|
+
}
|
|
172
193
|
}
|
|
173
194
|
|
|
174
195
|
export { ClientCredentialClient };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientCredentialClient.mjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"ClientCredentialClient.mjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;AA2BA;;AAEG;;AAGC;AAGI;AAOJ,MAAA,sBAAA,SAAA,UAAA,CAAA;;;AAGG,QAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA,CAAA;KACsB;AAmCzB;;AAEG;;AA4EH,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;;AAEG,QAAA,IAAA,OAAA,CAAA,SAAA,EAAA;AACH,YAAQ,OAAwB,MAAA,IAAA,CAAA,mBAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,CAAA;AAuBhC,SAAA;;;;AAIG,YAAA,IAAA,gBAAA,KAAA,YAAA,CAAA,qBAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,OAAA,0BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|