@azure/msal-node 5.2.4 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/CacheHelpers.mjs +16 -1
- package/dist/cache/CacheHelpers.mjs.map +1 -1
- package/dist/cache/NodeStorage.mjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
- package/dist/cache/serializer/Deserializer.mjs +2 -1
- package/dist/cache/serializer/Deserializer.mjs.map +1 -1
- package/dist/cache/serializer/Serializer.mjs +2 -1
- package/dist/cache/serializer/Serializer.mjs.map +1 -1
- package/dist/client/BaseClient.mjs +1 -1
- package/dist/client/ClientApplication.mjs +9 -9
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.mjs +2 -2
- package/dist/client/ClientAssertion.mjs.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +34 -16
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +61 -8
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.mjs +17 -16
- package/dist/client/DeviceCodeClient.mjs.map +1 -1
- package/dist/client/ManagedIdentityApplication.mjs +2 -2
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
- package/dist/client/ManagedIdentityClient.mjs +2 -2
- package/dist/client/ManagedIdentityClient.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +11 -11
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +6 -5
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +2 -2
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +1 -1
- package/dist/client/OnBehalfOfClient.mjs +9 -9
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- package/dist/client/PublicClientApplication.mjs +10 -9
- package/dist/client/PublicClientApplication.mjs.map +1 -1
- package/dist/client/UserFederatedIdentityCredentialClient.mjs +107 -0
- package/dist/client/UserFederatedIdentityCredentialClient.mjs.map +1 -0
- package/dist/client/UsernamePasswordClient.mjs +3 -3
- package/dist/client/UsernamePasswordClient.mjs.map +1 -1
- package/dist/config/Configuration.mjs +1 -1
- package/dist/config/ManagedIdentityId.mjs +4 -4
- package/dist/config/ManagedIdentityId.mjs.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
- package/dist/crypto/CryptoProvider.mjs +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/error/ClientAuthErrorCodes.mjs +5 -2
- package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
- package/dist/error/ManagedIdentityError.mjs +5 -5
- package/dist/error/ManagedIdentityError.mjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +1 -1
- package/dist/error/NodeAuthError.mjs +16 -16
- package/dist/error/NodeAuthError.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/network/HttpClient.mjs +4 -4
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/HttpClientWithRetries.mjs +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/protocol/Authorize.mjs +1 -1
- package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs +1 -1
- package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
- package/dist/retry/ImdsRetryPolicy.mjs +1 -1
- package/dist/retry/LinearRetryStrategy.mjs +1 -1
- package/dist/utils/Constants.mjs +2 -1
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/lib/msal-node.cjs +778 -521
- package/lib/msal-node.cjs.map +1 -1
- package/package.json +4 -4
- package/src/cache/CacheHelpers.ts +25 -0
- package/src/cache/serializer/Deserializer.ts +2 -0
- package/src/cache/serializer/Serializer.ts +2 -0
- package/src/cache/serializer/SerializerTypes.ts +1 -0
- package/src/client/ClientApplication.ts +19 -8
- package/src/client/ClientAssertion.ts +4 -1
- package/src/client/ClientCredentialClient.ts +61 -14
- package/src/client/ConfidentialClientApplication.ts +108 -6
- package/src/client/DeviceCodeClient.ts +28 -10
- package/src/client/ManagedIdentityApplication.ts +2 -1
- package/src/client/ManagedIdentityClient.ts +2 -1
- package/src/client/ManagedIdentitySources/AzureArc.ts +20 -10
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +10 -4
- package/src/client/ManagedIdentitySources/CloudShell.ts +2 -1
- package/src/client/OnBehalfOfClient.ts +22 -7
- package/src/client/PublicClientApplication.ts +23 -7
- package/src/client/UserFederatedIdentityCredentialClient.ts +226 -0
- package/src/client/UsernamePasswordClient.ts +6 -1
- package/src/config/ManagedIdentityId.ts +6 -3
- package/src/error/ClientAuthErrorCodes.ts +3 -0
- package/src/error/ManagedIdentityError.ts +9 -4
- package/src/error/NodeAuthError.ts +25 -6
- package/src/index.ts +1 -0
- package/src/network/HttpClient.ts +3 -0
- package/src/packageMetadata.ts +1 -1
- package/src/request/CommonClientCredentialRequest.ts +4 -0
- package/src/request/CommonUserFederatedIdentityCredentialRequest.ts +25 -0
- package/src/request/UserFederatedIdentityCredentialRequest.ts +46 -0
- package/src/utils/Constants.ts +1 -0
- package/types/cache/CacheHelpers.d.ts.map +1 -1
- package/types/cache/serializer/Deserializer.d.ts.map +1 -1
- package/types/cache/serializer/Serializer.d.ts.map +1 -1
- package/types/cache/serializer/SerializerTypes.d.ts +1 -0
- package/types/cache/serializer/SerializerTypes.d.ts.map +1 -1
- package/types/client/ClientApplication.d.ts +1 -1
- package/types/client/ClientApplication.d.ts.map +1 -1
- package/types/client/ClientAssertion.d.ts.map +1 -1
- package/types/client/ClientCredentialClient.d.ts +1 -1
- package/types/client/ClientCredentialClient.d.ts.map +1 -1
- package/types/client/ConfidentialClientApplication.d.ts +10 -0
- package/types/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/types/client/DeviceCodeClient.d.ts +1 -0
- package/types/client/DeviceCodeClient.d.ts.map +1 -1
- package/types/client/ManagedIdentityApplication.d.ts.map +1 -1
- package/types/client/ManagedIdentityClient.d.ts.map +1 -1
- package/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/types/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/types/client/OnBehalfOfClient.d.ts.map +1 -1
- package/types/client/PublicClientApplication.d.ts +1 -0
- package/types/client/PublicClientApplication.d.ts.map +1 -1
- package/types/client/UserFederatedIdentityCredentialClient.d.ts +26 -0
- package/types/client/UserFederatedIdentityCredentialClient.d.ts.map +1 -0
- package/types/client/UsernamePasswordClient.d.ts.map +1 -1
- package/types/config/ManagedIdentityId.d.ts.map +1 -1
- package/types/error/ClientAuthErrorCodes.d.ts +3 -0
- package/types/error/ClientAuthErrorCodes.d.ts.map +1 -1
- package/types/error/ManagedIdentityError.d.ts +2 -2
- package/types/error/ManagedIdentityError.d.ts.map +1 -1
- package/types/error/NodeAuthError.d.ts +5 -5
- package/types/error/NodeAuthError.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/network/HttpClient.d.ts.map +1 -1
- package/types/packageMetadata.d.ts +1 -1
- package/types/request/CommonClientCredentialRequest.d.ts +4 -0
- package/types/request/CommonClientCredentialRequest.d.ts.map +1 -1
- package/types/request/CommonUserFederatedIdentityCredentialRequest.d.ts +17 -0
- package/types/request/CommonUserFederatedIdentityCredentialRequest.d.ts.map +1 -0
- package/types/request/UserFederatedIdentityCredentialRequest.d.ts +32 -0
- package/types/request/UserFederatedIdentityCredentialRequest.d.ts.map +1 -0
- package/types/utils/Constants.d.ts +1 -0
- package/types/utils/Constants.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@azure/msal-node",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.3.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Microsoft",
|
|
7
7
|
"email": "nugetaad@microsoft.com",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
]
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@microsoft/api-extractor": "^7.
|
|
69
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
70
70
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
71
71
|
"@rollup/plugin-typescript": "^11.0.0",
|
|
72
72
|
"@types/jest": "^29.5.0",
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"prettier": "2.8.7",
|
|
79
79
|
"rollup": "^4.22.4",
|
|
80
80
|
"rollup-msal": "file:../../shared-configs/rollup-msal",
|
|
81
|
-
"ts-jest": "^29.
|
|
81
|
+
"ts-jest": "^29.4.11",
|
|
82
82
|
"tslib": "^1.10.0",
|
|
83
83
|
"typescript": "^4.9.5",
|
|
84
84
|
"yargs": "^17.3.1"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@azure/msal-common": "16.
|
|
87
|
+
"@azure/msal-common": "16.10.0",
|
|
88
88
|
"jsonwebtoken": "^9.0.0"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
@@ -8,8 +8,21 @@ import {
|
|
|
8
8
|
Constants,
|
|
9
9
|
CredentialEntity,
|
|
10
10
|
} from "@azure/msal-common/node";
|
|
11
|
+
import { createHash } from "crypto";
|
|
11
12
|
import { CACHE } from "../utils/Constants.js";
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Computes a combined hash from additional cache key components.
|
|
16
|
+
* Matches the cross-SDK algorithm: sort keys → concatenate key+value → SHA-256 → Base64URL (no padding).
|
|
17
|
+
*/
|
|
18
|
+
function computeAdditionalCacheKeyHash(
|
|
19
|
+
components: Record<string, string>
|
|
20
|
+
): string {
|
|
21
|
+
const sortedKeys = Object.keys(components).sort();
|
|
22
|
+
const input = sortedKeys.map((k) => k + components[k]).join("");
|
|
23
|
+
return createHash("sha256").update(input, "utf8").digest("base64url");
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
export function generateCredentialKey(credential: CredentialEntity): string {
|
|
14
27
|
const familyId =
|
|
15
28
|
(credential.credentialType === Constants.CredentialType.REFRESH_TOKEN &&
|
|
@@ -31,6 +44,18 @@ export function generateCredentialKey(credential: CredentialEntity): string {
|
|
|
31
44
|
scheme,
|
|
32
45
|
];
|
|
33
46
|
|
|
47
|
+
// Compute and append a combined hash from additional cache key components (e.g., fmi_path)
|
|
48
|
+
if (
|
|
49
|
+
credential.additionalCacheKeyComponents &&
|
|
50
|
+
Object.keys(credential.additionalCacheKeyComponents).length > 0
|
|
51
|
+
) {
|
|
52
|
+
credentialKey.push(
|
|
53
|
+
computeAdditionalCacheKeyHash(
|
|
54
|
+
credential.additionalCacheKeyComponents
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
34
59
|
return credentialKey.join(CACHE.KEY_SEPARATOR).toLowerCase();
|
|
35
60
|
}
|
|
36
61
|
|
|
@@ -134,6 +134,8 @@ export class Deserializer {
|
|
|
134
134
|
serializedAT.token_type as Constants.AuthenticationScheme,
|
|
135
135
|
userAssertionHash: serializedAT.userAssertionHash,
|
|
136
136
|
resource: serializedAT.resource,
|
|
137
|
+
additionalCacheKeyComponents:
|
|
138
|
+
serializedAT.additionalCacheKeyComponents,
|
|
137
139
|
lastUpdatedAt: Date.now().toString(),
|
|
138
140
|
};
|
|
139
141
|
atObjects[key] = accessToken;
|
|
@@ -166,7 +166,11 @@ export abstract class ClientApplication {
|
|
|
166
166
|
"acquireTokenByCode - validating state",
|
|
167
167
|
request.correlationId || ""
|
|
168
168
|
);
|
|
169
|
-
this.validateState(
|
|
169
|
+
this.validateState(
|
|
170
|
+
request.state,
|
|
171
|
+
authCodePayLoad.state || "",
|
|
172
|
+
request.correlationId || ""
|
|
173
|
+
);
|
|
170
174
|
// eslint-disable-next-line no-param-reassign
|
|
171
175
|
authCodePayLoad = { ...authCodePayLoad, state: "" };
|
|
172
176
|
}
|
|
@@ -208,7 +212,7 @@ export abstract class ClientApplication {
|
|
|
208
212
|
);
|
|
209
213
|
} catch (e) {
|
|
210
214
|
if (e instanceof AuthError) {
|
|
211
|
-
e.
|
|
215
|
+
e.correlationId = validRequest.correlationId;
|
|
212
216
|
}
|
|
213
217
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
214
218
|
throw e;
|
|
@@ -267,7 +271,7 @@ export abstract class ClientApplication {
|
|
|
267
271
|
);
|
|
268
272
|
} catch (e) {
|
|
269
273
|
if (e instanceof AuthError) {
|
|
270
|
-
e.
|
|
274
|
+
e.correlationId = validRequest.correlationId;
|
|
271
275
|
}
|
|
272
276
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
273
277
|
throw e;
|
|
@@ -346,7 +350,7 @@ export abstract class ClientApplication {
|
|
|
346
350
|
}
|
|
347
351
|
} catch (error) {
|
|
348
352
|
if (error instanceof AuthError) {
|
|
349
|
-
error.
|
|
353
|
+
error.correlationId = validRequest.correlationId;
|
|
350
354
|
}
|
|
351
355
|
serverTelemetryManager.cacheFailedRequest(error);
|
|
352
356
|
throw error;
|
|
@@ -441,7 +445,7 @@ export abstract class ClientApplication {
|
|
|
441
445
|
return await usernamePasswordClient.acquireToken(validRequest);
|
|
442
446
|
} catch (e) {
|
|
443
447
|
if (e instanceof AuthError) {
|
|
444
|
-
e.
|
|
448
|
+
e.correlationId = validRequest.correlationId;
|
|
445
449
|
}
|
|
446
450
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
447
451
|
throw e;
|
|
@@ -465,13 +469,20 @@ export abstract class ClientApplication {
|
|
|
465
469
|
* @param state - Unique GUID generated by the user that is cached by the user and sent to the server during the first leg of the flow
|
|
466
470
|
* @param cachedState - This string is sent back by the server with the authorization code
|
|
467
471
|
*/
|
|
468
|
-
protected validateState(
|
|
472
|
+
protected validateState(
|
|
473
|
+
state: string,
|
|
474
|
+
cachedState: string,
|
|
475
|
+
correlationId: string
|
|
476
|
+
): void {
|
|
469
477
|
if (!state) {
|
|
470
|
-
throw NodeAuthError.createStateNotFoundError();
|
|
478
|
+
throw NodeAuthError.createStateNotFoundError(correlationId);
|
|
471
479
|
}
|
|
472
480
|
|
|
473
481
|
if (state !== cachedState) {
|
|
474
|
-
throw createClientAuthError(
|
|
482
|
+
throw createClientAuthError(
|
|
483
|
+
ClientAuthErrorCodes.stateMismatch,
|
|
484
|
+
correlationId
|
|
485
|
+
);
|
|
475
486
|
}
|
|
476
487
|
}
|
|
477
488
|
|
|
@@ -116,7 +116,10 @@ export class ClientAssertion {
|
|
|
116
116
|
return this.jwt;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
throw createClientAuthError(
|
|
119
|
+
throw createClientAuthError(
|
|
120
|
+
NodeClientAuthErrorCodes.invalidAssertion,
|
|
121
|
+
""
|
|
122
|
+
);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
/**
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
+
AADServerParamKeys,
|
|
7
8
|
AccessTokenEntity,
|
|
8
9
|
AuthenticationResult,
|
|
9
10
|
Authority,
|
|
@@ -59,8 +60,21 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
59
60
|
public async acquireToken(
|
|
60
61
|
request: CommonClientCredentialRequest
|
|
61
62
|
): Promise<AuthenticationResult | null> {
|
|
63
|
+
// Build additional cache key components for FMI cache isolation
|
|
64
|
+
let additionalCacheKeyComponents: Record<string, string> | undefined;
|
|
65
|
+
if (request.fmiPath) {
|
|
66
|
+
additionalCacheKeyComponents = {
|
|
67
|
+
fmi_path: request.fmiPath,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
if (request.skipCache || request.claims) {
|
|
63
|
-
return this.executeTokenRequest(
|
|
72
|
+
return this.executeTokenRequest(
|
|
73
|
+
request,
|
|
74
|
+
this.authority,
|
|
75
|
+
/* refreshAccessToken */ undefined,
|
|
76
|
+
additionalCacheKeyComponents
|
|
77
|
+
);
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
const [cachedAuthenticationResult, lastCacheOutcome] =
|
|
@@ -70,7 +84,8 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
70
84
|
this.cryptoUtils,
|
|
71
85
|
this.authority,
|
|
72
86
|
this.cacheManager,
|
|
73
|
-
this.serverTelemetryManager
|
|
87
|
+
this.serverTelemetryManager,
|
|
88
|
+
additionalCacheKeyComponents
|
|
74
89
|
);
|
|
75
90
|
|
|
76
91
|
if (cachedAuthenticationResult) {
|
|
@@ -89,14 +104,20 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
89
104
|
await this.executeTokenRequest(
|
|
90
105
|
request,
|
|
91
106
|
this.authority,
|
|
92
|
-
refreshAccessToken
|
|
107
|
+
refreshAccessToken,
|
|
108
|
+
additionalCacheKeyComponents
|
|
93
109
|
);
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
// return the cached token
|
|
97
113
|
return cachedAuthenticationResult;
|
|
98
114
|
} else {
|
|
99
|
-
return this.executeTokenRequest(
|
|
115
|
+
return this.executeTokenRequest(
|
|
116
|
+
request,
|
|
117
|
+
this.authority,
|
|
118
|
+
/* refreshAccessToken */ undefined,
|
|
119
|
+
additionalCacheKeyComponents
|
|
120
|
+
);
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
123
|
|
|
@@ -109,7 +130,8 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
109
130
|
cryptoUtils: ICrypto,
|
|
110
131
|
authority: Authority,
|
|
111
132
|
cacheManager: CacheManager,
|
|
112
|
-
serverTelemetryManager?: ServerTelemetryManager | null
|
|
133
|
+
serverTelemetryManager?: ServerTelemetryManager | null,
|
|
134
|
+
additionalCacheKeyComponents?: Record<string, string>
|
|
113
135
|
): Promise<[AuthenticationResult | null, Constants.CacheOutcome]> {
|
|
114
136
|
const clientConfiguration = config as ClientConfiguration;
|
|
115
137
|
const managedIdentityConfiguration =
|
|
@@ -137,9 +159,10 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
137
159
|
authority,
|
|
138
160
|
managedIdentityConfiguration.managedIdentityId?.id ||
|
|
139
161
|
clientConfiguration.authOptions.clientId,
|
|
140
|
-
new ScopeSet(request.scopes || []),
|
|
162
|
+
new ScopeSet(request.scopes || [], request.correlationId),
|
|
141
163
|
cacheManager,
|
|
142
|
-
request.correlationId
|
|
164
|
+
request.correlationId,
|
|
165
|
+
additionalCacheKeyComponents
|
|
143
166
|
);
|
|
144
167
|
|
|
145
168
|
if (
|
|
@@ -212,7 +235,8 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
212
235
|
id: string,
|
|
213
236
|
scopeSet: ScopeSet,
|
|
214
237
|
cacheManager: CacheManager,
|
|
215
|
-
correlationId: string
|
|
238
|
+
correlationId: string,
|
|
239
|
+
additionalCacheKeyComponents?: Record<string, string>
|
|
216
240
|
): AccessTokenEntity | null {
|
|
217
241
|
const accessTokenFilter: CredentialFilter = {
|
|
218
242
|
homeAccountId: "",
|
|
@@ -221,7 +245,11 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
221
245
|
credentialType: Constants.CredentialType.ACCESS_TOKEN,
|
|
222
246
|
clientId: id,
|
|
223
247
|
realm: authority.tenant,
|
|
224
|
-
target: ScopeSet.createSearchScopes(
|
|
248
|
+
target: ScopeSet.createSearchScopes(
|
|
249
|
+
scopeSet.asArray(),
|
|
250
|
+
correlationId
|
|
251
|
+
),
|
|
252
|
+
additionalCacheKeyComponents: additionalCacheKeyComponents,
|
|
225
253
|
};
|
|
226
254
|
|
|
227
255
|
const accessTokens = cacheManager.getAccessTokensByFilter(
|
|
@@ -232,7 +260,8 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
232
260
|
return null;
|
|
233
261
|
} else if (accessTokens.length > 1) {
|
|
234
262
|
throw createClientAuthError(
|
|
235
|
-
ClientAuthErrorCodes.multipleMatchingTokens
|
|
263
|
+
ClientAuthErrorCodes.multipleMatchingTokens,
|
|
264
|
+
correlationId
|
|
236
265
|
);
|
|
237
266
|
}
|
|
238
267
|
return accessTokens[0] as AccessTokenEntity;
|
|
@@ -246,7 +275,8 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
246
275
|
private async executeTokenRequest(
|
|
247
276
|
request: CommonClientCredentialRequest,
|
|
248
277
|
authority: Authority,
|
|
249
|
-
refreshAccessToken?: boolean
|
|
278
|
+
refreshAccessToken?: boolean,
|
|
279
|
+
additionalCacheKeyComponents?: Record<string, string>
|
|
250
280
|
): Promise<AuthenticationResult | null> {
|
|
251
281
|
let serverTokenResponse: ServerAuthorizationTokenResponse;
|
|
252
282
|
let reqTimestamp: number;
|
|
@@ -337,7 +367,13 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
337
367
|
this.authority,
|
|
338
368
|
reqTimestamp,
|
|
339
369
|
request,
|
|
340
|
-
ApiId.acquireTokenByClientCredential
|
|
370
|
+
ApiId.acquireTokenByClientCredential,
|
|
371
|
+
undefined, // authCodePayload
|
|
372
|
+
undefined, // userAssertionHash
|
|
373
|
+
undefined, // handlingRefreshTokenResponse
|
|
374
|
+
undefined, // forceCacheRefreshTokenResponse
|
|
375
|
+
undefined, // serverRequestId
|
|
376
|
+
additionalCacheKeyComponents
|
|
341
377
|
);
|
|
342
378
|
|
|
343
379
|
return tokenResponse;
|
|
@@ -357,7 +393,12 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
357
393
|
this.config.authOptions.clientId
|
|
358
394
|
);
|
|
359
395
|
|
|
360
|
-
RequestParameterBuilder.addScopes(
|
|
396
|
+
RequestParameterBuilder.addScopes(
|
|
397
|
+
parameters,
|
|
398
|
+
request.scopes,
|
|
399
|
+
request.correlationId,
|
|
400
|
+
false
|
|
401
|
+
);
|
|
361
402
|
|
|
362
403
|
RequestParameterBuilder.addGrantType(
|
|
363
404
|
parameters,
|
|
@@ -405,7 +446,8 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
405
446
|
await getClientAssertion(
|
|
406
447
|
clientAssertion.assertion,
|
|
407
448
|
this.config.authOptions.clientId,
|
|
408
|
-
|
|
449
|
+
this.authority.tokenEndpoint,
|
|
450
|
+
request.fmiPath
|
|
409
451
|
)
|
|
410
452
|
);
|
|
411
453
|
RequestParameterBuilder.addClientAssertionType(
|
|
@@ -414,6 +456,10 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
414
456
|
);
|
|
415
457
|
}
|
|
416
458
|
|
|
459
|
+
if (request.fmiPath) {
|
|
460
|
+
parameters.set(AADServerParamKeys.FMI_PATH, request.fmiPath);
|
|
461
|
+
}
|
|
462
|
+
|
|
417
463
|
if (
|
|
418
464
|
!StringUtils.isEmptyObj(request.claims) ||
|
|
419
465
|
(this.config.authOptions.clientCapabilities &&
|
|
@@ -421,6 +467,7 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
421
467
|
) {
|
|
422
468
|
RequestParameterBuilder.addClaims(
|
|
423
469
|
parameters,
|
|
470
|
+
request.correlationId,
|
|
424
471
|
request.claims,
|
|
425
472
|
this.config.authOptions.clientCapabilities
|
|
426
473
|
);
|
|
@@ -33,6 +33,9 @@ import { CommonClientCredentialRequest } from "../request/CommonClientCredential
|
|
|
33
33
|
import { ClientCredentialRequest } from "../request/ClientCredentialRequest.js";
|
|
34
34
|
import { ClientCredentialClient } from "./ClientCredentialClient.js";
|
|
35
35
|
import { OnBehalfOfClient } from "./OnBehalfOfClient.js";
|
|
36
|
+
import { UserFederatedIdentityCredentialClient } from "./UserFederatedIdentityCredentialClient.js";
|
|
37
|
+
import { UserFederatedIdentityCredentialRequest } from "../request/UserFederatedIdentityCredentialRequest.js";
|
|
38
|
+
import { CommonUserFederatedIdentityCredentialRequest } from "../request/CommonUserFederatedIdentityCredentialRequest.js";
|
|
36
39
|
import * as NodeClientAuthErrorCodes from "../error/ClientAuthErrorCodes.js";
|
|
37
40
|
|
|
38
41
|
/**
|
|
@@ -90,7 +93,8 @@ export class ConfidentialClientApplication
|
|
|
90
93
|
(clientSecretNotEmpty && certificateNotEmpty)
|
|
91
94
|
) {
|
|
92
95
|
throw createClientAuthError(
|
|
93
|
-
NodeClientAuthErrorCodes.invalidClientCredential
|
|
96
|
+
NodeClientAuthErrorCodes.invalidClientCredential,
|
|
97
|
+
""
|
|
94
98
|
);
|
|
95
99
|
}
|
|
96
100
|
|
|
@@ -107,7 +111,8 @@ export class ConfidentialClientApplication
|
|
|
107
111
|
|
|
108
112
|
if (!certificateNotEmpty) {
|
|
109
113
|
throw createClientAuthError(
|
|
110
|
-
NodeClientAuthErrorCodes.invalidClientCredential
|
|
114
|
+
NodeClientAuthErrorCodes.invalidClientCredential,
|
|
115
|
+
""
|
|
111
116
|
);
|
|
112
117
|
} else {
|
|
113
118
|
this.clientAssertion = !!this.config.auth.clientCertificate
|
|
@@ -182,7 +187,10 @@ export class ConfidentialClientApplication
|
|
|
182
187
|
* valid request should not have "common" or "organizations" in lieu of the tenant_id in the authority in the auth configuration
|
|
183
188
|
* example authority: "https://login.microsoftonline.com/TenantId",
|
|
184
189
|
*/
|
|
185
|
-
const authority = new UrlString(
|
|
190
|
+
const authority = new UrlString(
|
|
191
|
+
validRequest.authority,
|
|
192
|
+
validRequest.correlationId
|
|
193
|
+
);
|
|
186
194
|
const tenantId = authority.getUrlComponents().PathSegments[0];
|
|
187
195
|
if (
|
|
188
196
|
Object.values(Constants.AADAuthority).includes(
|
|
@@ -190,7 +198,8 @@ export class ConfidentialClientApplication
|
|
|
190
198
|
)
|
|
191
199
|
) {
|
|
192
200
|
throw createClientAuthError(
|
|
193
|
-
NodeClientAuthErrorCodes.missingTenantIdError
|
|
201
|
+
NodeClientAuthErrorCodes.missingTenantIdError,
|
|
202
|
+
validRequest.correlationId
|
|
194
203
|
);
|
|
195
204
|
}
|
|
196
205
|
|
|
@@ -245,7 +254,7 @@ export class ConfidentialClientApplication
|
|
|
245
254
|
return await clientCredentialClient.acquireToken(validRequest);
|
|
246
255
|
} catch (e) {
|
|
247
256
|
if (e instanceof AuthError) {
|
|
248
|
-
e.
|
|
257
|
+
e.correlationId = validRequest.correlationId;
|
|
249
258
|
}
|
|
250
259
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
251
260
|
throw e;
|
|
@@ -295,8 +304,101 @@ export class ConfidentialClientApplication
|
|
|
295
304
|
return await oboClient.acquireToken(validRequest);
|
|
296
305
|
} catch (e) {
|
|
297
306
|
if (e instanceof AuthError) {
|
|
298
|
-
e.
|
|
307
|
+
e.correlationId = validRequest.correlationId;
|
|
308
|
+
}
|
|
309
|
+
throw e;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Acquires a user-scoped token using the user_fic grant type (Leg 3 of Agent Identity).
|
|
315
|
+
*
|
|
316
|
+
* Exchanges a federated identity credential (instance token from Leg 2) for a user-scoped token.
|
|
317
|
+
* Exactly one of `userObjectId` or `username` must be provided to identify the target user.
|
|
318
|
+
*
|
|
319
|
+
* This method always makes a network call. Use `acquireTokenSilent` to retrieve cached FIC tokens.
|
|
320
|
+
*/
|
|
321
|
+
public async acquireTokenByUserFederatedIdentityCredential(
|
|
322
|
+
request: UserFederatedIdentityCredentialRequest
|
|
323
|
+
): Promise<AuthenticationResult | null> {
|
|
324
|
+
this.logger.info(
|
|
325
|
+
"acquireTokenByUserFederatedIdentityCredential called",
|
|
326
|
+
request.correlationId || ""
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
// Validate that exactly one user identifier is provided
|
|
330
|
+
if (request.userObjectId && request.username) {
|
|
331
|
+
throw createClientAuthError(
|
|
332
|
+
NodeClientAuthErrorCodes.conflictingUserIdentifiers,
|
|
333
|
+
request.correlationId || ""
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
if (!request.userObjectId && !request.username) {
|
|
337
|
+
throw createClientAuthError(
|
|
338
|
+
NodeClientAuthErrorCodes.missingUserIdentifier,
|
|
339
|
+
request.correlationId || ""
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Validate that the assertion is not empty
|
|
344
|
+
if (!request.assertion) {
|
|
345
|
+
throw createClientAuthError(
|
|
346
|
+
NodeClientAuthErrorCodes.emptyFicAssertion,
|
|
347
|
+
request.correlationId || ""
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// If there is a client assertion present in the request, resolve it
|
|
352
|
+
let clientAssertion: ClientAssertionType | undefined;
|
|
353
|
+
if (request.clientAssertion) {
|
|
354
|
+
clientAssertion = {
|
|
355
|
+
assertion: await getClientAssertion(
|
|
356
|
+
request.clientAssertion,
|
|
357
|
+
this.config.auth.clientId
|
|
358
|
+
),
|
|
359
|
+
assertionType: NodeConstants.JWT_BEARER_ASSERTION_TYPE,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const baseRequest = await this.initializeBaseRequest(request);
|
|
364
|
+
const validRequest: CommonUserFederatedIdentityCredentialRequest = {
|
|
365
|
+
...request,
|
|
366
|
+
...baseRequest,
|
|
367
|
+
assertion: request.assertion,
|
|
368
|
+
clientAssertion,
|
|
369
|
+
} as CommonUserFederatedIdentityCredentialRequest;
|
|
370
|
+
|
|
371
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
|
372
|
+
ApiId.acquireTokenByUserFederatedIdentityCredential,
|
|
373
|
+
validRequest.correlationId
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
try {
|
|
377
|
+
const discoveredAuthority = await this.createAuthority(
|
|
378
|
+
validRequest.authority,
|
|
379
|
+
validRequest.correlationId,
|
|
380
|
+
undefined,
|
|
381
|
+
request.azureCloudOptions
|
|
382
|
+
);
|
|
383
|
+
const clientConfig = await this.buildOauthClientConfiguration(
|
|
384
|
+
discoveredAuthority,
|
|
385
|
+
validRequest.correlationId,
|
|
386
|
+
"",
|
|
387
|
+
serverTelemetryManager
|
|
388
|
+
);
|
|
389
|
+
const ficClient = new UserFederatedIdentityCredentialClient(
|
|
390
|
+
clientConfig
|
|
391
|
+
);
|
|
392
|
+
this.logger.verbose(
|
|
393
|
+
"UserFederatedIdentityCredential client created",
|
|
394
|
+
validRequest.correlationId
|
|
395
|
+
);
|
|
396
|
+
return await ficClient.acquireToken(validRequest);
|
|
397
|
+
} catch (e) {
|
|
398
|
+
if (e instanceof AuthError) {
|
|
399
|
+
e.correlationId = validRequest.correlationId;
|
|
299
400
|
}
|
|
401
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
300
402
|
throw e;
|
|
301
403
|
}
|
|
302
404
|
}
|
|
@@ -177,7 +177,11 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
177
177
|
private createQueryString(request: CommonDeviceCodeRequest): string {
|
|
178
178
|
const parameters = new Map<string, string>();
|
|
179
179
|
|
|
180
|
-
RequestParameterBuilder.addScopes(
|
|
180
|
+
RequestParameterBuilder.addScopes(
|
|
181
|
+
parameters,
|
|
182
|
+
request.scopes,
|
|
183
|
+
request.correlationId
|
|
184
|
+
);
|
|
181
185
|
RequestParameterBuilder.addClientId(
|
|
182
186
|
parameters,
|
|
183
187
|
this.config.authOptions.clientId
|
|
@@ -197,6 +201,7 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
197
201
|
) {
|
|
198
202
|
RequestParameterBuilder.addClaims(
|
|
199
203
|
parameters,
|
|
204
|
+
request.correlationId,
|
|
200
205
|
request.claims,
|
|
201
206
|
this.config.authOptions.clientCapabilities
|
|
202
207
|
);
|
|
@@ -208,21 +213,24 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
208
213
|
/**
|
|
209
214
|
* Breaks the polling with specific conditions
|
|
210
215
|
* @param deviceCodeExpirationTime - expiration time for the device code request
|
|
216
|
+
* @param correlationId - correlation id of the request
|
|
211
217
|
* @param userSpecifiedTimeout - developer provided timeout, to be compared against deviceCodeExpirationTime
|
|
212
218
|
* @param userSpecifiedCancelFlag - boolean indicating the developer would like to cancel the request
|
|
213
219
|
*/
|
|
214
220
|
private continuePolling(
|
|
215
221
|
deviceCodeExpirationTime: number,
|
|
222
|
+
correlationId: string,
|
|
216
223
|
userSpecifiedTimeout?: number,
|
|
217
224
|
userSpecifiedCancelFlag?: boolean
|
|
218
225
|
): boolean {
|
|
219
226
|
if (userSpecifiedCancelFlag) {
|
|
220
227
|
this.logger.error(
|
|
221
228
|
"Token request cancelled by setting DeviceCodeRequest.cancel = true",
|
|
222
|
-
|
|
229
|
+
correlationId
|
|
223
230
|
);
|
|
224
231
|
throw createClientAuthError(
|
|
225
|
-
NodeClientAuthErrorCodes.deviceCodePollingCancelled
|
|
232
|
+
NodeClientAuthErrorCodes.deviceCodePollingCancelled,
|
|
233
|
+
correlationId
|
|
226
234
|
);
|
|
227
235
|
} else if (
|
|
228
236
|
userSpecifiedTimeout &&
|
|
@@ -231,24 +239,26 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
231
239
|
) {
|
|
232
240
|
this.logger.error(
|
|
233
241
|
`User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`,
|
|
234
|
-
|
|
242
|
+
correlationId
|
|
235
243
|
);
|
|
236
244
|
throw createClientAuthError(
|
|
237
|
-
NodeClientAuthErrorCodes.userTimeoutReached
|
|
245
|
+
NodeClientAuthErrorCodes.userTimeoutReached,
|
|
246
|
+
correlationId
|
|
238
247
|
);
|
|
239
248
|
} else if (TimeUtils.nowSeconds() > deviceCodeExpirationTime) {
|
|
240
249
|
if (userSpecifiedTimeout) {
|
|
241
250
|
this.logger.verbose(
|
|
242
251
|
`User specified timeout ignored as the device code has expired before the timeout elapsed. The user specified timeout was set for ${userSpecifiedTimeout}`,
|
|
243
|
-
|
|
252
|
+
correlationId
|
|
244
253
|
);
|
|
245
254
|
}
|
|
246
255
|
this.logger.error(
|
|
247
256
|
`Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`,
|
|
248
|
-
|
|
257
|
+
correlationId
|
|
249
258
|
);
|
|
250
259
|
throw createClientAuthError(
|
|
251
|
-
NodeClientAuthErrorCodes.deviceCodeExpired
|
|
260
|
+
NodeClientAuthErrorCodes.deviceCodeExpired,
|
|
261
|
+
correlationId
|
|
252
262
|
);
|
|
253
263
|
}
|
|
254
264
|
return true;
|
|
@@ -289,6 +299,7 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
289
299
|
while (
|
|
290
300
|
this.continuePolling(
|
|
291
301
|
deviceCodeExpirationTime,
|
|
302
|
+
request.correlationId,
|
|
292
303
|
userSpecifiedTimeout,
|
|
293
304
|
request.cancel
|
|
294
305
|
)
|
|
@@ -328,6 +339,7 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
328
339
|
);
|
|
329
340
|
throw createAuthError(
|
|
330
341
|
AuthErrorCodes.postRequestFailed,
|
|
342
|
+
request.correlationId,
|
|
331
343
|
response.body.error
|
|
332
344
|
);
|
|
333
345
|
}
|
|
@@ -349,7 +361,8 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
349
361
|
request.correlationId
|
|
350
362
|
);
|
|
351
363
|
throw createClientAuthError(
|
|
352
|
-
NodeClientAuthErrorCodes.deviceCodeUnknownError
|
|
364
|
+
NodeClientAuthErrorCodes.deviceCodeUnknownError,
|
|
365
|
+
request.correlationId
|
|
353
366
|
);
|
|
354
367
|
}
|
|
355
368
|
|
|
@@ -364,7 +377,11 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
364
377
|
): string {
|
|
365
378
|
const parameters = new Map<string, string>();
|
|
366
379
|
|
|
367
|
-
RequestParameterBuilder.addScopes(
|
|
380
|
+
RequestParameterBuilder.addScopes(
|
|
381
|
+
parameters,
|
|
382
|
+
request.scopes,
|
|
383
|
+
request.correlationId
|
|
384
|
+
);
|
|
368
385
|
RequestParameterBuilder.addClientId(
|
|
369
386
|
parameters,
|
|
370
387
|
this.config.authOptions.clientId
|
|
@@ -405,6 +422,7 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
405
422
|
) {
|
|
406
423
|
RequestParameterBuilder.addClaims(
|
|
407
424
|
parameters,
|
|
425
|
+
request.correlationId,
|
|
408
426
|
request.claims,
|
|
409
427
|
this.config.authOptions.clientCapabilities
|
|
410
428
|
);
|
|
@@ -135,7 +135,8 @@ export class ManagedIdentityApplication {
|
|
|
135
135
|
): Promise<AuthenticationResult> {
|
|
136
136
|
if (!managedIdentityRequestParams.resource) {
|
|
137
137
|
throw createClientConfigurationError(
|
|
138
|
-
ClientConfigurationErrorCodes.urlEmptyError
|
|
138
|
+
ClientConfigurationErrorCodes.urlEmptyError,
|
|
139
|
+
""
|
|
139
140
|
);
|
|
140
141
|
}
|
|
141
142
|
|