@azure/msal-node 5.2.5 → 5.3.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/CacheHelpers.mjs +16 -1
- package/dist/cache/CacheHelpers.mjs.map +1 -1
- package/dist/cache/NodeStorage.mjs +1 -1
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs.map +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/BaseClient.mjs.map +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/AppService.mjs.map +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/Imds.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +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/Configuration.mjs.map +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/config/ManagedIdentityRequestParameters.mjs.map +1 -1
- package/dist/crypto/CryptoProvider.mjs +1 -1
- package/dist/crypto/CryptoProvider.mjs.map +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/GuidGenerator.mjs.map +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/HashUtils.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs.map +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/ManagedIdentityErrorCodes.mjs.map +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/HttpClientWithRetries.mjs.map +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/protocol/Authorize.mjs +1 -1
- package/dist/protocol/Authorize.mjs.map +1 -1
- package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs +1 -1
- package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs.map +1 -1
- package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
- package/dist/retry/ExponentialRetryStrategy.mjs.map +1 -1
- package/dist/retry/ImdsRetryPolicy.mjs +1 -1
- package/dist/retry/ImdsRetryPolicy.mjs.map +1 -1
- package/dist/retry/LinearRetryStrategy.mjs +1 -1
- package/dist/retry/LinearRetryStrategy.mjs.map +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/EncodingUtils.mjs.map +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs.map +1 -1
- package/lib/msal-node.cjs +5899 -5666
- package/lib/msal-node.cjs.map +1 -1
- package/package.json +2 -2
- 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
|
@@ -227,7 +227,8 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
227
227
|
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
228
228
|
) {
|
|
229
229
|
throw createManagedIdentityError(
|
|
230
|
-
ManagedIdentityErrorCodes.unableToCreateAzureArc
|
|
230
|
+
ManagedIdentityErrorCodes.unableToCreateAzureArc,
|
|
231
|
+
""
|
|
231
232
|
);
|
|
232
233
|
}
|
|
233
234
|
|
|
@@ -310,12 +311,14 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
310
311
|
originalResponse.headers["www-authenticate"];
|
|
311
312
|
if (!wwwAuthHeader) {
|
|
312
313
|
throw createManagedIdentityError(
|
|
313
|
-
ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing
|
|
314
|
+
ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing,
|
|
315
|
+
""
|
|
314
316
|
);
|
|
315
317
|
}
|
|
316
318
|
if (!wwwAuthHeader.includes("Basic realm=")) {
|
|
317
319
|
throw createManagedIdentityError(
|
|
318
|
-
ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat
|
|
320
|
+
ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat,
|
|
321
|
+
""
|
|
319
322
|
);
|
|
320
323
|
}
|
|
321
324
|
|
|
@@ -326,7 +329,8 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
326
329
|
!SUPPORTED_AZURE_ARC_PLATFORMS.hasOwnProperty(process.platform)
|
|
327
330
|
) {
|
|
328
331
|
throw createManagedIdentityError(
|
|
329
|
-
ManagedIdentityErrorCodes.platformNotSupported
|
|
332
|
+
ManagedIdentityErrorCodes.platformNotSupported,
|
|
333
|
+
""
|
|
330
334
|
);
|
|
331
335
|
}
|
|
332
336
|
|
|
@@ -340,7 +344,8 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
340
344
|
const fileName: string = path.basename(secretFilePath);
|
|
341
345
|
if (!fileName.endsWith(".key")) {
|
|
342
346
|
throw createManagedIdentityError(
|
|
343
|
-
ManagedIdentityErrorCodes.invalidFileExtension
|
|
347
|
+
ManagedIdentityErrorCodes.invalidFileExtension,
|
|
348
|
+
""
|
|
344
349
|
);
|
|
345
350
|
}
|
|
346
351
|
|
|
@@ -351,7 +356,8 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
351
356
|
*/
|
|
352
357
|
if (expectedSecretFilePath + fileName !== secretFilePath) {
|
|
353
358
|
throw createManagedIdentityError(
|
|
354
|
-
ManagedIdentityErrorCodes.invalidFilePath
|
|
359
|
+
ManagedIdentityErrorCodes.invalidFilePath,
|
|
360
|
+
""
|
|
355
361
|
);
|
|
356
362
|
}
|
|
357
363
|
|
|
@@ -361,13 +367,15 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
361
367
|
secretFileSize = await statSync(secretFilePath).size;
|
|
362
368
|
} catch (e) {
|
|
363
369
|
throw createManagedIdentityError(
|
|
364
|
-
ManagedIdentityErrorCodes.unableToReadSecretFile
|
|
370
|
+
ManagedIdentityErrorCodes.unableToReadSecretFile,
|
|
371
|
+
""
|
|
365
372
|
);
|
|
366
373
|
}
|
|
367
374
|
// throw an error if the secret file's size is greater than 4096 bytes
|
|
368
375
|
if (secretFileSize > AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES) {
|
|
369
376
|
throw createManagedIdentityError(
|
|
370
|
-
ManagedIdentityErrorCodes.invalidSecret
|
|
377
|
+
ManagedIdentityErrorCodes.invalidSecret,
|
|
378
|
+
""
|
|
371
379
|
);
|
|
372
380
|
}
|
|
373
381
|
|
|
@@ -380,7 +388,8 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
380
388
|
);
|
|
381
389
|
} catch (e) {
|
|
382
390
|
throw createManagedIdentityError(
|
|
383
|
-
ManagedIdentityErrorCodes.unableToReadSecretFile
|
|
391
|
+
ManagedIdentityErrorCodes.unableToReadSecretFile,
|
|
392
|
+
""
|
|
384
393
|
);
|
|
385
394
|
}
|
|
386
395
|
const authHeaderValue = `Basic ${secret}`;
|
|
@@ -404,7 +413,8 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
404
413
|
throw error;
|
|
405
414
|
} else {
|
|
406
415
|
throw createClientAuthError(
|
|
407
|
-
ClientAuthErrorCodes.networkError
|
|
416
|
+
ClientAuthErrorCodes.networkError,
|
|
417
|
+
""
|
|
408
418
|
);
|
|
409
419
|
}
|
|
410
420
|
}
|
|
@@ -294,7 +294,10 @@ export abstract class BaseManagedIdentitySource {
|
|
|
294
294
|
if (error instanceof AuthError) {
|
|
295
295
|
throw error;
|
|
296
296
|
} else {
|
|
297
|
-
throw createClientAuthError(
|
|
297
|
+
throw createClientAuthError(
|
|
298
|
+
ClientAuthErrorCodes.networkError,
|
|
299
|
+
managedIdentityRequest.correlationId
|
|
300
|
+
);
|
|
298
301
|
}
|
|
299
302
|
}
|
|
300
303
|
|
|
@@ -380,7 +383,8 @@ export abstract class BaseManagedIdentitySource {
|
|
|
380
383
|
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_OBJECT_ID;
|
|
381
384
|
default:
|
|
382
385
|
throw createManagedIdentityError(
|
|
383
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
386
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType,
|
|
387
|
+
""
|
|
384
388
|
);
|
|
385
389
|
}
|
|
386
390
|
}
|
|
@@ -406,7 +410,8 @@ export abstract class BaseManagedIdentitySource {
|
|
|
406
410
|
logger: Logger
|
|
407
411
|
): string => {
|
|
408
412
|
try {
|
|
409
|
-
|
|
413
|
+
// Static boot-time helper invoked from each MI source's tryCreate() before any request exists
|
|
414
|
+
return new UrlString(envVariable, "").urlString;
|
|
410
415
|
} catch (error) {
|
|
411
416
|
logger.info(
|
|
412
417
|
`[Managed Identity] ${sourceName} managed identity is unavailable because the '${envVariableStringName}' environment variable is malformed.`,
|
|
@@ -417,7 +422,8 @@ export abstract class BaseManagedIdentitySource {
|
|
|
417
422
|
ManagedIdentityErrorCodes
|
|
418
423
|
.MsiEnvironmentVariableUrlMalformedErrorCodes[
|
|
419
424
|
envVariableStringName
|
|
420
|
-
]
|
|
425
|
+
],
|
|
426
|
+
""
|
|
421
427
|
);
|
|
422
428
|
}
|
|
423
429
|
};
|
|
@@ -133,7 +133,8 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
133
133
|
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
134
134
|
) {
|
|
135
135
|
throw createManagedIdentityError(
|
|
136
|
-
ManagedIdentityErrorCodes.unableToCreateCloudShell
|
|
136
|
+
ManagedIdentityErrorCodes.unableToCreateCloudShell,
|
|
137
|
+
""
|
|
137
138
|
);
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -52,7 +52,10 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
52
52
|
public async acquireToken(
|
|
53
53
|
request: CommonOnBehalfOfRequest
|
|
54
54
|
): Promise<AuthenticationResult | null> {
|
|
55
|
-
this.scopeSet = new ScopeSet(
|
|
55
|
+
this.scopeSet = new ScopeSet(
|
|
56
|
+
request.scopes || [],
|
|
57
|
+
request.correlationId
|
|
58
|
+
);
|
|
56
59
|
|
|
57
60
|
// generate the user_assertion_hash for OBOAssertion
|
|
58
61
|
this.userAssertionHash = await this.cryptoUtils.hashString(
|
|
@@ -105,7 +108,8 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
105
108
|
request.correlationId
|
|
106
109
|
);
|
|
107
110
|
throw createClientAuthError(
|
|
108
|
-
ClientAuthErrorCodes.tokenRefreshRequired
|
|
111
|
+
ClientAuthErrorCodes.tokenRefreshRequired,
|
|
112
|
+
request.correlationId
|
|
109
113
|
);
|
|
110
114
|
} else if (
|
|
111
115
|
TimeUtils.isTokenExpired(
|
|
@@ -122,7 +126,8 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
122
126
|
request.correlationId
|
|
123
127
|
);
|
|
124
128
|
throw createClientAuthError(
|
|
125
|
-
ClientAuthErrorCodes.tokenRefreshRequired
|
|
129
|
+
ClientAuthErrorCodes.tokenRefreshRequired,
|
|
130
|
+
request.correlationId
|
|
126
131
|
);
|
|
127
132
|
}
|
|
128
133
|
|
|
@@ -136,7 +141,8 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
136
141
|
if (cachedIdToken) {
|
|
137
142
|
idTokenClaims = AuthToken.extractTokenClaims(
|
|
138
143
|
cachedIdToken.secret,
|
|
139
|
-
EncodingUtils.base64Decode
|
|
144
|
+
EncodingUtils.base64Decode,
|
|
145
|
+
request.correlationId
|
|
140
146
|
);
|
|
141
147
|
const localAccountId = idTokenClaims.oid || idTokenClaims.sub;
|
|
142
148
|
const accountInfo: AccountInfo = {
|
|
@@ -229,7 +235,10 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
229
235
|
const accessTokenFilter: CredentialFilter = {
|
|
230
236
|
credentialType: credentialType,
|
|
231
237
|
clientId,
|
|
232
|
-
target: ScopeSet.createSearchScopes(
|
|
238
|
+
target: ScopeSet.createSearchScopes(
|
|
239
|
+
this.scopeSet.asArray(),
|
|
240
|
+
request.correlationId
|
|
241
|
+
),
|
|
233
242
|
tokenType: authScheme,
|
|
234
243
|
keyId: request.sshKid,
|
|
235
244
|
userAssertionHash: this.userAssertionHash,
|
|
@@ -245,7 +254,8 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
245
254
|
return null;
|
|
246
255
|
} else if (numAccessTokens > 1) {
|
|
247
256
|
throw createClientAuthError(
|
|
248
|
-
ClientAuthErrorCodes.multipleMatchingTokens
|
|
257
|
+
ClientAuthErrorCodes.multipleMatchingTokens,
|
|
258
|
+
request.correlationId
|
|
249
259
|
);
|
|
250
260
|
}
|
|
251
261
|
|
|
@@ -332,7 +342,11 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
332
342
|
this.config.authOptions.clientId
|
|
333
343
|
);
|
|
334
344
|
|
|
335
|
-
RequestParameterBuilder.addScopes(
|
|
345
|
+
RequestParameterBuilder.addScopes(
|
|
346
|
+
parameters,
|
|
347
|
+
request.scopes,
|
|
348
|
+
request.correlationId
|
|
349
|
+
);
|
|
336
350
|
|
|
337
351
|
RequestParameterBuilder.addGrantType(
|
|
338
352
|
parameters,
|
|
@@ -405,6 +419,7 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
405
419
|
) {
|
|
406
420
|
RequestParameterBuilder.addClaims(
|
|
407
421
|
parameters,
|
|
422
|
+
request.correlationId,
|
|
408
423
|
request.claims,
|
|
409
424
|
this.config.authOptions.clientCapabilities
|
|
410
425
|
);
|
|
@@ -135,7 +135,7 @@ export class PublicClientApplication
|
|
|
135
135
|
return await deviceCodeClient.acquireToken(validRequest);
|
|
136
136
|
} catch (e) {
|
|
137
137
|
if (e instanceof AuthError) {
|
|
138
|
-
e.
|
|
138
|
+
e.correlationId = validRequest.correlationId;
|
|
139
139
|
}
|
|
140
140
|
serverTelemetryManager.cacheFailedRequest(e as AuthError);
|
|
141
141
|
throw e;
|
|
@@ -185,7 +185,9 @@ export class PublicClientApplication
|
|
|
185
185
|
if (request.redirectUri) {
|
|
186
186
|
// If it's not a broker fallback scenario, we throw an error
|
|
187
187
|
if (!this.config.broker.nativeBrokerPlugin) {
|
|
188
|
-
throw NodeAuthError.createRedirectUriNotSupportedError(
|
|
188
|
+
throw NodeAuthError.createRedirectUriNotSupportedError(
|
|
189
|
+
correlationId
|
|
190
|
+
);
|
|
189
191
|
}
|
|
190
192
|
// If a redirect URI is provided for a broker flow but MSAL runtime startup failed, we fall back to the browser flow and will ignore the redirect URI provided for the broker flow
|
|
191
193
|
request.redirectUri = "";
|
|
@@ -211,7 +213,10 @@ export class PublicClientApplication
|
|
|
211
213
|
});
|
|
212
214
|
|
|
213
215
|
// Wait for server to be listening
|
|
214
|
-
const redirectUri = await this.waitForRedirectUri(
|
|
216
|
+
const redirectUri = await this.waitForRedirectUri(
|
|
217
|
+
loopbackClient,
|
|
218
|
+
correlationId
|
|
219
|
+
);
|
|
215
220
|
|
|
216
221
|
const validRequest: AuthorizationUrlRequest = {
|
|
217
222
|
...remainingProperties,
|
|
@@ -234,11 +239,14 @@ export class PublicClientApplication
|
|
|
234
239
|
if (authCodeResponse.error) {
|
|
235
240
|
throw new ServerError(
|
|
236
241
|
authCodeResponse.error,
|
|
242
|
+
correlationId,
|
|
237
243
|
authCodeResponse.error_description,
|
|
238
244
|
authCodeResponse.suberror
|
|
239
245
|
);
|
|
240
246
|
} else if (!authCodeResponse.code) {
|
|
241
|
-
throw NodeAuthError.createNoAuthCodeInResponseError(
|
|
247
|
+
throw NodeAuthError.createNoAuthCodeInResponseError(
|
|
248
|
+
correlationId
|
|
249
|
+
);
|
|
242
250
|
}
|
|
243
251
|
|
|
244
252
|
const clientInfo = authCodeResponse.client_info;
|
|
@@ -289,7 +297,9 @@ export class PublicClientApplication
|
|
|
289
297
|
if (request.redirectUri) {
|
|
290
298
|
// If it's not a broker fallback scenario, we throw an error
|
|
291
299
|
if (!this.config.broker.nativeBrokerPlugin) {
|
|
292
|
-
throw NodeAuthError.createRedirectUriNotSupportedError(
|
|
300
|
+
throw NodeAuthError.createRedirectUriNotSupportedError(
|
|
301
|
+
correlationId
|
|
302
|
+
);
|
|
293
303
|
}
|
|
294
304
|
request.redirectUri = "";
|
|
295
305
|
}
|
|
@@ -362,10 +372,12 @@ export class PublicClientApplication
|
|
|
362
372
|
/**
|
|
363
373
|
* Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
|
|
364
374
|
* @param loopbackClient - developer provided custom loopback server implementation
|
|
375
|
+
* @param correlationId - correlation id of the request
|
|
365
376
|
* @returns
|
|
366
377
|
*/
|
|
367
378
|
private async waitForRedirectUri(
|
|
368
|
-
loopbackClient: ILoopbackClient
|
|
379
|
+
loopbackClient: ILoopbackClient,
|
|
380
|
+
correlationId: string
|
|
369
381
|
): Promise<string> {
|
|
370
382
|
return new Promise<string>((resolve, reject) => {
|
|
371
383
|
let ticks = 0;
|
|
@@ -376,7 +388,11 @@ export class PublicClientApplication
|
|
|
376
388
|
ticks
|
|
377
389
|
) {
|
|
378
390
|
clearInterval(id);
|
|
379
|
-
reject(
|
|
391
|
+
reject(
|
|
392
|
+
NodeAuthError.createLoopbackServerTimeoutError(
|
|
393
|
+
correlationId
|
|
394
|
+
)
|
|
395
|
+
);
|
|
380
396
|
return;
|
|
381
397
|
}
|
|
382
398
|
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AADServerParamKeys,
|
|
8
|
+
AuthenticationResult,
|
|
9
|
+
Authority,
|
|
10
|
+
ClientConfiguration,
|
|
11
|
+
Constants,
|
|
12
|
+
RequestParameterBuilder,
|
|
13
|
+
RequestThumbprint,
|
|
14
|
+
ResponseHandler,
|
|
15
|
+
ScopeSet,
|
|
16
|
+
TimeUtils,
|
|
17
|
+
UrlString,
|
|
18
|
+
ClientAssertion,
|
|
19
|
+
getClientAssertion,
|
|
20
|
+
UrlUtils,
|
|
21
|
+
} from "@azure/msal-common/node";
|
|
22
|
+
import { ApiId } from "../utils/Constants.js";
|
|
23
|
+
import { BaseClient } from "./BaseClient.js";
|
|
24
|
+
import { CommonUserFederatedIdentityCredentialRequest } from "../request/CommonUserFederatedIdentityCredentialRequest.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Client for the user_fic grant type (Leg 3 of Agent Identity).
|
|
28
|
+
* Exchanges a federated identity credential (instance token) for a user-scoped token.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export class UserFederatedIdentityCredentialClient extends BaseClient {
|
|
32
|
+
constructor(configuration: ClientConfiguration) {
|
|
33
|
+
super(configuration);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Acquires a token using the user_fic grant type.
|
|
38
|
+
* Always hits the network (no cache lookup for the network call).
|
|
39
|
+
* Developers use acquireTokenSilent for cached FIC tokens.
|
|
40
|
+
*/
|
|
41
|
+
public async acquireToken(
|
|
42
|
+
request: CommonUserFederatedIdentityCredentialRequest
|
|
43
|
+
): Promise<AuthenticationResult | null> {
|
|
44
|
+
return this.executeTokenRequest(request, this.authority);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Makes a network call to the token endpoint
|
|
49
|
+
*/
|
|
50
|
+
private async executeTokenRequest(
|
|
51
|
+
request: CommonUserFederatedIdentityCredentialRequest,
|
|
52
|
+
authority: Authority
|
|
53
|
+
): Promise<AuthenticationResult | null> {
|
|
54
|
+
// Build augmented scopes once for both thumbprint and body
|
|
55
|
+
const scopeSet = new ScopeSet(
|
|
56
|
+
request.scopes || [],
|
|
57
|
+
request.correlationId
|
|
58
|
+
);
|
|
59
|
+
scopeSet.appendScopes(Constants.OIDC_DEFAULT_SCOPES);
|
|
60
|
+
const augmentedScopes = scopeSet.asArray();
|
|
61
|
+
|
|
62
|
+
const queryParametersString = this.createTokenQueryParameters(request);
|
|
63
|
+
const endpoint = UrlString.appendQueryString(
|
|
64
|
+
authority.tokenEndpoint,
|
|
65
|
+
queryParametersString
|
|
66
|
+
);
|
|
67
|
+
const requestBody = await this.createTokenRequestBody(
|
|
68
|
+
request,
|
|
69
|
+
augmentedScopes
|
|
70
|
+
);
|
|
71
|
+
const headers: Record<string, string> =
|
|
72
|
+
this.createTokenRequestHeaders();
|
|
73
|
+
const thumbprint: RequestThumbprint = {
|
|
74
|
+
clientId: this.config.authOptions.clientId,
|
|
75
|
+
authority: request.authority,
|
|
76
|
+
scopes: augmentedScopes,
|
|
77
|
+
claims: request.claims,
|
|
78
|
+
authenticationScheme: request.authenticationScheme,
|
|
79
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
80
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
81
|
+
shrClaims: request.shrClaims,
|
|
82
|
+
sshKid: request.sshKid,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const reqTimestamp = TimeUtils.nowSeconds();
|
|
86
|
+
const response = await this.executePostToTokenEndpoint(
|
|
87
|
+
endpoint,
|
|
88
|
+
requestBody,
|
|
89
|
+
headers,
|
|
90
|
+
thumbprint,
|
|
91
|
+
request.correlationId
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const responseHandler = new ResponseHandler(
|
|
95
|
+
this.config.authOptions.clientId,
|
|
96
|
+
this.cacheManager,
|
|
97
|
+
this.cryptoUtils,
|
|
98
|
+
this.logger,
|
|
99
|
+
this.performanceClient,
|
|
100
|
+
this.config.serializableCache,
|
|
101
|
+
this.config.persistencePlugin
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
responseHandler.validateTokenResponse(
|
|
105
|
+
response.body,
|
|
106
|
+
request.correlationId
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const tokenResponse = await responseHandler.handleServerTokenResponse(
|
|
110
|
+
response.body,
|
|
111
|
+
this.authority,
|
|
112
|
+
reqTimestamp,
|
|
113
|
+
request,
|
|
114
|
+
ApiId.acquireTokenByUserFederatedIdentityCredential
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return tokenResponse;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Builds the request body for the user_fic grant type
|
|
122
|
+
*/
|
|
123
|
+
private async createTokenRequestBody(
|
|
124
|
+
request: CommonUserFederatedIdentityCredentialRequest,
|
|
125
|
+
augmentedScopes: string[]
|
|
126
|
+
): Promise<string> {
|
|
127
|
+
const parameters = new Map<string, string>();
|
|
128
|
+
|
|
129
|
+
RequestParameterBuilder.addClientId(
|
|
130
|
+
parameters,
|
|
131
|
+
this.config.authOptions.clientId
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
RequestParameterBuilder.addScopes(
|
|
135
|
+
parameters,
|
|
136
|
+
augmentedScopes,
|
|
137
|
+
request.correlationId
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
RequestParameterBuilder.addGrantType(
|
|
141
|
+
parameters,
|
|
142
|
+
Constants.GrantType.USER_FIC
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Send client_info=1 to get homeAccountId for user cache
|
|
146
|
+
RequestParameterBuilder.addClientInfo(parameters);
|
|
147
|
+
|
|
148
|
+
// Add the user_federated_identity_credential (instance token)
|
|
149
|
+
parameters.set(
|
|
150
|
+
AADServerParamKeys.USER_FEDERATED_IDENTITY_CREDENTIAL,
|
|
151
|
+
request.assertion
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// Add user identification: either username or user_id (object ID)
|
|
155
|
+
if (request.username) {
|
|
156
|
+
parameters.set(AADServerParamKeys.USERNAME, request.username);
|
|
157
|
+
} else if (request.userObjectId) {
|
|
158
|
+
parameters.set(AADServerParamKeys.USER_ID, request.userObjectId);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
RequestParameterBuilder.addLibraryInfo(
|
|
162
|
+
parameters,
|
|
163
|
+
this.config.libraryInfo
|
|
164
|
+
);
|
|
165
|
+
RequestParameterBuilder.addApplicationTelemetry(
|
|
166
|
+
parameters,
|
|
167
|
+
this.config.telemetry.application
|
|
168
|
+
);
|
|
169
|
+
RequestParameterBuilder.addThrottling(parameters);
|
|
170
|
+
|
|
171
|
+
if (this.serverTelemetryManager) {
|
|
172
|
+
RequestParameterBuilder.addServerTelemetry(
|
|
173
|
+
parameters,
|
|
174
|
+
this.serverTelemetryManager
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const correlationId =
|
|
179
|
+
request.correlationId ||
|
|
180
|
+
this.config.cryptoInterface.createNewGuid();
|
|
181
|
+
RequestParameterBuilder.addCorrelationId(parameters, correlationId);
|
|
182
|
+
|
|
183
|
+
// Add client credentials (secret or assertion)
|
|
184
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
185
|
+
RequestParameterBuilder.addClientSecret(
|
|
186
|
+
parameters,
|
|
187
|
+
this.config.clientCredentials.clientSecret
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Use per-request client assertion if provided, otherwise fall back to app-level
|
|
192
|
+
const clientAssertion: ClientAssertion | undefined =
|
|
193
|
+
request.clientAssertion ||
|
|
194
|
+
this.config.clientCredentials.clientAssertion;
|
|
195
|
+
|
|
196
|
+
if (clientAssertion) {
|
|
197
|
+
RequestParameterBuilder.addClientAssertion(
|
|
198
|
+
parameters,
|
|
199
|
+
await getClientAssertion(
|
|
200
|
+
clientAssertion.assertion,
|
|
201
|
+
this.config.authOptions.clientId,
|
|
202
|
+
this.authority.tokenEndpoint
|
|
203
|
+
)
|
|
204
|
+
);
|
|
205
|
+
RequestParameterBuilder.addClientAssertionType(
|
|
206
|
+
parameters,
|
|
207
|
+
clientAssertion.assertionType
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (
|
|
212
|
+
request.claims ||
|
|
213
|
+
(this.config.authOptions.clientCapabilities &&
|
|
214
|
+
this.config.authOptions.clientCapabilities.length > 0)
|
|
215
|
+
) {
|
|
216
|
+
RequestParameterBuilder.addClaims(
|
|
217
|
+
parameters,
|
|
218
|
+
request.correlationId,
|
|
219
|
+
request.claims,
|
|
220
|
+
this.config.authOptions.clientCapabilities
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return UrlUtils.mapToQueryString(parameters);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -137,7 +137,11 @@ export class UsernamePasswordClient extends BaseClient {
|
|
|
137
137
|
RequestParameterBuilder.addUsername(parameters, request.username);
|
|
138
138
|
RequestParameterBuilder.addPassword(parameters, request.password);
|
|
139
139
|
|
|
140
|
-
RequestParameterBuilder.addScopes(
|
|
140
|
+
RequestParameterBuilder.addScopes(
|
|
141
|
+
parameters,
|
|
142
|
+
request.scopes,
|
|
143
|
+
request.correlationId
|
|
144
|
+
);
|
|
141
145
|
|
|
142
146
|
RequestParameterBuilder.addResponseType(
|
|
143
147
|
parameters,
|
|
@@ -204,6 +208,7 @@ export class UsernamePasswordClient extends BaseClient {
|
|
|
204
208
|
) {
|
|
205
209
|
RequestParameterBuilder.addClaims(
|
|
206
210
|
parameters,
|
|
211
|
+
request.correlationId,
|
|
207
212
|
request.claims,
|
|
208
213
|
this.config.authOptions.clientCapabilities
|
|
209
214
|
);
|
|
@@ -41,7 +41,8 @@ export class ManagedIdentityId {
|
|
|
41
41
|
if (userAssignedClientId) {
|
|
42
42
|
if (userAssignedResourceId || userAssignedObjectId) {
|
|
43
43
|
throw createManagedIdentityError(
|
|
44
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
44
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType,
|
|
45
|
+
""
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -50,7 +51,8 @@ export class ManagedIdentityId {
|
|
|
50
51
|
} else if (userAssignedResourceId) {
|
|
51
52
|
if (userAssignedClientId || userAssignedObjectId) {
|
|
52
53
|
throw createManagedIdentityError(
|
|
53
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
54
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType,
|
|
55
|
+
""
|
|
54
56
|
);
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -59,7 +61,8 @@ export class ManagedIdentityId {
|
|
|
59
61
|
} else if (userAssignedObjectId) {
|
|
60
62
|
if (userAssignedClientId || userAssignedResourceId) {
|
|
61
63
|
throw createManagedIdentityError(
|
|
62
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
64
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType,
|
|
65
|
+
""
|
|
63
66
|
);
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -7,6 +7,9 @@ export const missingTenantIdError = "missing_tenant_id_error";
|
|
|
7
7
|
export const userTimeoutReached = "user_timeout_reached";
|
|
8
8
|
export const invalidAssertion = "invalid_assertion";
|
|
9
9
|
export const invalidClientCredential = "invalid_client_credential";
|
|
10
|
+
export const emptyFicAssertion = "empty_fic_assertion";
|
|
11
|
+
export const conflictingUserIdentifiers = "conflicting_user_identifiers";
|
|
12
|
+
export const missingUserIdentifier = "missing_user_identifier";
|
|
10
13
|
export const deviceCodePollingCancelled = "device_code_polling_cancelled";
|
|
11
14
|
export const deviceCodeExpired = "device_code_expired";
|
|
12
15
|
export const deviceCodeUnknownError = "device_code_unknown_error";
|
|
@@ -51,15 +51,20 @@ export const ManagedIdentityErrorMessages = {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export class ManagedIdentityError extends AuthError {
|
|
54
|
-
constructor(errorCode: string) {
|
|
55
|
-
super(
|
|
54
|
+
constructor(errorCode: string, correlationId: string) {
|
|
55
|
+
super(
|
|
56
|
+
errorCode,
|
|
57
|
+
correlationId,
|
|
58
|
+
ManagedIdentityErrorMessages[errorCode]
|
|
59
|
+
);
|
|
56
60
|
this.name = "ManagedIdentityError";
|
|
57
61
|
Object.setPrototypeOf(this, ManagedIdentityError.prototype);
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
export function createManagedIdentityError(
|
|
62
|
-
errorCode: string
|
|
66
|
+
errorCode: string,
|
|
67
|
+
correlationId: string
|
|
63
68
|
): ManagedIdentityError {
|
|
64
|
-
return new ManagedIdentityError(errorCode);
|
|
69
|
+
return new ManagedIdentityError(errorCode, correlationId);
|
|
65
70
|
}
|