@azure/msal-node 2.7.0 → 2.7.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cache/NodeStorage.cjs +1 -1
- package/dist/cache/NodeStorage.mjs +1 -1
- package/dist/cache/TokenCache.cjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.cjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
- package/dist/cache/serializer/Deserializer.cjs +1 -1
- package/dist/cache/serializer/Deserializer.mjs +1 -1
- package/dist/cache/serializer/Serializer.cjs +1 -1
- package/dist/cache/serializer/Serializer.mjs +1 -1
- package/dist/client/ClientApplication.cjs +6 -4
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +2 -1
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +7 -5
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.cjs +1 -1
- package/dist/client/ClientAssertion.mjs +1 -1
- package/dist/client/ClientCredentialClient.cjs +5 -5
- package/dist/client/ClientCredentialClient.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +6 -6
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.cjs +6 -3
- package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +11 -8
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.cjs +1 -1
- package/dist/client/DeviceCodeClient.mjs +1 -1
- package/dist/client/ManagedIdentityApplication.cjs +3 -9
- package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
- package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
- package/dist/client/ManagedIdentityApplication.mjs +4 -10
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
- package/dist/client/ManagedIdentityClient.cjs +1 -1
- package/dist/client/ManagedIdentityClient.mjs +1 -1
- package/dist/client/ManagedIdentitySources/AppService.cjs +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +11 -7
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +12 -8
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +1 -1
- package/dist/client/ManagedIdentitySources/Imds.cjs +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +1 -1
- package/dist/client/OnBehalfOfClient.cjs +7 -7
- package/dist/client/OnBehalfOfClient.cjs.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.mjs +8 -8
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- package/dist/client/PublicClientApplication.cjs +1 -1
- package/dist/client/PublicClientApplication.mjs +1 -1
- package/dist/client/UsernamePasswordClient.cjs +6 -6
- package/dist/client/UsernamePasswordClient.cjs.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.mjs +7 -7
- package/dist/client/UsernamePasswordClient.mjs.map +1 -1
- package/dist/config/Configuration.cjs +1 -1
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +6 -3
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +1 -1
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/config/ManagedIdentityId.cjs +1 -1
- package/dist/config/ManagedIdentityId.mjs +1 -1
- package/dist/config/ManagedIdentityRequestParameters.cjs +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
- package/dist/crypto/CryptoProvider.cjs +1 -1
- package/dist/crypto/CryptoProvider.mjs +1 -1
- package/dist/crypto/GuidGenerator.cjs +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/HashUtils.cjs +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/PkceGenerator.cjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/error/ManagedIdentityError.cjs +1 -2
- package/dist/error/ManagedIdentityError.cjs.map +1 -1
- package/dist/error/ManagedIdentityError.d.ts +0 -1
- package/dist/error/ManagedIdentityError.d.ts.map +1 -1
- package/dist/error/ManagedIdentityError.mjs +2 -3
- package/dist/error/ManagedIdentityError.mjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.cjs +1 -3
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts +0 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +2 -3
- package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
- package/dist/error/NodeAuthError.cjs +1 -1
- package/dist/error/NodeAuthError.mjs +1 -1
- package/dist/index.cjs +21 -21
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/network/HttpClient.cjs +23 -25
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +2 -2
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +23 -25
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/HttpClientWithRetries.cjs +1 -1
- package/dist/network/HttpClientWithRetries.mjs +1 -1
- package/dist/network/LoopbackClient.cjs +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/packageMetadata.cjs +2 -2
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/ClientCredentialRequest.d.ts +3 -3
- package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
- package/dist/retry/LinearRetryPolicy.cjs +1 -1
- package/dist/retry/LinearRetryPolicy.mjs +1 -1
- package/dist/utils/Constants.cjs +6 -5
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +2 -1
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +6 -5
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +1 -1
- package/dist/utils/EncodingUtils.mjs +1 -1
- package/dist/utils/NetworkUtils.cjs +1 -1
- package/dist/utils/NetworkUtils.mjs +1 -1
- package/package.json +2 -2
- package/src/client/ClientApplication.ts +19 -6
- package/src/client/ClientCredentialClient.ts +14 -6
- package/src/client/ConfidentialClientApplication.ts +10 -5
- package/src/client/ManagedIdentityApplication.ts +5 -13
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +12 -9
- package/src/client/OnBehalfOfClient.ts +18 -7
- package/src/client/UsernamePasswordClient.ts +16 -7
- package/src/config/Configuration.ts +6 -2
- package/src/error/ManagedIdentityError.ts +0 -2
- package/src/error/ManagedIdentityErrorCodes.ts +0 -1
- package/src/index.ts +1 -0
- package/src/network/HttpClient.ts +23 -30
- package/src/packageMetadata.ts +1 -1
- package/src/request/ClientCredentialRequest.ts +6 -3
- package/src/utils/Constants.ts +5 -4
|
@@ -33,6 +33,9 @@ import {
|
|
|
33
33
|
createClientAuthError,
|
|
34
34
|
ClientAuthErrorCodes,
|
|
35
35
|
buildStaticAuthorityOptions,
|
|
36
|
+
ClientAssertion as ClientAssertionType,
|
|
37
|
+
getClientAssertion,
|
|
38
|
+
ClientAssertionCallback,
|
|
36
39
|
} from "@azure/msal-common";
|
|
37
40
|
import {
|
|
38
41
|
Configuration,
|
|
@@ -77,6 +80,9 @@ export abstract class ClientApplication {
|
|
|
77
80
|
* Client assertion passed by the user for confidential client flows
|
|
78
81
|
*/
|
|
79
82
|
protected clientAssertion: ClientAssertion;
|
|
83
|
+
protected developerProvidedClientAssertion:
|
|
84
|
+
| string
|
|
85
|
+
| ClientAssertionCallback;
|
|
80
86
|
/**
|
|
81
87
|
* Client secret passed by the user for confidential client flows
|
|
82
88
|
*/
|
|
@@ -451,8 +457,8 @@ export abstract class ClientApplication {
|
|
|
451
457
|
serverTelemetryManager: serverTelemetryManager,
|
|
452
458
|
clientCredentials: {
|
|
453
459
|
clientSecret: this.clientSecret,
|
|
454
|
-
clientAssertion: this.
|
|
455
|
-
? this.getClientAssertion(discoveredAuthority)
|
|
460
|
+
clientAssertion: this.developerProvidedClientAssertion
|
|
461
|
+
? await this.getClientAssertion(discoveredAuthority)
|
|
456
462
|
: undefined,
|
|
457
463
|
},
|
|
458
464
|
libraryInfo: {
|
|
@@ -469,10 +475,17 @@ export abstract class ClientApplication {
|
|
|
469
475
|
return clientConfiguration;
|
|
470
476
|
}
|
|
471
477
|
|
|
472
|
-
private getClientAssertion(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
478
|
+
private async getClientAssertion(
|
|
479
|
+
authority: Authority
|
|
480
|
+
): Promise<ClientAssertionType> {
|
|
481
|
+
this.clientAssertion = ClientAssertion.fromAssertion(
|
|
482
|
+
await getClientAssertion(
|
|
483
|
+
this.developerProvidedClientAssertion,
|
|
484
|
+
this.config.auth.clientId,
|
|
485
|
+
authority.tokenEndpoint
|
|
486
|
+
)
|
|
487
|
+
);
|
|
488
|
+
|
|
476
489
|
return {
|
|
477
490
|
assertion: this.clientAssertion.getJwt(
|
|
478
491
|
this.cryptoProvider,
|
|
@@ -32,6 +32,8 @@ import {
|
|
|
32
32
|
TokenCacheContext,
|
|
33
33
|
UrlString,
|
|
34
34
|
createClientAuthError,
|
|
35
|
+
ClientAssertion,
|
|
36
|
+
getClientAssertion,
|
|
35
37
|
} from "@azure/msal-common";
|
|
36
38
|
import {
|
|
37
39
|
ManagedIdentityConfiguration,
|
|
@@ -59,7 +61,7 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
59
61
|
public async acquireToken(
|
|
60
62
|
request: CommonClientCredentialRequest
|
|
61
63
|
): Promise<AuthenticationResult | null> {
|
|
62
|
-
if (request.skipCache) {
|
|
64
|
+
if (request.skipCache || request.claims) {
|
|
63
65
|
return this.executeTokenRequest(request, this.authority);
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -270,7 +272,7 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
270
272
|
queryParametersString
|
|
271
273
|
);
|
|
272
274
|
|
|
273
|
-
const requestBody = this.createTokenRequestBody(request);
|
|
275
|
+
const requestBody = await this.createTokenRequestBody(request);
|
|
274
276
|
const headers: Record<string, string> =
|
|
275
277
|
this.createTokenRequestHeaders();
|
|
276
278
|
const thumbprint: RequestThumbprint = {
|
|
@@ -330,9 +332,9 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
330
332
|
* generate the request to the server in the acceptable format
|
|
331
333
|
* @param request
|
|
332
334
|
*/
|
|
333
|
-
private createTokenRequestBody(
|
|
335
|
+
private async createTokenRequestBody(
|
|
334
336
|
request: CommonClientCredentialRequest
|
|
335
|
-
): string {
|
|
337
|
+
): Promise<string> {
|
|
336
338
|
const parameterBuilder = new RequestParameterBuilder();
|
|
337
339
|
|
|
338
340
|
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
@@ -364,12 +366,18 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
364
366
|
}
|
|
365
367
|
|
|
366
368
|
// Use clientAssertion from request, fallback to client assertion in base configuration
|
|
367
|
-
const clientAssertion =
|
|
369
|
+
const clientAssertion: ClientAssertion | undefined =
|
|
368
370
|
request.clientAssertion ||
|
|
369
371
|
this.config.clientCredentials.clientAssertion;
|
|
370
372
|
|
|
371
373
|
if (clientAssertion) {
|
|
372
|
-
parameterBuilder.addClientAssertion(
|
|
374
|
+
parameterBuilder.addClientAssertion(
|
|
375
|
+
await getClientAssertion(
|
|
376
|
+
clientAssertion.assertion,
|
|
377
|
+
this.config.authOptions.clientId,
|
|
378
|
+
request.resourceRequestUri
|
|
379
|
+
)
|
|
380
|
+
);
|
|
373
381
|
parameterBuilder.addClientAssertionType(
|
|
374
382
|
clientAssertion.assertionType
|
|
375
383
|
);
|
|
@@ -26,6 +26,8 @@ import {
|
|
|
26
26
|
AADAuthorityConstants,
|
|
27
27
|
createClientAuthError,
|
|
28
28
|
ClientAuthErrorCodes,
|
|
29
|
+
ClientAssertion as ClientAssertionType,
|
|
30
|
+
getClientAssertion,
|
|
29
31
|
} from "@azure/msal-common";
|
|
30
32
|
import { IConfidentialClientApplication } from "./IConfidentialClientApplication.js";
|
|
31
33
|
import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest.js";
|
|
@@ -91,10 +93,14 @@ export class ConfidentialClientApplication
|
|
|
91
93
|
);
|
|
92
94
|
|
|
93
95
|
// If there is a client assertion present in the request, it overrides the one present in the client configuration
|
|
94
|
-
let clientAssertion;
|
|
96
|
+
let clientAssertion: ClientAssertionType | undefined;
|
|
95
97
|
if (request.clientAssertion) {
|
|
96
98
|
clientAssertion = {
|
|
97
|
-
assertion:
|
|
99
|
+
assertion: await getClientAssertion(
|
|
100
|
+
request.clientAssertion,
|
|
101
|
+
this.config.auth.clientId
|
|
102
|
+
// tokenEndpoint will be undefined. resourceRequestUri is omitted in ClientCredentialRequest
|
|
103
|
+
),
|
|
98
104
|
assertionType: NodeConstants.JWT_BEARER_ASSERTION_TYPE,
|
|
99
105
|
};
|
|
100
106
|
}
|
|
@@ -247,9 +253,8 @@ export class ConfidentialClientApplication
|
|
|
247
253
|
}
|
|
248
254
|
|
|
249
255
|
if (configuration.auth.clientAssertion) {
|
|
250
|
-
this.
|
|
251
|
-
configuration.auth.clientAssertion
|
|
252
|
-
);
|
|
256
|
+
this.developerProvidedClientAssertion =
|
|
257
|
+
configuration.auth.clientAssertion;
|
|
253
258
|
return;
|
|
254
259
|
}
|
|
255
260
|
|
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
ProtocolMode,
|
|
17
17
|
StaticAuthorityOptions,
|
|
18
18
|
AuthenticationResult,
|
|
19
|
-
|
|
19
|
+
createClientConfigurationError,
|
|
20
|
+
ClientConfigurationErrorCodes,
|
|
20
21
|
} from "@azure/msal-common";
|
|
21
22
|
import {
|
|
22
23
|
ManagedIdentityConfiguration,
|
|
@@ -31,10 +32,6 @@ import { ManagedIdentityClient } from "./ManagedIdentityClient";
|
|
|
31
32
|
import { ManagedIdentityRequestParams } from "../request/ManagedIdentityRequestParams";
|
|
32
33
|
import { NodeStorage } from "../cache/NodeStorage";
|
|
33
34
|
import { DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY } from "../utils/Constants";
|
|
34
|
-
import {
|
|
35
|
-
ManagedIdentityErrorCodes,
|
|
36
|
-
createManagedIdentityError,
|
|
37
|
-
} from "../error/ManagedIdentityError";
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
37
|
* Class to initialize a managed identity and identify the service
|
|
@@ -122,14 +119,9 @@ export class ManagedIdentityApplication {
|
|
|
122
119
|
public async acquireToken(
|
|
123
120
|
managedIdentityRequestParams: ManagedIdentityRequestParams
|
|
124
121
|
): Promise<AuthenticationResult> {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
resourceUrlString.validateAsUri();
|
|
130
|
-
} catch (e) {
|
|
131
|
-
throw createManagedIdentityError(
|
|
132
|
-
ManagedIdentityErrorCodes.invalidResource
|
|
122
|
+
if (!managedIdentityRequestParams.resource) {
|
|
123
|
+
throw createClientConfigurationError(
|
|
124
|
+
ClientConfigurationErrorCodes.urlEmptyError
|
|
133
125
|
);
|
|
134
126
|
}
|
|
135
127
|
|
|
@@ -81,28 +81,31 @@ export abstract class BaseManagedIdentitySource {
|
|
|
81
81
|
public getServerTokenResponse(
|
|
82
82
|
response: NetworkResponse<ManagedIdentityTokenResponse>
|
|
83
83
|
): ServerAuthorizationTokenResponse {
|
|
84
|
+
let refreshIn, expiresIn: number | undefined;
|
|
85
|
+
if (response.body.expires_on) {
|
|
86
|
+
expiresIn = response.body.expires_on - TimeUtils.nowSeconds();
|
|
87
|
+
|
|
88
|
+
// compute refresh_in as 1/2 of expires_in, but only if expires_in > 2h
|
|
89
|
+
if (expiresIn > 2 * 3600) {
|
|
90
|
+
refreshIn = expiresIn / 2;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
84
94
|
const serverTokenResponse: ServerAuthorizationTokenResponse = {
|
|
85
95
|
status: response.status,
|
|
86
96
|
|
|
87
97
|
// success
|
|
88
98
|
access_token: response.body.access_token,
|
|
89
|
-
expires_in:
|
|
99
|
+
expires_in: expiresIn,
|
|
90
100
|
scope: response.body.resource,
|
|
91
101
|
token_type: response.body.token_type,
|
|
102
|
+
refresh_in: refreshIn,
|
|
92
103
|
|
|
93
104
|
// error
|
|
94
105
|
error: response.body.message,
|
|
95
106
|
correlation_id: response.body.correlationId,
|
|
96
107
|
};
|
|
97
108
|
|
|
98
|
-
// compute refresh_in as 1/2 of expires_in, but only if expires_in > 2h
|
|
99
|
-
if (
|
|
100
|
-
serverTokenResponse.expires_in &&
|
|
101
|
-
serverTokenResponse.expires_in > 2 * 3600
|
|
102
|
-
) {
|
|
103
|
-
serverTokenResponse.refresh_in = serverTokenResponse.expires_in / 2;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
109
|
return serverTokenResponse;
|
|
107
110
|
}
|
|
108
111
|
|
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
TimeUtils,
|
|
31
31
|
TokenClaims,
|
|
32
32
|
UrlString,
|
|
33
|
+
ClientAssertion,
|
|
34
|
+
getClientAssertion,
|
|
33
35
|
} from "@azure/msal-common";
|
|
34
36
|
import { EncodingUtils } from "../utils/EncodingUtils";
|
|
35
37
|
|
|
@@ -58,7 +60,7 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
58
60
|
request.oboAssertion
|
|
59
61
|
);
|
|
60
62
|
|
|
61
|
-
if (request.skipCache) {
|
|
63
|
+
if (request.skipCache || request.claims) {
|
|
62
64
|
return this.executeTokenRequest(
|
|
63
65
|
request,
|
|
64
66
|
this.authority,
|
|
@@ -257,7 +259,7 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
257
259
|
authority.tokenEndpoint,
|
|
258
260
|
queryParametersString
|
|
259
261
|
);
|
|
260
|
-
const requestBody = this.createTokenRequestBody(request);
|
|
262
|
+
const requestBody = await this.createTokenRequestBody(request);
|
|
261
263
|
const headers: Record<string, string> =
|
|
262
264
|
this.createTokenRequestHeaders();
|
|
263
265
|
const thumbprint: RequestThumbprint = {
|
|
@@ -307,7 +309,9 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
307
309
|
* generate a server request in accepable format
|
|
308
310
|
* @param request
|
|
309
311
|
*/
|
|
310
|
-
private createTokenRequestBody(
|
|
312
|
+
private async createTokenRequestBody(
|
|
313
|
+
request: CommonOnBehalfOfRequest
|
|
314
|
+
): Promise<string> {
|
|
311
315
|
const parameterBuilder = new RequestParameterBuilder();
|
|
312
316
|
|
|
313
317
|
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
@@ -343,10 +347,17 @@ export class OnBehalfOfClient extends BaseClient {
|
|
|
343
347
|
);
|
|
344
348
|
}
|
|
345
349
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
+
const clientAssertion: ClientAssertion | undefined =
|
|
351
|
+
this.config.clientCredentials.clientAssertion;
|
|
352
|
+
|
|
353
|
+
if (clientAssertion) {
|
|
354
|
+
parameterBuilder.addClientAssertion(
|
|
355
|
+
await getClientAssertion(
|
|
356
|
+
clientAssertion.assertion,
|
|
357
|
+
this.config.authOptions.clientId,
|
|
358
|
+
request.resourceRequestUri
|
|
359
|
+
)
|
|
360
|
+
);
|
|
350
361
|
parameterBuilder.addClientAssertionType(
|
|
351
362
|
clientAssertion.assertionType
|
|
352
363
|
);
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Authority,
|
|
9
9
|
BaseClient,
|
|
10
10
|
CcsCredentialType,
|
|
11
|
+
ClientAssertion,
|
|
11
12
|
ClientConfiguration,
|
|
12
13
|
CommonUsernamePasswordRequest,
|
|
13
14
|
GrantType,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
StringUtils,
|
|
20
21
|
TimeUtils,
|
|
21
22
|
UrlString,
|
|
23
|
+
getClientAssertion,
|
|
22
24
|
} from "@azure/msal-common";
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -81,7 +83,7 @@ export class UsernamePasswordClient extends BaseClient {
|
|
|
81
83
|
authority.tokenEndpoint,
|
|
82
84
|
queryParametersString
|
|
83
85
|
);
|
|
84
|
-
const requestBody = this.createTokenRequestBody(request);
|
|
86
|
+
const requestBody = await this.createTokenRequestBody(request);
|
|
85
87
|
const headers: Record<string, string> = this.createTokenRequestHeaders({
|
|
86
88
|
credential: request.username,
|
|
87
89
|
type: CcsCredentialType.UPN,
|
|
@@ -111,9 +113,9 @@ export class UsernamePasswordClient extends BaseClient {
|
|
|
111
113
|
* Generates a map for all the params to be sent to the service
|
|
112
114
|
* @param request
|
|
113
115
|
*/
|
|
114
|
-
private createTokenRequestBody(
|
|
116
|
+
private async createTokenRequestBody(
|
|
115
117
|
request: CommonUsernamePasswordRequest
|
|
116
|
-
): string {
|
|
118
|
+
): Promise<string> {
|
|
117
119
|
const parameterBuilder = new RequestParameterBuilder();
|
|
118
120
|
|
|
119
121
|
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
@@ -148,10 +150,17 @@ export class UsernamePasswordClient extends BaseClient {
|
|
|
148
150
|
);
|
|
149
151
|
}
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const clientAssertion: ClientAssertion | undefined =
|
|
154
|
+
this.config.clientCredentials.clientAssertion;
|
|
155
|
+
|
|
156
|
+
if (clientAssertion) {
|
|
157
|
+
parameterBuilder.addClientAssertion(
|
|
158
|
+
await getClientAssertion(
|
|
159
|
+
clientAssertion.assertion,
|
|
160
|
+
this.config.authOptions.clientId,
|
|
161
|
+
request.resourceRequestUri
|
|
162
|
+
)
|
|
163
|
+
);
|
|
155
164
|
parameterBuilder.addClientAssertionType(
|
|
156
165
|
clientAssertion.assertionType
|
|
157
166
|
);
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
AzureCloudOptions,
|
|
15
15
|
ApplicationTelemetry,
|
|
16
16
|
INativeBrokerPlugin,
|
|
17
|
+
ClientAssertionCallback,
|
|
17
18
|
} from "@azure/msal-common";
|
|
18
19
|
import { HttpClient } from "../network/HttpClient.js";
|
|
19
20
|
import http from "http";
|
|
@@ -32,7 +33,7 @@ import { HttpClientWithRetries } from "../network/HttpClientWithRetries.js";
|
|
|
32
33
|
* - authority - Url of the authority. If no value is set, defaults to https://login.microsoftonline.com/common.
|
|
33
34
|
* - knownAuthorities - Needed for Azure B2C and ADFS. All authorities that will be used in the client application. Only the host of the authority should be passed in.
|
|
34
35
|
* - clientSecret - Secret string that the application uses when requesting a token. Only used in confidential client applications. Can be created in the Azure app registration portal.
|
|
35
|
-
* - clientAssertion -
|
|
36
|
+
* - clientAssertion - A ClientAssertion object containing an assertion string or a callback function that returns an assertion string that the application uses when requesting a token, as well as the assertion's type (urn:ietf:params:oauth:client-assertion-type:jwt-bearer). Only used in confidential client applications.
|
|
36
37
|
* - clientCertificate - Certificate that the application uses when requesting a token. Only used in confidential client applications. Requires hex encoded X.509 SHA-1 thumbprint of the certificiate, and the PEM encoded private key (string should contain -----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY----- )
|
|
37
38
|
* - protocolMode - Enum that represents the protocol that msal follows. Used for configuring proper endpoints.
|
|
38
39
|
* - skipAuthorityMetadataCache - A flag to choose whether to use or not use the local metadata cache during authority initialization. Defaults to false.
|
|
@@ -42,7 +43,7 @@ export type NodeAuthOptions = {
|
|
|
42
43
|
clientId: string;
|
|
43
44
|
authority?: string;
|
|
44
45
|
clientSecret?: string;
|
|
45
|
-
clientAssertion?: string;
|
|
46
|
+
clientAssertion?: string | ClientAssertionCallback;
|
|
46
47
|
clientCertificate?: {
|
|
47
48
|
thumbprint: string;
|
|
48
49
|
privateKey: string;
|
|
@@ -65,6 +66,9 @@ export type NodeAuthOptions = {
|
|
|
65
66
|
*/
|
|
66
67
|
export type CacheOptions = {
|
|
67
68
|
cachePlugin?: ICachePlugin;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated claims-based-caching functionality will be removed in the next version of MSALJS
|
|
71
|
+
*/
|
|
68
72
|
claimsBasedCachingEnabled?: boolean;
|
|
69
73
|
};
|
|
70
74
|
|
|
@@ -14,8 +14,6 @@ export { ManagedIdentityErrorCodes };
|
|
|
14
14
|
export const ManagedIdentityErrorMessages = {
|
|
15
15
|
[ManagedIdentityErrorCodes.invalidManagedIdentityIdType]:
|
|
16
16
|
"More than one ManagedIdentityIdType was provided.",
|
|
17
|
-
[ManagedIdentityErrorCodes.invalidResource]:
|
|
18
|
-
"The supplied resource is an invalid URL.",
|
|
19
17
|
[ManagedIdentityErrorCodes.missingId]:
|
|
20
18
|
"A ManagedIdentityId id was not provided.",
|
|
21
19
|
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import { ManagedIdentityEnvironmentVariableNames } from "../utils/Constants";
|
|
7
7
|
|
|
8
8
|
export const invalidManagedIdentityIdType = "invalid_managed_identity_id_type";
|
|
9
|
-
export const invalidResource = "invalid_resource";
|
|
10
9
|
export const missingId = "missing_client_id";
|
|
11
10
|
export const networkUnavailable = "network_unavailable";
|
|
12
11
|
export const unableToCreateAzureArc = "unable_to_create_azure_arc";
|
package/src/index.ts
CHANGED
|
@@ -36,7 +36,8 @@ export class HttpClient implements INetworkModule {
|
|
|
36
36
|
*/
|
|
37
37
|
async sendGetRequestAsync<T>(
|
|
38
38
|
url: string,
|
|
39
|
-
options?: NetworkRequestOptions
|
|
39
|
+
options?: NetworkRequestOptions,
|
|
40
|
+
timeout?: number
|
|
40
41
|
): Promise<NetworkResponse<T>> {
|
|
41
42
|
if (this.proxyUrl) {
|
|
42
43
|
return networkRequestViaProxy(
|
|
@@ -44,7 +45,8 @@ export class HttpClient implements INetworkModule {
|
|
|
44
45
|
this.proxyUrl,
|
|
45
46
|
HttpMethod.GET,
|
|
46
47
|
options,
|
|
47
|
-
this.customAgentOptions as http.AgentOptions
|
|
48
|
+
this.customAgentOptions as http.AgentOptions,
|
|
49
|
+
timeout
|
|
48
50
|
);
|
|
49
51
|
} else {
|
|
50
52
|
return networkRequestViaHttps(
|
|
@@ -52,7 +54,7 @@ export class HttpClient implements INetworkModule {
|
|
|
52
54
|
HttpMethod.GET,
|
|
53
55
|
options,
|
|
54
56
|
this.customAgentOptions as https.AgentOptions,
|
|
55
|
-
|
|
57
|
+
timeout
|
|
56
58
|
);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
@@ -64,8 +66,7 @@ export class HttpClient implements INetworkModule {
|
|
|
64
66
|
*/
|
|
65
67
|
async sendPostRequestAsync<T>(
|
|
66
68
|
url: string,
|
|
67
|
-
options?: NetworkRequestOptions
|
|
68
|
-
cancellationToken?: number
|
|
69
|
+
options?: NetworkRequestOptions
|
|
69
70
|
): Promise<NetworkResponse<T>> {
|
|
70
71
|
if (this.proxyUrl) {
|
|
71
72
|
return networkRequestViaProxy(
|
|
@@ -73,16 +74,14 @@ export class HttpClient implements INetworkModule {
|
|
|
73
74
|
this.proxyUrl,
|
|
74
75
|
HttpMethod.POST,
|
|
75
76
|
options,
|
|
76
|
-
this.customAgentOptions as http.AgentOptions
|
|
77
|
-
cancellationToken
|
|
77
|
+
this.customAgentOptions as http.AgentOptions
|
|
78
78
|
);
|
|
79
79
|
} else {
|
|
80
80
|
return networkRequestViaHttps(
|
|
81
81
|
url,
|
|
82
82
|
HttpMethod.POST,
|
|
83
83
|
options,
|
|
84
|
-
this.customAgentOptions as https.AgentOptions
|
|
85
|
-
cancellationToken
|
|
84
|
+
this.customAgentOptions as https.AgentOptions
|
|
86
85
|
);
|
|
87
86
|
}
|
|
88
87
|
}
|
|
@@ -109,10 +108,6 @@ const networkRequestViaProxy = <T>(
|
|
|
109
108
|
headers: headers,
|
|
110
109
|
};
|
|
111
110
|
|
|
112
|
-
if (timeout) {
|
|
113
|
-
tunnelRequestOptions.timeout = timeout;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
111
|
if (agentOptions && Object.keys(agentOptions).length) {
|
|
117
112
|
tunnelRequestOptions.agent = new http.Agent(agentOptions);
|
|
118
113
|
}
|
|
@@ -125,6 +120,11 @@ const networkRequestViaProxy = <T>(
|
|
|
125
120
|
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
|
126
121
|
`Content-Length: ${body.length}\r\n` +
|
|
127
122
|
`\r\n${body}`;
|
|
123
|
+
} else {
|
|
124
|
+
// optional timeout is only for get requests (regionDiscovery, for example)
|
|
125
|
+
if (timeout) {
|
|
126
|
+
tunnelRequestOptions.timeout = timeout;
|
|
127
|
+
}
|
|
128
128
|
}
|
|
129
129
|
const outgoingRequestString =
|
|
130
130
|
`${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` +
|
|
@@ -136,7 +136,7 @@ const networkRequestViaProxy = <T>(
|
|
|
136
136
|
return new Promise<NetworkResponse<T>>((resolve, reject) => {
|
|
137
137
|
const request = http.request(tunnelRequestOptions);
|
|
138
138
|
|
|
139
|
-
if (
|
|
139
|
+
if (timeout) {
|
|
140
140
|
request.on("timeout", () => {
|
|
141
141
|
request.destroy();
|
|
142
142
|
reject(new Error("Request time out"));
|
|
@@ -165,14 +165,6 @@ const networkRequestViaProxy = <T>(
|
|
|
165
165
|
)
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
|
-
if (tunnelRequestOptions.timeout) {
|
|
169
|
-
socket.setTimeout(tunnelRequestOptions.timeout);
|
|
170
|
-
socket.on("timeout", () => {
|
|
171
|
-
request.destroy();
|
|
172
|
-
socket.destroy();
|
|
173
|
-
reject(new Error("Request time out"));
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
168
|
|
|
177
169
|
// make a request over an HTTP tunnel
|
|
178
170
|
socket.write(outgoingRequestString);
|
|
@@ -291,10 +283,6 @@ const networkRequestViaHttps = <T>(
|
|
|
291
283
|
...NetworkUtils.urlToHttpOptions(url),
|
|
292
284
|
};
|
|
293
285
|
|
|
294
|
-
if (timeout) {
|
|
295
|
-
customOptions.timeout = timeout;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
286
|
if (agentOptions && Object.keys(agentOptions).length) {
|
|
299
287
|
customOptions.agent = new https.Agent(agentOptions);
|
|
300
288
|
}
|
|
@@ -305,6 +293,11 @@ const networkRequestViaHttps = <T>(
|
|
|
305
293
|
...customOptions.headers,
|
|
306
294
|
"Content-Length": body.length,
|
|
307
295
|
};
|
|
296
|
+
} else {
|
|
297
|
+
// optional timeout is only for get requests (regionDiscovery, for example)
|
|
298
|
+
if (timeout) {
|
|
299
|
+
customOptions.timeout = timeout;
|
|
300
|
+
}
|
|
308
301
|
}
|
|
309
302
|
|
|
310
303
|
return new Promise<NetworkResponse<T>>((resolve, reject) => {
|
|
@@ -316,6 +309,10 @@ const networkRequestViaHttps = <T>(
|
|
|
316
309
|
request = https.request(customOptions);
|
|
317
310
|
}
|
|
318
311
|
|
|
312
|
+
if (isPostRequest) {
|
|
313
|
+
request.write(body);
|
|
314
|
+
}
|
|
315
|
+
|
|
319
316
|
if (timeout) {
|
|
320
317
|
request.on("timeout", () => {
|
|
321
318
|
request.destroy();
|
|
@@ -323,10 +320,6 @@ const networkRequestViaHttps = <T>(
|
|
|
323
320
|
});
|
|
324
321
|
}
|
|
325
322
|
|
|
326
|
-
if (isPostRequest) {
|
|
327
|
-
request.write(body);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
323
|
request.end();
|
|
331
324
|
|
|
332
325
|
request.on("response", (response) => {
|
package/src/packageMetadata.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ClientAssertionCallback,
|
|
8
|
+
CommonClientCredentialRequest,
|
|
9
|
+
} from "@azure/msal-common";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* CommonClientCredentialRequest
|
|
@@ -11,7 +14,7 @@ import { CommonClientCredentialRequest } from "@azure/msal-common";
|
|
|
11
14
|
* - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
|
|
12
15
|
* - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
|
|
13
16
|
* - skipCache - Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
|
|
14
|
-
* - clientAssertion -
|
|
17
|
+
* - clientAssertion - An assertion string or a callback function that returns an assertion string (both are Base64Url-encoded signed JWTs) used in the Client Credential flow
|
|
15
18
|
* - tokenQueryParameters - String to string map of custom query parameters added to the /token call
|
|
16
19
|
* @public
|
|
17
20
|
*/
|
|
@@ -25,5 +28,5 @@ export type ClientCredentialRequest = Partial<
|
|
|
25
28
|
| "storeInCache"
|
|
26
29
|
>
|
|
27
30
|
> & {
|
|
28
|
-
clientAssertion?: string;
|
|
31
|
+
clientAssertion?: string | ClientAssertionCallback;
|
|
29
32
|
};
|
package/src/utils/Constants.ts
CHANGED
|
@@ -65,9 +65,10 @@ export const HttpMethod = {
|
|
|
65
65
|
export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];
|
|
66
66
|
|
|
67
67
|
export const ProxyStatus = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
SUCCESS: HttpStatus.SUCCESS,
|
|
69
|
+
SUCCESS_RANGE_START: HttpStatus.SUCCESS_RANGE_START,
|
|
70
|
+
SUCCESS_RANGE_END: HttpStatus.SUCCESS_RANGE_END,
|
|
71
|
+
SERVER_ERROR: HttpStatus.SERVER_ERROR,
|
|
71
72
|
} as const;
|
|
72
73
|
export type ProxyStatus = (typeof ProxyStatus)[keyof typeof ProxyStatus];
|
|
73
74
|
|
|
@@ -160,7 +161,7 @@ export const MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON = [
|
|
|
160
161
|
HttpStatus.NOT_FOUND,
|
|
161
162
|
HttpStatus.REQUEST_TIMEOUT,
|
|
162
163
|
HttpStatus.TOO_MANY_REQUESTS,
|
|
163
|
-
HttpStatus.
|
|
164
|
+
HttpStatus.SERVER_ERROR,
|
|
164
165
|
HttpStatus.SERVICE_UNAVAILABLE,
|
|
165
166
|
HttpStatus.GATEWAY_TIMEOUT,
|
|
166
167
|
];
|