@azure/msal-node 2.0.0-alpha.1 → 2.0.0-beta.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/LICENSE +21 -21
- package/README.md +182 -182
- package/dist/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.d.ts +182 -182
- package/dist/cache/NodeStorage.esm.js +401 -401
- package/dist/cache/NodeStorage.js +401 -401
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.esm.js +269 -269
- package/dist/cache/TokenCache.js +269 -269
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.esm.js +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.js +26 -26
- package/dist/cache/distributed/ICacheClient.d.ts +17 -17
- package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.esm.js +175 -175
- package/dist/cache/serializer/Deserializer.js +175 -175
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.esm.js +134 -134
- package/dist/cache/serializer/Serializer.js +134 -134
- package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
- package/dist/client/ClientApplication.d.ts +142 -142
- package/dist/client/ClientApplication.esm.js +327 -327
- package/dist/client/ClientApplication.js +327 -327
- package/dist/client/ClientAssertion.d.ts +46 -46
- package/dist/client/ClientAssertion.esm.js +116 -116
- package/dist/client/ClientAssertion.js +116 -116
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.esm.js +157 -157
- package/dist/client/ClientCredentialClient.js +157 -157
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.esm.js +163 -163
- package/dist/client/ConfidentialClientApplication.js +163 -163
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.esm.js +207 -207
- package/dist/client/DeviceCodeClient.js +207 -207
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.esm.js +204 -204
- package/dist/client/OnBehalfOfClient.js +204 -204
- package/dist/client/PublicClientApplication.d.ts +65 -65
- package/dist/client/PublicClientApplication.esm.js +175 -175
- package/dist/client/PublicClientApplication.js +175 -175
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.esm.js +102 -102
- package/dist/client/UsernamePasswordClient.js +102 -102
- package/dist/config/Configuration.d.ts +105 -105
- package/dist/config/Configuration.esm.js +70 -70
- package/dist/config/Configuration.js +70 -70
- package/dist/crypto/CryptoProvider.d.ts +52 -52
- package/dist/crypto/CryptoProvider.esm.js +75 -75
- package/dist/crypto/CryptoProvider.js +75 -75
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.esm.js +22 -22
- package/dist/crypto/GuidGenerator.js +22 -22
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.esm.js +13 -13
- package/dist/crypto/HashUtils.js +13 -13
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.esm.js +49 -49
- package/dist/crypto/PkceGenerator.js +49 -49
- package/dist/error/NodeAuthError.d.ts +65 -65
- package/dist/error/NodeAuthError.esm.js +85 -85
- package/dist/error/NodeAuthError.js +85 -85
- package/dist/index.d.ts +41 -41
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internals.d.ts +6 -6
- package/dist/internals.esm.js +4 -4
- package/dist/internals.js +4 -4
- package/dist/network/HttpClient.d.ts +25 -25
- package/dist/network/HttpClient.esm.js +276 -276
- package/dist/network/HttpClient.js +276 -276
- package/dist/network/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.d.ts +21 -21
- package/dist/network/LoopbackClient.esm.js +84 -84
- package/dist/network/LoopbackClient.js +84 -84
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.esm.js +4 -4
- package/dist/packageMetadata.js +4 -4
- package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
- package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
- package/dist/request/ClientCredentialRequest.d.ts +14 -15
- package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- 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.d.ts +96 -92
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.esm.js +89 -93
- package/dist/utils/Constants.esm.js.map +1 -1
- package/dist/utils/Constants.js +93 -93
- package/dist/utils/Constants.js.map +1 -1
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.esm.js +44 -44
- package/dist/utils/EncodingUtils.js +44 -44
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.esm.js +38 -38
- package/dist/utils/NetworkUtils.js +38 -38
- package/package.json +77 -73
- package/dist/msal-node.cjs.development.js +0 -2705
- package/dist/msal-node.cjs.development.js.map +0 -1
- package/dist/msal-node.cjs.production.min.js +0 -2
- package/dist/msal-node.cjs.production.min.js.map +0 -1
- package/dist/msal-node.esm.js +0 -2594
- package/dist/msal-node.esm.js.map +0 -1
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.0.0-
|
|
1
|
+
/*! @azure/msal-node v2.0.0-beta.0 2023-06-19 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
var msalCommon = require('@azure/msal-common');
|
|
6
6
|
|
|
7
|
-
/*
|
|
8
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
-
* Licensed under the MIT License.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* On-Behalf-Of client
|
|
13
|
-
*/
|
|
14
|
-
class OnBehalfOfClient extends msalCommon.BaseClient {
|
|
15
|
-
constructor(configuration) {
|
|
16
|
-
super(configuration);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Public API to acquire tokens with on behalf of flow
|
|
20
|
-
* @param request
|
|
21
|
-
*/
|
|
22
|
-
async acquireToken(request) {
|
|
23
|
-
this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
|
|
24
|
-
// generate the user_assertion_hash for OBOAssertion
|
|
25
|
-
this.userAssertionHash = await this.cryptoUtils.hashString(request.oboAssertion);
|
|
26
|
-
if (request.skipCache) {
|
|
27
|
-
return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
return await this.getCachedAuthenticationResult(request);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
// Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
|
|
34
|
-
return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* look up cache for tokens
|
|
39
|
-
* Find idtoken in the cache
|
|
40
|
-
* Find accessToken based on user assertion and account info in the cache
|
|
41
|
-
* Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires
|
|
42
|
-
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
|
43
|
-
* @param request
|
|
44
|
-
*/
|
|
45
|
-
async getCachedAuthenticationResult(request) {
|
|
46
|
-
// look in the cache for the access_token which matches the incoming_assertion
|
|
47
|
-
const cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
|
|
48
|
-
if (!cachedAccessToken) {
|
|
49
|
-
// Must refresh due to non-existent access_token.
|
|
50
|
-
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
51
|
-
this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
|
|
52
|
-
throw msalCommon.ClientAuthError.createRefreshRequiredError();
|
|
53
|
-
}
|
|
54
|
-
else if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
55
|
-
// Access token expired, will need to renewed
|
|
56
|
-
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
57
|
-
this.logger.info(`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);
|
|
58
|
-
throw msalCommon.ClientAuthError.createRefreshRequiredError();
|
|
59
|
-
}
|
|
60
|
-
// fetch the idToken from cache
|
|
61
|
-
const cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
|
|
62
|
-
let idTokenObject;
|
|
63
|
-
let cachedAccount = null;
|
|
64
|
-
if (cachedIdToken) {
|
|
65
|
-
idTokenObject = new msalCommon.AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
|
|
66
|
-
const localAccountId = idTokenObject.claims.oid
|
|
67
|
-
? idTokenObject.claims.oid
|
|
68
|
-
: idTokenObject.claims.sub;
|
|
69
|
-
const accountInfo = {
|
|
70
|
-
homeAccountId: cachedIdToken.homeAccountId,
|
|
71
|
-
environment: cachedIdToken.environment,
|
|
72
|
-
tenantId: cachedIdToken.realm,
|
|
73
|
-
username: msalCommon.Constants.EMPTY_STRING,
|
|
74
|
-
localAccountId: localAccountId || msalCommon.Constants.EMPTY_STRING,
|
|
75
|
-
};
|
|
76
|
-
cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
|
|
77
|
-
}
|
|
78
|
-
// increment telemetry cache hit counter
|
|
79
|
-
if (this.config.serverTelemetryManager) {
|
|
80
|
-
this.config.serverTelemetryManager.incrementCacheHits();
|
|
81
|
-
}
|
|
82
|
-
return await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
|
|
83
|
-
account: cachedAccount,
|
|
84
|
-
accessToken: cachedAccessToken,
|
|
85
|
-
idToken: cachedIdToken,
|
|
86
|
-
refreshToken: null,
|
|
87
|
-
appMetadata: null,
|
|
88
|
-
}, true, request, idTokenObject);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
|
92
|
-
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
93
|
-
* @param atHomeAccountId {string}
|
|
94
|
-
*/
|
|
95
|
-
readIdTokenFromCacheForOBO(atHomeAccountId) {
|
|
96
|
-
const idTokenFilter = {
|
|
97
|
-
homeAccountId: atHomeAccountId,
|
|
98
|
-
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
99
|
-
credentialType: msalCommon.CredentialType.ID_TOKEN,
|
|
100
|
-
clientId: this.config.authOptions.clientId,
|
|
101
|
-
realm: this.authority.tenant,
|
|
102
|
-
};
|
|
103
|
-
const idTokens = this.cacheManager.getIdTokensByFilter(idTokenFilter);
|
|
104
|
-
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
105
|
-
if (idTokens.length < 1) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
return idTokens[0];
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Fetches the cached access token based on incoming assertion
|
|
112
|
-
* @param clientId
|
|
113
|
-
* @param request
|
|
114
|
-
* @param userAssertionHash
|
|
115
|
-
*/
|
|
116
|
-
readAccessTokenFromCacheForOBO(clientId, request) {
|
|
117
|
-
const authScheme = request.authenticationScheme || msalCommon.AuthenticationScheme.BEARER;
|
|
118
|
-
/*
|
|
119
|
-
* Distinguish between Bearer and PoP/SSH token cache types
|
|
120
|
-
* Cast to lowercase to handle "bearer" from ADFS
|
|
121
|
-
*/
|
|
122
|
-
const credentialType = authScheme &&
|
|
123
|
-
authScheme.toLowerCase() !==
|
|
124
|
-
msalCommon.AuthenticationScheme.BEARER.toLowerCase()
|
|
125
|
-
? msalCommon.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
|
|
126
|
-
: msalCommon.CredentialType.ACCESS_TOKEN;
|
|
127
|
-
const accessTokenFilter = {
|
|
128
|
-
credentialType: credentialType,
|
|
129
|
-
clientId,
|
|
130
|
-
target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
131
|
-
tokenType: authScheme,
|
|
132
|
-
keyId: request.sshKid,
|
|
133
|
-
requestedClaimsHash: request.requestedClaimsHash,
|
|
134
|
-
userAssertionHash: this.userAssertionHash,
|
|
135
|
-
};
|
|
136
|
-
const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
137
|
-
const numAccessTokens = accessTokens.length;
|
|
138
|
-
if (numAccessTokens < 1) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
else if (numAccessTokens > 1) {
|
|
142
|
-
throw msalCommon.ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
143
|
-
}
|
|
144
|
-
return accessTokens[0];
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Make a network call to the server requesting credentials
|
|
148
|
-
* @param request
|
|
149
|
-
* @param authority
|
|
150
|
-
*/
|
|
151
|
-
async executeTokenRequest(request, authority, userAssertionHash) {
|
|
152
|
-
const queryParametersString = this.createTokenQueryParameters(request);
|
|
153
|
-
const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
154
|
-
const requestBody = this.createTokenRequestBody(request);
|
|
155
|
-
const headers = this.createTokenRequestHeaders();
|
|
156
|
-
const thumbprint = {
|
|
157
|
-
clientId: this.config.authOptions.clientId,
|
|
158
|
-
authority: request.authority,
|
|
159
|
-
scopes: request.scopes,
|
|
160
|
-
claims: request.claims,
|
|
161
|
-
authenticationScheme: request.authenticationScheme,
|
|
162
|
-
resourceRequestMethod: request.resourceRequestMethod,
|
|
163
|
-
resourceRequestUri: request.resourceRequestUri,
|
|
164
|
-
shrClaims: request.shrClaims,
|
|
165
|
-
sshKid: request.sshKid,
|
|
166
|
-
};
|
|
167
|
-
const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
|
|
168
|
-
const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);
|
|
169
|
-
const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
170
|
-
responseHandler.validateTokenResponse(response.body);
|
|
171
|
-
const tokenResponse = await responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash);
|
|
172
|
-
return tokenResponse;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* generate a server request in accepable format
|
|
176
|
-
* @param request
|
|
177
|
-
*/
|
|
178
|
-
createTokenRequestBody(request) {
|
|
179
|
-
const parameterBuilder = new msalCommon.RequestParameterBuilder();
|
|
180
|
-
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
181
|
-
parameterBuilder.addScopes(request.scopes);
|
|
182
|
-
parameterBuilder.addGrantType(msalCommon.GrantType.JWT_BEARER);
|
|
183
|
-
parameterBuilder.addClientInfo();
|
|
184
|
-
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
185
|
-
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
186
|
-
parameterBuilder.addThrottling();
|
|
187
|
-
if (this.serverTelemetryManager) {
|
|
188
|
-
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
189
|
-
}
|
|
190
|
-
const correlationId = request.correlationId ||
|
|
191
|
-
this.config.cryptoInterface.createNewGuid();
|
|
192
|
-
parameterBuilder.addCorrelationId(correlationId);
|
|
193
|
-
parameterBuilder.addRequestTokenUse(msalCommon.AADServerParamKeys.ON_BEHALF_OF);
|
|
194
|
-
parameterBuilder.addOboAssertion(request.oboAssertion);
|
|
195
|
-
if (this.config.clientCredentials.clientSecret) {
|
|
196
|
-
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
197
|
-
}
|
|
198
|
-
if (this.config.clientCredentials.clientAssertion) {
|
|
199
|
-
const clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
200
|
-
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
201
|
-
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
202
|
-
}
|
|
203
|
-
if (request.claims ||
|
|
204
|
-
(this.config.authOptions.clientCapabilities &&
|
|
205
|
-
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
206
|
-
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
207
|
-
}
|
|
208
|
-
return parameterBuilder.createQueryString();
|
|
209
|
-
}
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* On-Behalf-Of client
|
|
13
|
+
*/
|
|
14
|
+
class OnBehalfOfClient extends msalCommon.BaseClient {
|
|
15
|
+
constructor(configuration) {
|
|
16
|
+
super(configuration);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Public API to acquire tokens with on behalf of flow
|
|
20
|
+
* @param request
|
|
21
|
+
*/
|
|
22
|
+
async acquireToken(request) {
|
|
23
|
+
this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
|
|
24
|
+
// generate the user_assertion_hash for OBOAssertion
|
|
25
|
+
this.userAssertionHash = await this.cryptoUtils.hashString(request.oboAssertion);
|
|
26
|
+
if (request.skipCache) {
|
|
27
|
+
return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return await this.getCachedAuthenticationResult(request);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
|
|
34
|
+
return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* look up cache for tokens
|
|
39
|
+
* Find idtoken in the cache
|
|
40
|
+
* Find accessToken based on user assertion and account info in the cache
|
|
41
|
+
* Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires
|
|
42
|
+
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
|
43
|
+
* @param request
|
|
44
|
+
*/
|
|
45
|
+
async getCachedAuthenticationResult(request) {
|
|
46
|
+
// look in the cache for the access_token which matches the incoming_assertion
|
|
47
|
+
const cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
|
|
48
|
+
if (!cachedAccessToken) {
|
|
49
|
+
// Must refresh due to non-existent access_token.
|
|
50
|
+
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
51
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
|
|
52
|
+
throw msalCommon.ClientAuthError.createRefreshRequiredError();
|
|
53
|
+
}
|
|
54
|
+
else if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
55
|
+
// Access token expired, will need to renewed
|
|
56
|
+
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
57
|
+
this.logger.info(`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);
|
|
58
|
+
throw msalCommon.ClientAuthError.createRefreshRequiredError();
|
|
59
|
+
}
|
|
60
|
+
// fetch the idToken from cache
|
|
61
|
+
const cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
|
|
62
|
+
let idTokenObject;
|
|
63
|
+
let cachedAccount = null;
|
|
64
|
+
if (cachedIdToken) {
|
|
65
|
+
idTokenObject = new msalCommon.AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
|
|
66
|
+
const localAccountId = idTokenObject.claims.oid
|
|
67
|
+
? idTokenObject.claims.oid
|
|
68
|
+
: idTokenObject.claims.sub;
|
|
69
|
+
const accountInfo = {
|
|
70
|
+
homeAccountId: cachedIdToken.homeAccountId,
|
|
71
|
+
environment: cachedIdToken.environment,
|
|
72
|
+
tenantId: cachedIdToken.realm,
|
|
73
|
+
username: msalCommon.Constants.EMPTY_STRING,
|
|
74
|
+
localAccountId: localAccountId || msalCommon.Constants.EMPTY_STRING,
|
|
75
|
+
};
|
|
76
|
+
cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
|
|
77
|
+
}
|
|
78
|
+
// increment telemetry cache hit counter
|
|
79
|
+
if (this.config.serverTelemetryManager) {
|
|
80
|
+
this.config.serverTelemetryManager.incrementCacheHits();
|
|
81
|
+
}
|
|
82
|
+
return await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
|
|
83
|
+
account: cachedAccount,
|
|
84
|
+
accessToken: cachedAccessToken,
|
|
85
|
+
idToken: cachedIdToken,
|
|
86
|
+
refreshToken: null,
|
|
87
|
+
appMetadata: null,
|
|
88
|
+
}, true, request, idTokenObject);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
|
92
|
+
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
93
|
+
* @param atHomeAccountId {string}
|
|
94
|
+
*/
|
|
95
|
+
readIdTokenFromCacheForOBO(atHomeAccountId) {
|
|
96
|
+
const idTokenFilter = {
|
|
97
|
+
homeAccountId: atHomeAccountId,
|
|
98
|
+
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
99
|
+
credentialType: msalCommon.CredentialType.ID_TOKEN,
|
|
100
|
+
clientId: this.config.authOptions.clientId,
|
|
101
|
+
realm: this.authority.tenant,
|
|
102
|
+
};
|
|
103
|
+
const idTokens = this.cacheManager.getIdTokensByFilter(idTokenFilter);
|
|
104
|
+
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
105
|
+
if (idTokens.length < 1) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return idTokens[0];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fetches the cached access token based on incoming assertion
|
|
112
|
+
* @param clientId
|
|
113
|
+
* @param request
|
|
114
|
+
* @param userAssertionHash
|
|
115
|
+
*/
|
|
116
|
+
readAccessTokenFromCacheForOBO(clientId, request) {
|
|
117
|
+
const authScheme = request.authenticationScheme || msalCommon.AuthenticationScheme.BEARER;
|
|
118
|
+
/*
|
|
119
|
+
* Distinguish between Bearer and PoP/SSH token cache types
|
|
120
|
+
* Cast to lowercase to handle "bearer" from ADFS
|
|
121
|
+
*/
|
|
122
|
+
const credentialType = authScheme &&
|
|
123
|
+
authScheme.toLowerCase() !==
|
|
124
|
+
msalCommon.AuthenticationScheme.BEARER.toLowerCase()
|
|
125
|
+
? msalCommon.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
|
|
126
|
+
: msalCommon.CredentialType.ACCESS_TOKEN;
|
|
127
|
+
const accessTokenFilter = {
|
|
128
|
+
credentialType: credentialType,
|
|
129
|
+
clientId,
|
|
130
|
+
target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
131
|
+
tokenType: authScheme,
|
|
132
|
+
keyId: request.sshKid,
|
|
133
|
+
requestedClaimsHash: request.requestedClaimsHash,
|
|
134
|
+
userAssertionHash: this.userAssertionHash,
|
|
135
|
+
};
|
|
136
|
+
const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
137
|
+
const numAccessTokens = accessTokens.length;
|
|
138
|
+
if (numAccessTokens < 1) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
else if (numAccessTokens > 1) {
|
|
142
|
+
throw msalCommon.ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
143
|
+
}
|
|
144
|
+
return accessTokens[0];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Make a network call to the server requesting credentials
|
|
148
|
+
* @param request
|
|
149
|
+
* @param authority
|
|
150
|
+
*/
|
|
151
|
+
async executeTokenRequest(request, authority, userAssertionHash) {
|
|
152
|
+
const queryParametersString = this.createTokenQueryParameters(request);
|
|
153
|
+
const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
154
|
+
const requestBody = this.createTokenRequestBody(request);
|
|
155
|
+
const headers = this.createTokenRequestHeaders();
|
|
156
|
+
const thumbprint = {
|
|
157
|
+
clientId: this.config.authOptions.clientId,
|
|
158
|
+
authority: request.authority,
|
|
159
|
+
scopes: request.scopes,
|
|
160
|
+
claims: request.claims,
|
|
161
|
+
authenticationScheme: request.authenticationScheme,
|
|
162
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
163
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
164
|
+
shrClaims: request.shrClaims,
|
|
165
|
+
sshKid: request.sshKid,
|
|
166
|
+
};
|
|
167
|
+
const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
|
|
168
|
+
const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);
|
|
169
|
+
const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
170
|
+
responseHandler.validateTokenResponse(response.body);
|
|
171
|
+
const tokenResponse = await responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash);
|
|
172
|
+
return tokenResponse;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* generate a server request in accepable format
|
|
176
|
+
* @param request
|
|
177
|
+
*/
|
|
178
|
+
createTokenRequestBody(request) {
|
|
179
|
+
const parameterBuilder = new msalCommon.RequestParameterBuilder();
|
|
180
|
+
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
181
|
+
parameterBuilder.addScopes(request.scopes);
|
|
182
|
+
parameterBuilder.addGrantType(msalCommon.GrantType.JWT_BEARER);
|
|
183
|
+
parameterBuilder.addClientInfo();
|
|
184
|
+
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
185
|
+
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
186
|
+
parameterBuilder.addThrottling();
|
|
187
|
+
if (this.serverTelemetryManager) {
|
|
188
|
+
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
189
|
+
}
|
|
190
|
+
const correlationId = request.correlationId ||
|
|
191
|
+
this.config.cryptoInterface.createNewGuid();
|
|
192
|
+
parameterBuilder.addCorrelationId(correlationId);
|
|
193
|
+
parameterBuilder.addRequestTokenUse(msalCommon.AADServerParamKeys.ON_BEHALF_OF);
|
|
194
|
+
parameterBuilder.addOboAssertion(request.oboAssertion);
|
|
195
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
196
|
+
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
197
|
+
}
|
|
198
|
+
if (this.config.clientCredentials.clientAssertion) {
|
|
199
|
+
const clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
200
|
+
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
201
|
+
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
202
|
+
}
|
|
203
|
+
if (request.claims ||
|
|
204
|
+
(this.config.authOptions.clientCapabilities &&
|
|
205
|
+
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
206
|
+
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
207
|
+
}
|
|
208
|
+
return parameterBuilder.createQueryString();
|
|
209
|
+
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
exports.OnBehalfOfClient = OnBehalfOfClient;
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { AuthenticationResult, AccountInfo } from "@azure/msal-common";
|
|
2
|
-
import { Configuration } from "../config/Configuration";
|
|
3
|
-
import { ClientApplication } from "./ClientApplication";
|
|
4
|
-
import { IPublicClientApplication } from "./IPublicClientApplication";
|
|
5
|
-
import { DeviceCodeRequest } from "../request/DeviceCodeRequest";
|
|
6
|
-
import { InteractiveRequest } from "../request/InteractiveRequest";
|
|
7
|
-
import { SilentFlowRequest } from "../request/SilentFlowRequest";
|
|
8
|
-
import { SignOutRequest } from "../request/SignOutRequest";
|
|
9
|
-
/**
|
|
10
|
-
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
11
|
-
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export declare class PublicClientApplication extends ClientApplication implements IPublicClientApplication {
|
|
15
|
-
private nativeBrokerPlugin?;
|
|
16
|
-
/**
|
|
17
|
-
* Important attributes in the Configuration object for auth are:
|
|
18
|
-
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
19
|
-
* - authority: the authority URL for your application.
|
|
20
|
-
*
|
|
21
|
-
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
22
|
-
* - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
|
|
23
|
-
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
24
|
-
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
25
|
-
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
26
|
-
*
|
|
27
|
-
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
28
|
-
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
29
|
-
* construction.
|
|
30
|
-
*
|
|
31
|
-
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
32
|
-
*/
|
|
33
|
-
constructor(configuration: Configuration);
|
|
34
|
-
/**
|
|
35
|
-
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
36
|
-
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
37
|
-
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
38
|
-
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
39
|
-
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
40
|
-
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
41
|
-
* until the end-user completes input of credentials.
|
|
42
|
-
*/
|
|
43
|
-
acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
|
|
44
|
-
/**
|
|
45
|
-
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
46
|
-
*/
|
|
47
|
-
acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
|
|
48
|
-
/**
|
|
49
|
-
* Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
|
|
50
|
-
* @param request
|
|
51
|
-
* @returns
|
|
52
|
-
*/
|
|
53
|
-
acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
|
|
54
|
-
/**
|
|
55
|
-
* Removes cache artifacts associated with the given account
|
|
56
|
-
* @param request
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
signOut(request: SignOutRequest): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
getAllAccounts(): Promise<AccountInfo[]>;
|
|
65
|
-
}
|
|
1
|
+
import { AuthenticationResult, AccountInfo } from "@azure/msal-common";
|
|
2
|
+
import { Configuration } from "../config/Configuration";
|
|
3
|
+
import { ClientApplication } from "./ClientApplication";
|
|
4
|
+
import { IPublicClientApplication } from "./IPublicClientApplication";
|
|
5
|
+
import { DeviceCodeRequest } from "../request/DeviceCodeRequest";
|
|
6
|
+
import { InteractiveRequest } from "../request/InteractiveRequest";
|
|
7
|
+
import { SilentFlowRequest } from "../request/SilentFlowRequest";
|
|
8
|
+
import { SignOutRequest } from "../request/SignOutRequest";
|
|
9
|
+
/**
|
|
10
|
+
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
11
|
+
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare class PublicClientApplication extends ClientApplication implements IPublicClientApplication {
|
|
15
|
+
private nativeBrokerPlugin?;
|
|
16
|
+
/**
|
|
17
|
+
* Important attributes in the Configuration object for auth are:
|
|
18
|
+
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
19
|
+
* - authority: the authority URL for your application.
|
|
20
|
+
*
|
|
21
|
+
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
22
|
+
* - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
|
|
23
|
+
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
24
|
+
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
25
|
+
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
26
|
+
*
|
|
27
|
+
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
28
|
+
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
29
|
+
* construction.
|
|
30
|
+
*
|
|
31
|
+
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
32
|
+
*/
|
|
33
|
+
constructor(configuration: Configuration);
|
|
34
|
+
/**
|
|
35
|
+
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
36
|
+
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
37
|
+
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
38
|
+
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
39
|
+
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
40
|
+
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
41
|
+
* until the end-user completes input of credentials.
|
|
42
|
+
*/
|
|
43
|
+
acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
46
|
+
*/
|
|
47
|
+
acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
|
|
50
|
+
* @param request
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Removes cache artifacts associated with the given account
|
|
56
|
+
* @param request
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
signOut(request: SignOutRequest): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getAllAccounts(): Promise<AccountInfo[]>;
|
|
65
|
+
}
|
|
66
66
|
//# sourceMappingURL=PublicClientApplication.d.ts.map
|