@azure/msal-node 2.12.0 → 2.13.1
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/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +423 -423
- package/dist/cache/NodeStorage.d.ts +193 -193
- package/dist/cache/NodeStorage.mjs +423 -423
- package/dist/cache/TokenCache.cjs +265 -265
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.mjs +265 -265
- package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.mjs +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.cjs +167 -167
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.mjs +167 -167
- package/dist/cache/serializer/Serializer.cjs +137 -137
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.mjs +137 -137
- package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
- package/dist/client/ClientApplication.cjs +334 -334
- package/dist/client/ClientApplication.d.ts +143 -143
- package/dist/client/ClientApplication.mjs +334 -334
- package/dist/client/ClientAssertion.cjs +143 -143
- package/dist/client/ClientAssertion.d.ts +55 -55
- package/dist/client/ClientAssertion.mjs +143 -143
- package/dist/client/ClientCredentialClient.cjs +194 -194
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.mjs +194 -194
- package/dist/client/ConfidentialClientApplication.cjs +169 -169
- package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.mjs +169 -169
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.cjs +207 -207
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.mjs +207 -207
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/ManagedIdentityApplication.cjs +84 -84
- package/dist/client/ManagedIdentityApplication.d.ts +30 -30
- package/dist/client/ManagedIdentityApplication.mjs +84 -84
- package/dist/client/ManagedIdentityClient.cjs +60 -60
- package/dist/client/ManagedIdentityClient.d.ts +27 -27
- package/dist/client/ManagedIdentityClient.mjs +60 -60
- package/dist/client/ManagedIdentitySources/AppService.cjs +45 -45
- package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -17
- package/dist/client/ManagedIdentitySources/AppService.mjs +45 -45
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +155 -120
- package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +27 -23
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +155 -122
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +122 -122
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -30
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +122 -122
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +38 -38
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +16 -16
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +38 -38
- package/dist/client/ManagedIdentitySources/Imds.cjs +43 -43
- package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
- package/dist/client/ManagedIdentitySources/Imds.mjs +43 -43
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +54 -54
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +17 -17
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +54 -54
- package/dist/client/OnBehalfOfClient.cjs +202 -202
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.mjs +202 -202
- package/dist/client/PublicClientApplication.cjs +237 -237
- package/dist/client/PublicClientApplication.d.ts +72 -72
- package/dist/client/PublicClientApplication.mjs +237 -237
- package/dist/client/UsernamePasswordClient.cjs +95 -95
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/config/Configuration.cjs +106 -106
- package/dist/config/Configuration.d.ts +131 -131
- package/dist/config/Configuration.mjs +106 -106
- package/dist/config/ManagedIdentityId.cjs +48 -48
- package/dist/config/ManagedIdentityId.d.ts +11 -11
- package/dist/config/ManagedIdentityId.mjs +48 -48
- package/dist/config/ManagedIdentityRequestParameters.cjs +28 -28
- package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
- package/dist/config/ManagedIdentityRequestParameters.mjs +28 -28
- package/dist/crypto/CryptoProvider.cjs +89 -89
- package/dist/crypto/CryptoProvider.d.ts +62 -62
- package/dist/crypto/CryptoProvider.mjs +89 -89
- package/dist/crypto/GuidGenerator.cjs +22 -22
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/HashUtils.cjs +13 -13
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/PkceGenerator.cjs +49 -49
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/error/ManagedIdentityError.cjs +41 -41
- package/dist/error/ManagedIdentityError.d.ts +30 -30
- package/dist/error/ManagedIdentityError.mjs +41 -41
- package/dist/error/ManagedIdentityErrorCodes.cjs +24 -24
- package/dist/error/ManagedIdentityErrorCodes.d.ts +22 -22
- package/dist/error/ManagedIdentityErrorCodes.mjs +24 -24
- package/dist/error/NodeAuthError.cjs +95 -95
- package/dist/error/NodeAuthError.d.ts +73 -73
- package/dist/error/NodeAuthError.mjs +95 -95
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +45 -45
- package/dist/index.mjs +1 -1
- package/dist/internals.cjs +8 -8
- package/dist/internals.d.ts +6 -6
- package/dist/internals.mjs +8 -8
- package/dist/network/HttpClient.cjs +281 -281
- package/dist/network/HttpClient.d.ts +25 -25
- package/dist/network/HttpClient.mjs +281 -281
- package/dist/network/HttpClientWithRetries.cjs +34 -34
- package/dist/network/HttpClientWithRetries.d.ts +11 -11
- package/dist/network/HttpClientWithRetries.mjs +34 -34
- package/dist/network/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.cjs +81 -77
- 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 +81 -77
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +4 -4
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +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 -14
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- package/dist/request/ManagedIdentityRequest.d.ts +8 -8
- package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
- 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/response/ManagedIdentityTokenResponse.d.ts +34 -34
- package/dist/retry/IHttpRetryPolicy.d.ts +5 -5
- package/dist/retry/LinearRetryPolicy.cjs +40 -40
- package/dist/retry/LinearRetryPolicy.d.ts +11 -11
- package/dist/retry/LinearRetryPolicy.mjs +40 -40
- package/dist/utils/Constants.cjs +136 -136
- package/dist/utils/Constants.d.ts +141 -141
- package/dist/utils/Constants.mjs +136 -136
- package/dist/utils/EncodingUtils.cjs +44 -44
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/NetworkUtils.cjs +38 -38
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/package.json +2 -2
- package/src/client/ConfidentialClientApplication.ts +3 -3
- package/src/client/ManagedIdentitySources/AzureArc.ts +80 -25
- package/src/network/LoopbackClient.ts +7 -1
- package/src/packageMetadata.ts +1 -1
|
@@ -1,211 +1,211 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.13.1 2024-08-29 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
var msalCommon = require('@azure/msal-common');
|
|
6
6
|
var EncodingUtils = require('../utils/EncodingUtils.cjs');
|
|
7
7
|
|
|
8
|
-
/*
|
|
9
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
-
* Licensed under the MIT License.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* On-Behalf-Of client
|
|
14
|
-
*/
|
|
15
|
-
class OnBehalfOfClient extends msalCommon.BaseClient {
|
|
16
|
-
constructor(configuration) {
|
|
17
|
-
super(configuration);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Public API to acquire tokens with on behalf of flow
|
|
21
|
-
* @param request
|
|
22
|
-
*/
|
|
23
|
-
async acquireToken(request) {
|
|
24
|
-
this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
|
|
25
|
-
// generate the user_assertion_hash for OBOAssertion
|
|
26
|
-
this.userAssertionHash = await this.cryptoUtils.hashString(request.oboAssertion);
|
|
27
|
-
if (request.skipCache || request.claims) {
|
|
28
|
-
return this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
return await this.getCachedAuthenticationResult(request);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
// Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
|
|
35
|
-
return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* look up cache for tokens
|
|
40
|
-
* Find idtoken in the cache
|
|
41
|
-
* Find accessToken based on user assertion and account info in the cache
|
|
42
|
-
* 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
|
|
43
|
-
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
|
44
|
-
* @param request
|
|
45
|
-
*/
|
|
46
|
-
async getCachedAuthenticationResult(request) {
|
|
47
|
-
// look in the cache for the access_token which matches the incoming_assertion
|
|
48
|
-
const cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
|
|
49
|
-
if (!cachedAccessToken) {
|
|
50
|
-
// Must refresh due to non-existent access_token.
|
|
51
|
-
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
52
|
-
this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
|
|
53
|
-
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.tokenRefreshRequired);
|
|
54
|
-
}
|
|
55
|
-
else if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
56
|
-
// Access token expired, will need to renewed
|
|
57
|
-
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
58
|
-
this.logger.info(`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);
|
|
59
|
-
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.tokenRefreshRequired);
|
|
60
|
-
}
|
|
61
|
-
// fetch the idToken from cache
|
|
62
|
-
const cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
|
|
63
|
-
let idTokenClaims;
|
|
64
|
-
let cachedAccount = null;
|
|
65
|
-
if (cachedIdToken) {
|
|
66
|
-
idTokenClaims = msalCommon.AuthToken.extractTokenClaims(cachedIdToken.secret, EncodingUtils.EncodingUtils.base64Decode);
|
|
67
|
-
const localAccountId = idTokenClaims.oid || idTokenClaims.sub;
|
|
68
|
-
const accountInfo = {
|
|
69
|
-
homeAccountId: cachedIdToken.homeAccountId,
|
|
70
|
-
environment: cachedIdToken.environment,
|
|
71
|
-
tenantId: cachedIdToken.realm,
|
|
72
|
-
username: msalCommon.Constants.EMPTY_STRING,
|
|
73
|
-
localAccountId: localAccountId || msalCommon.Constants.EMPTY_STRING,
|
|
74
|
-
};
|
|
75
|
-
cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
|
|
76
|
-
}
|
|
77
|
-
// increment telemetry cache hit counter
|
|
78
|
-
if (this.config.serverTelemetryManager) {
|
|
79
|
-
this.config.serverTelemetryManager.incrementCacheHits();
|
|
80
|
-
}
|
|
81
|
-
return msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
|
|
82
|
-
account: cachedAccount,
|
|
83
|
-
accessToken: cachedAccessToken,
|
|
84
|
-
idToken: cachedIdToken,
|
|
85
|
-
refreshToken: null,
|
|
86
|
-
appMetadata: null,
|
|
87
|
-
}, true, request, idTokenClaims);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
|
91
|
-
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
92
|
-
* @param atHomeAccountId {string}
|
|
93
|
-
*/
|
|
94
|
-
readIdTokenFromCacheForOBO(atHomeAccountId) {
|
|
95
|
-
const idTokenFilter = {
|
|
96
|
-
homeAccountId: atHomeAccountId,
|
|
97
|
-
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
98
|
-
credentialType: msalCommon.CredentialType.ID_TOKEN,
|
|
99
|
-
clientId: this.config.authOptions.clientId,
|
|
100
|
-
realm: this.authority.tenant,
|
|
101
|
-
};
|
|
102
|
-
const idTokenMap = this.cacheManager.getIdTokensByFilter(idTokenFilter);
|
|
103
|
-
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
104
|
-
if (Object.values(idTokenMap).length < 1) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
return Object.values(idTokenMap)[0];
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Fetches the cached access token based on incoming assertion
|
|
111
|
-
* @param clientId
|
|
112
|
-
* @param request
|
|
113
|
-
* @param userAssertionHash
|
|
114
|
-
*/
|
|
115
|
-
readAccessTokenFromCacheForOBO(clientId, request) {
|
|
116
|
-
const authScheme = request.authenticationScheme || msalCommon.AuthenticationScheme.BEARER;
|
|
117
|
-
/*
|
|
118
|
-
* Distinguish between Bearer and PoP/SSH token cache types
|
|
119
|
-
* Cast to lowercase to handle "bearer" from ADFS
|
|
120
|
-
*/
|
|
121
|
-
const credentialType = authScheme &&
|
|
122
|
-
authScheme.toLowerCase() !==
|
|
123
|
-
msalCommon.AuthenticationScheme.BEARER.toLowerCase()
|
|
124
|
-
? msalCommon.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
|
|
125
|
-
: msalCommon.CredentialType.ACCESS_TOKEN;
|
|
126
|
-
const accessTokenFilter = {
|
|
127
|
-
credentialType: credentialType,
|
|
128
|
-
clientId,
|
|
129
|
-
target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
130
|
-
tokenType: authScheme,
|
|
131
|
-
keyId: request.sshKid,
|
|
132
|
-
requestedClaimsHash: request.requestedClaimsHash,
|
|
133
|
-
userAssertionHash: this.userAssertionHash,
|
|
134
|
-
};
|
|
135
|
-
const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
136
|
-
const numAccessTokens = accessTokens.length;
|
|
137
|
-
if (numAccessTokens < 1) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
else if (numAccessTokens > 1) {
|
|
141
|
-
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.multipleMatchingTokens);
|
|
142
|
-
}
|
|
143
|
-
return accessTokens[0];
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Make a network call to the server requesting credentials
|
|
147
|
-
* @param request
|
|
148
|
-
* @param authority
|
|
149
|
-
*/
|
|
150
|
-
async executeTokenRequest(request, authority, userAssertionHash) {
|
|
151
|
-
const queryParametersString = this.createTokenQueryParameters(request);
|
|
152
|
-
const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
153
|
-
const requestBody = await this.createTokenRequestBody(request);
|
|
154
|
-
const headers = this.createTokenRequestHeaders();
|
|
155
|
-
const thumbprint = {
|
|
156
|
-
clientId: this.config.authOptions.clientId,
|
|
157
|
-
authority: request.authority,
|
|
158
|
-
scopes: request.scopes,
|
|
159
|
-
claims: request.claims,
|
|
160
|
-
authenticationScheme: request.authenticationScheme,
|
|
161
|
-
resourceRequestMethod: request.resourceRequestMethod,
|
|
162
|
-
resourceRequestUri: request.resourceRequestUri,
|
|
163
|
-
shrClaims: request.shrClaims,
|
|
164
|
-
sshKid: request.sshKid,
|
|
165
|
-
};
|
|
166
|
-
const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
|
|
167
|
-
const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
168
|
-
const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
169
|
-
responseHandler.validateTokenResponse(response.body);
|
|
170
|
-
const tokenResponse = await responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash);
|
|
171
|
-
return tokenResponse;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* generate a server request in accepable format
|
|
175
|
-
* @param request
|
|
176
|
-
*/
|
|
177
|
-
async createTokenRequestBody(request) {
|
|
178
|
-
const parameterBuilder = new msalCommon.RequestParameterBuilder();
|
|
179
|
-
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
180
|
-
parameterBuilder.addScopes(request.scopes);
|
|
181
|
-
parameterBuilder.addGrantType(msalCommon.GrantType.JWT_BEARER);
|
|
182
|
-
parameterBuilder.addClientInfo();
|
|
183
|
-
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
184
|
-
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
185
|
-
parameterBuilder.addThrottling();
|
|
186
|
-
if (this.serverTelemetryManager) {
|
|
187
|
-
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
188
|
-
}
|
|
189
|
-
const correlationId = request.correlationId ||
|
|
190
|
-
this.config.cryptoInterface.createNewGuid();
|
|
191
|
-
parameterBuilder.addCorrelationId(correlationId);
|
|
192
|
-
parameterBuilder.addRequestTokenUse(msalCommon.AADServerParamKeys.ON_BEHALF_OF);
|
|
193
|
-
parameterBuilder.addOboAssertion(request.oboAssertion);
|
|
194
|
-
if (this.config.clientCredentials.clientSecret) {
|
|
195
|
-
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
196
|
-
}
|
|
197
|
-
const clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
198
|
-
if (clientAssertion) {
|
|
199
|
-
parameterBuilder.addClientAssertion(await msalCommon.getClientAssertion(clientAssertion.assertion, this.config.authOptions.clientId, request.resourceRequestUri));
|
|
200
|
-
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
201
|
-
}
|
|
202
|
-
if (request.claims ||
|
|
203
|
-
(this.config.authOptions.clientCapabilities &&
|
|
204
|
-
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
205
|
-
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
206
|
-
}
|
|
207
|
-
return parameterBuilder.createQueryString();
|
|
208
|
-
}
|
|
8
|
+
/*
|
|
9
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
+
* Licensed under the MIT License.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* On-Behalf-Of client
|
|
14
|
+
*/
|
|
15
|
+
class OnBehalfOfClient extends msalCommon.BaseClient {
|
|
16
|
+
constructor(configuration) {
|
|
17
|
+
super(configuration);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Public API to acquire tokens with on behalf of flow
|
|
21
|
+
* @param request
|
|
22
|
+
*/
|
|
23
|
+
async acquireToken(request) {
|
|
24
|
+
this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
|
|
25
|
+
// generate the user_assertion_hash for OBOAssertion
|
|
26
|
+
this.userAssertionHash = await this.cryptoUtils.hashString(request.oboAssertion);
|
|
27
|
+
if (request.skipCache || request.claims) {
|
|
28
|
+
return this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return await this.getCachedAuthenticationResult(request);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
|
|
35
|
+
return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* look up cache for tokens
|
|
40
|
+
* Find idtoken in the cache
|
|
41
|
+
* Find accessToken based on user assertion and account info in the cache
|
|
42
|
+
* 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
|
|
43
|
+
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
|
44
|
+
* @param request
|
|
45
|
+
*/
|
|
46
|
+
async getCachedAuthenticationResult(request) {
|
|
47
|
+
// look in the cache for the access_token which matches the incoming_assertion
|
|
48
|
+
const cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
|
|
49
|
+
if (!cachedAccessToken) {
|
|
50
|
+
// Must refresh due to non-existent access_token.
|
|
51
|
+
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
52
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
|
|
53
|
+
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.tokenRefreshRequired);
|
|
54
|
+
}
|
|
55
|
+
else if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
56
|
+
// Access token expired, will need to renewed
|
|
57
|
+
this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
58
|
+
this.logger.info(`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);
|
|
59
|
+
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.tokenRefreshRequired);
|
|
60
|
+
}
|
|
61
|
+
// fetch the idToken from cache
|
|
62
|
+
const cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
|
|
63
|
+
let idTokenClaims;
|
|
64
|
+
let cachedAccount = null;
|
|
65
|
+
if (cachedIdToken) {
|
|
66
|
+
idTokenClaims = msalCommon.AuthToken.extractTokenClaims(cachedIdToken.secret, EncodingUtils.EncodingUtils.base64Decode);
|
|
67
|
+
const localAccountId = idTokenClaims.oid || idTokenClaims.sub;
|
|
68
|
+
const accountInfo = {
|
|
69
|
+
homeAccountId: cachedIdToken.homeAccountId,
|
|
70
|
+
environment: cachedIdToken.environment,
|
|
71
|
+
tenantId: cachedIdToken.realm,
|
|
72
|
+
username: msalCommon.Constants.EMPTY_STRING,
|
|
73
|
+
localAccountId: localAccountId || msalCommon.Constants.EMPTY_STRING,
|
|
74
|
+
};
|
|
75
|
+
cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
|
|
76
|
+
}
|
|
77
|
+
// increment telemetry cache hit counter
|
|
78
|
+
if (this.config.serverTelemetryManager) {
|
|
79
|
+
this.config.serverTelemetryManager.incrementCacheHits();
|
|
80
|
+
}
|
|
81
|
+
return msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
|
|
82
|
+
account: cachedAccount,
|
|
83
|
+
accessToken: cachedAccessToken,
|
|
84
|
+
idToken: cachedIdToken,
|
|
85
|
+
refreshToken: null,
|
|
86
|
+
appMetadata: null,
|
|
87
|
+
}, true, request, idTokenClaims);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
|
91
|
+
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
92
|
+
* @param atHomeAccountId {string}
|
|
93
|
+
*/
|
|
94
|
+
readIdTokenFromCacheForOBO(atHomeAccountId) {
|
|
95
|
+
const idTokenFilter = {
|
|
96
|
+
homeAccountId: atHomeAccountId,
|
|
97
|
+
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
98
|
+
credentialType: msalCommon.CredentialType.ID_TOKEN,
|
|
99
|
+
clientId: this.config.authOptions.clientId,
|
|
100
|
+
realm: this.authority.tenant,
|
|
101
|
+
};
|
|
102
|
+
const idTokenMap = this.cacheManager.getIdTokensByFilter(idTokenFilter);
|
|
103
|
+
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
104
|
+
if (Object.values(idTokenMap).length < 1) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return Object.values(idTokenMap)[0];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Fetches the cached access token based on incoming assertion
|
|
111
|
+
* @param clientId
|
|
112
|
+
* @param request
|
|
113
|
+
* @param userAssertionHash
|
|
114
|
+
*/
|
|
115
|
+
readAccessTokenFromCacheForOBO(clientId, request) {
|
|
116
|
+
const authScheme = request.authenticationScheme || msalCommon.AuthenticationScheme.BEARER;
|
|
117
|
+
/*
|
|
118
|
+
* Distinguish between Bearer and PoP/SSH token cache types
|
|
119
|
+
* Cast to lowercase to handle "bearer" from ADFS
|
|
120
|
+
*/
|
|
121
|
+
const credentialType = authScheme &&
|
|
122
|
+
authScheme.toLowerCase() !==
|
|
123
|
+
msalCommon.AuthenticationScheme.BEARER.toLowerCase()
|
|
124
|
+
? msalCommon.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
|
|
125
|
+
: msalCommon.CredentialType.ACCESS_TOKEN;
|
|
126
|
+
const accessTokenFilter = {
|
|
127
|
+
credentialType: credentialType,
|
|
128
|
+
clientId,
|
|
129
|
+
target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
130
|
+
tokenType: authScheme,
|
|
131
|
+
keyId: request.sshKid,
|
|
132
|
+
requestedClaimsHash: request.requestedClaimsHash,
|
|
133
|
+
userAssertionHash: this.userAssertionHash,
|
|
134
|
+
};
|
|
135
|
+
const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
136
|
+
const numAccessTokens = accessTokens.length;
|
|
137
|
+
if (numAccessTokens < 1) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
else if (numAccessTokens > 1) {
|
|
141
|
+
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.multipleMatchingTokens);
|
|
142
|
+
}
|
|
143
|
+
return accessTokens[0];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Make a network call to the server requesting credentials
|
|
147
|
+
* @param request
|
|
148
|
+
* @param authority
|
|
149
|
+
*/
|
|
150
|
+
async executeTokenRequest(request, authority, userAssertionHash) {
|
|
151
|
+
const queryParametersString = this.createTokenQueryParameters(request);
|
|
152
|
+
const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
153
|
+
const requestBody = await this.createTokenRequestBody(request);
|
|
154
|
+
const headers = this.createTokenRequestHeaders();
|
|
155
|
+
const thumbprint = {
|
|
156
|
+
clientId: this.config.authOptions.clientId,
|
|
157
|
+
authority: request.authority,
|
|
158
|
+
scopes: request.scopes,
|
|
159
|
+
claims: request.claims,
|
|
160
|
+
authenticationScheme: request.authenticationScheme,
|
|
161
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
162
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
163
|
+
shrClaims: request.shrClaims,
|
|
164
|
+
sshKid: request.sshKid,
|
|
165
|
+
};
|
|
166
|
+
const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
|
|
167
|
+
const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
168
|
+
const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
169
|
+
responseHandler.validateTokenResponse(response.body);
|
|
170
|
+
const tokenResponse = await responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash);
|
|
171
|
+
return tokenResponse;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* generate a server request in accepable format
|
|
175
|
+
* @param request
|
|
176
|
+
*/
|
|
177
|
+
async createTokenRequestBody(request) {
|
|
178
|
+
const parameterBuilder = new msalCommon.RequestParameterBuilder();
|
|
179
|
+
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
180
|
+
parameterBuilder.addScopes(request.scopes);
|
|
181
|
+
parameterBuilder.addGrantType(msalCommon.GrantType.JWT_BEARER);
|
|
182
|
+
parameterBuilder.addClientInfo();
|
|
183
|
+
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
184
|
+
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
185
|
+
parameterBuilder.addThrottling();
|
|
186
|
+
if (this.serverTelemetryManager) {
|
|
187
|
+
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
188
|
+
}
|
|
189
|
+
const correlationId = request.correlationId ||
|
|
190
|
+
this.config.cryptoInterface.createNewGuid();
|
|
191
|
+
parameterBuilder.addCorrelationId(correlationId);
|
|
192
|
+
parameterBuilder.addRequestTokenUse(msalCommon.AADServerParamKeys.ON_BEHALF_OF);
|
|
193
|
+
parameterBuilder.addOboAssertion(request.oboAssertion);
|
|
194
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
195
|
+
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
196
|
+
}
|
|
197
|
+
const clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
198
|
+
if (clientAssertion) {
|
|
199
|
+
parameterBuilder.addClientAssertion(await msalCommon.getClientAssertion(clientAssertion.assertion, this.config.authOptions.clientId, request.resourceRequestUri));
|
|
200
|
+
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
201
|
+
}
|
|
202
|
+
if (request.claims ||
|
|
203
|
+
(this.config.authOptions.clientCapabilities &&
|
|
204
|
+
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
205
|
+
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
206
|
+
}
|
|
207
|
+
return parameterBuilder.createQueryString();
|
|
208
|
+
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
exports.OnBehalfOfClient = OnBehalfOfClient;
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { AuthenticationResult, BaseClient, ClientConfiguration, CommonOnBehalfOfRequest } from "@azure/msal-common";
|
|
2
|
-
/**
|
|
3
|
-
* On-Behalf-Of client
|
|
4
|
-
*/
|
|
5
|
-
export declare class OnBehalfOfClient extends BaseClient {
|
|
6
|
-
private scopeSet;
|
|
7
|
-
private userAssertionHash;
|
|
8
|
-
constructor(configuration: ClientConfiguration);
|
|
9
|
-
/**
|
|
10
|
-
* Public API to acquire tokens with on behalf of flow
|
|
11
|
-
* @param request
|
|
12
|
-
*/
|
|
13
|
-
acquireToken(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null>;
|
|
14
|
-
/**
|
|
15
|
-
* look up cache for tokens
|
|
16
|
-
* Find idtoken in the cache
|
|
17
|
-
* Find accessToken based on user assertion and account info in the cache
|
|
18
|
-
* 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
|
|
19
|
-
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
|
20
|
-
* @param request
|
|
21
|
-
*/
|
|
22
|
-
private getCachedAuthenticationResult;
|
|
23
|
-
/**
|
|
24
|
-
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
|
25
|
-
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
26
|
-
* @param atHomeAccountId {string}
|
|
27
|
-
*/
|
|
28
|
-
private readIdTokenFromCacheForOBO;
|
|
29
|
-
/**
|
|
30
|
-
* Fetches the cached access token based on incoming assertion
|
|
31
|
-
* @param clientId
|
|
32
|
-
* @param request
|
|
33
|
-
* @param userAssertionHash
|
|
34
|
-
*/
|
|
35
|
-
private readAccessTokenFromCacheForOBO;
|
|
36
|
-
/**
|
|
37
|
-
* Make a network call to the server requesting credentials
|
|
38
|
-
* @param request
|
|
39
|
-
* @param authority
|
|
40
|
-
*/
|
|
41
|
-
private executeTokenRequest;
|
|
42
|
-
/**
|
|
43
|
-
* generate a server request in accepable format
|
|
44
|
-
* @param request
|
|
45
|
-
*/
|
|
46
|
-
private createTokenRequestBody;
|
|
47
|
-
}
|
|
1
|
+
import { AuthenticationResult, BaseClient, ClientConfiguration, CommonOnBehalfOfRequest } from "@azure/msal-common";
|
|
2
|
+
/**
|
|
3
|
+
* On-Behalf-Of client
|
|
4
|
+
*/
|
|
5
|
+
export declare class OnBehalfOfClient extends BaseClient {
|
|
6
|
+
private scopeSet;
|
|
7
|
+
private userAssertionHash;
|
|
8
|
+
constructor(configuration: ClientConfiguration);
|
|
9
|
+
/**
|
|
10
|
+
* Public API to acquire tokens with on behalf of flow
|
|
11
|
+
* @param request
|
|
12
|
+
*/
|
|
13
|
+
acquireToken(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null>;
|
|
14
|
+
/**
|
|
15
|
+
* look up cache for tokens
|
|
16
|
+
* Find idtoken in the cache
|
|
17
|
+
* Find accessToken based on user assertion and account info in the cache
|
|
18
|
+
* 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
|
|
19
|
+
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
|
20
|
+
* @param request
|
|
21
|
+
*/
|
|
22
|
+
private getCachedAuthenticationResult;
|
|
23
|
+
/**
|
|
24
|
+
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
|
25
|
+
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
26
|
+
* @param atHomeAccountId {string}
|
|
27
|
+
*/
|
|
28
|
+
private readIdTokenFromCacheForOBO;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches the cached access token based on incoming assertion
|
|
31
|
+
* @param clientId
|
|
32
|
+
* @param request
|
|
33
|
+
* @param userAssertionHash
|
|
34
|
+
*/
|
|
35
|
+
private readAccessTokenFromCacheForOBO;
|
|
36
|
+
/**
|
|
37
|
+
* Make a network call to the server requesting credentials
|
|
38
|
+
* @param request
|
|
39
|
+
* @param authority
|
|
40
|
+
*/
|
|
41
|
+
private executeTokenRequest;
|
|
42
|
+
/**
|
|
43
|
+
* generate a server request in accepable format
|
|
44
|
+
* @param request
|
|
45
|
+
*/
|
|
46
|
+
private createTokenRequestBody;
|
|
47
|
+
}
|
|
48
48
|
//# sourceMappingURL=OnBehalfOfClient.d.ts.map
|