@azure/msal-node 3.5.3 → 3.6.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/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 +1 -1
- package/dist/cache/serializer/Serializer.mjs +1 -1
- package/dist/client/ClientApplication.mjs +1 -1
- package/dist/client/ClientAssertion.d.ts.map +1 -1
- package/dist/client/ClientAssertion.mjs +3 -3
- package/dist/client/ClientAssertion.mjs.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +1 -1
- package/dist/client/DeviceCodeClient.mjs +1 -1
- package/dist/client/ManagedIdentityApplication.d.ts +11 -0
- package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
- package/dist/client/ManagedIdentityApplication.mjs +46 -11
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
- package/dist/client/ManagedIdentityClient.mjs +1 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +6 -5
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +8 -8
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +11 -2
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +4 -4
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +32 -0
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +39 -8
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs +7 -6
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +30 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +36 -10
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -1
- package/dist/client/OnBehalfOfClient.mjs +1 -1
- package/dist/client/PublicClientApplication.mjs +1 -1
- package/dist/client/UsernamePasswordClient.mjs +1 -1
- package/dist/config/Configuration.d.ts +4 -2
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +3 -2
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/config/ManagedIdentityId.mjs +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
- package/dist/crypto/CryptoProvider.d.ts.map +1 -1
- package/dist/crypto/CryptoProvider.mjs +3 -2
- package/dist/crypto/CryptoProvider.mjs.map +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +3 -3
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/error/ManagedIdentityError.mjs +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +1 -1
- package/dist/error/NodeAuthError.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/network/HttpClient.mjs +1 -1
- package/dist/network/HttpClientWithRetries.mjs +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/protocol/Authorize.mjs +1 -1
- package/dist/request/ManagedIdentityRequest.d.ts +6 -3
- package/dist/request/ManagedIdentityRequest.d.ts.map +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.d.ts +20 -6
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +20 -8
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.mjs +4 -4
- package/dist/utils/EncodingUtils.mjs.map +1 -1
- package/dist/utils/NetworkUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/lib/msal-node.cjs +234 -124
- package/lib/msal-node.cjs.map +1 -1
- package/lib/types/client/ClientAssertion.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentityApplication.d.ts +11 -0
- package/lib/types/client/ManagedIdentityApplication.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/Imds.d.ts +32 -0
- package/lib/types/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts +30 -0
- package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/lib/types/config/Configuration.d.ts +4 -2
- package/lib/types/config/Configuration.d.ts.map +1 -1
- package/lib/types/crypto/CryptoProvider.d.ts.map +1 -1
- package/lib/types/crypto/PkceGenerator.d.ts.map +1 -1
- package/lib/types/packageMetadata.d.ts +1 -1
- package/lib/types/request/ManagedIdentityRequest.d.ts +6 -3
- package/lib/types/request/ManagedIdentityRequest.d.ts.map +1 -1
- package/lib/types/utils/Constants.d.ts +20 -6
- package/lib/types/utils/Constants.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/client/ClientAssertion.ts +2 -1
- package/src/client/ManagedIdentityApplication.ts +71 -10
- package/src/client/ManagedIdentitySources/AppService.ts +6 -6
- package/src/client/ManagedIdentitySources/AzureArc.ts +10 -9
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +28 -1
- package/src/client/ManagedIdentitySources/CloudShell.ts +4 -4
- package/src/client/ManagedIdentitySources/Imds.ts +40 -10
- package/src/client/ManagedIdentitySources/MachineLearning.ts +7 -8
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +36 -11
- package/src/config/Configuration.ts +5 -1
- package/src/crypto/CryptoProvider.ts +3 -3
- package/src/crypto/PkceGenerator.ts +3 -3
- package/src/packageMetadata.ts +1 -1
- package/src/request/ManagedIdentityRequest.ts +6 -3
- package/src/utils/Constants.ts +24 -6
- package/src/utils/EncodingUtils.ts +3 -3
|
@@ -10,11 +10,11 @@ import { NodeStorage } from "../../cache/NodeStorage.js";
|
|
|
10
10
|
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
|
11
11
|
import {
|
|
12
12
|
HttpMethod,
|
|
13
|
-
METADATA_HEADER_NAME,
|
|
14
13
|
ManagedIdentityEnvironmentVariableNames,
|
|
14
|
+
ManagedIdentityHeaders,
|
|
15
15
|
ManagedIdentityIdType,
|
|
16
|
+
ManagedIdentityQueryParameters,
|
|
16
17
|
ManagedIdentitySourceNames,
|
|
17
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
18
18
|
} from "../../utils/Constants.js";
|
|
19
19
|
import {
|
|
20
20
|
ManagedIdentityErrorCodes,
|
|
@@ -109,9 +109,9 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
109
109
|
this.msiEndpoint
|
|
110
110
|
);
|
|
111
111
|
|
|
112
|
-
request.headers[METADATA_HEADER_NAME] = "true";
|
|
112
|
+
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
|
113
113
|
|
|
114
|
-
request.bodyParameters[
|
|
114
|
+
request.bodyParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
|
115
115
|
resource;
|
|
116
116
|
|
|
117
117
|
return request;
|
|
@@ -9,27 +9,37 @@ import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRe
|
|
|
9
9
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
|
10
10
|
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
|
11
11
|
import {
|
|
12
|
-
API_VERSION_QUERY_PARAMETER_NAME,
|
|
13
12
|
HttpMethod,
|
|
14
|
-
METADATA_HEADER_NAME,
|
|
15
13
|
ManagedIdentityEnvironmentVariableNames,
|
|
14
|
+
ManagedIdentityHeaders,
|
|
16
15
|
ManagedIdentityIdType,
|
|
16
|
+
ManagedIdentityQueryParameters,
|
|
17
17
|
ManagedIdentitySourceNames,
|
|
18
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
19
18
|
} from "../../utils/Constants.js";
|
|
20
19
|
import { NodeStorage } from "../../cache/NodeStorage.js";
|
|
21
20
|
import { ImdsRetryPolicy } from "../../retry/ImdsRetryPolicy.js";
|
|
22
21
|
|
|
23
|
-
//
|
|
22
|
+
// Documentation for IMDS is available at https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
|
|
23
|
+
|
|
24
24
|
const IMDS_TOKEN_PATH: string = "/metadata/identity/oauth2/token";
|
|
25
25
|
const DEFAULT_IMDS_ENDPOINT: string = `http://169.254.169.254${IMDS_TOKEN_PATH}`;
|
|
26
|
-
|
|
27
26
|
const IMDS_API_VERSION: string = "2018-02-01";
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
|
|
30
|
+
*/
|
|
30
31
|
export class Imds extends BaseManagedIdentitySource {
|
|
31
32
|
private identityEndpoint: string;
|
|
32
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Constructs an Imds instance.
|
|
36
|
+
* @param logger - Logger instance for logging.
|
|
37
|
+
* @param nodeStorage - NodeStorage instance for caching.
|
|
38
|
+
* @param networkClient - Network client for HTTP requests.
|
|
39
|
+
* @param cryptoProvider - CryptoProvider for cryptographic operations.
|
|
40
|
+
* @param disableInternalRetries - Whether to disable internal retry logic.
|
|
41
|
+
* @param identityEndpoint - The IMDS endpoint to use.
|
|
42
|
+
*/
|
|
33
43
|
constructor(
|
|
34
44
|
logger: Logger,
|
|
35
45
|
nodeStorage: NodeStorage,
|
|
@@ -49,6 +59,18 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
49
59
|
this.identityEndpoint = identityEndpoint;
|
|
50
60
|
}
|
|
51
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Attempts to create an Imds instance by determining the correct endpoint.
|
|
64
|
+
* If the AZURE_POD_IDENTITY_AUTHORITY_HOST environment variable is set, it uses that as the endpoint.
|
|
65
|
+
* Otherwise, it falls back to the default IMDS endpoint.
|
|
66
|
+
*
|
|
67
|
+
* @param logger - Logger instance for logging.
|
|
68
|
+
* @param nodeStorage - NodeStorage instance for caching.
|
|
69
|
+
* @param networkClient - Network client for HTTP requests.
|
|
70
|
+
* @param cryptoProvider - CryptoProvider for cryptographic operations.
|
|
71
|
+
* @param disableInternalRetries - Whether to disable internal retry logic.
|
|
72
|
+
* @returns An instance of Imds configured with the appropriate endpoint.
|
|
73
|
+
*/
|
|
52
74
|
public static tryCreate(
|
|
53
75
|
logger: Logger,
|
|
54
76
|
nodeStorage: NodeStorage,
|
|
@@ -102,6 +124,14 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
102
124
|
);
|
|
103
125
|
}
|
|
104
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Creates a ManagedIdentityRequestParameters object for acquiring a token from IMDS.
|
|
129
|
+
* Sets the required headers and query parameters for the IMDS token request.
|
|
130
|
+
*
|
|
131
|
+
* @param resource - The resource URI for which the token is requested.
|
|
132
|
+
* @param managedIdentityId - The managed identity ID (system-assigned or user-assigned).
|
|
133
|
+
* @returns A ManagedIdentityRequestParameters object configured for IMDS.
|
|
134
|
+
*/
|
|
105
135
|
public createRequest(
|
|
106
136
|
resource: string,
|
|
107
137
|
managedIdentityId: ManagedIdentityId
|
|
@@ -112,11 +142,11 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
112
142
|
this.identityEndpoint
|
|
113
143
|
);
|
|
114
144
|
|
|
115
|
-
request.headers[METADATA_HEADER_NAME] = "true";
|
|
145
|
+
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
|
116
146
|
|
|
117
|
-
request.queryParameters[
|
|
147
|
+
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
|
118
148
|
IMDS_API_VERSION;
|
|
119
|
-
request.queryParameters[
|
|
149
|
+
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
|
120
150
|
resource;
|
|
121
151
|
|
|
122
152
|
if (
|
|
@@ -130,7 +160,7 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
130
160
|
] = managedIdentityId.id;
|
|
131
161
|
}
|
|
132
162
|
|
|
133
|
-
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
163
|
+
// The bodyParameters are calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity.
|
|
134
164
|
|
|
135
165
|
request.retryPolicy = new ImdsRetryPolicy();
|
|
136
166
|
|
|
@@ -7,13 +7,11 @@ import { INetworkModule, Logger } from "@azure/msal-common/node";
|
|
|
7
7
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
|
8
8
|
import {
|
|
9
9
|
HttpMethod,
|
|
10
|
-
API_VERSION_QUERY_PARAMETER_NAME,
|
|
11
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
12
10
|
ManagedIdentityEnvironmentVariableNames,
|
|
13
11
|
ManagedIdentitySourceNames,
|
|
14
12
|
ManagedIdentityIdType,
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
ManagedIdentityQueryParameters,
|
|
14
|
+
ManagedIdentityHeaders,
|
|
17
15
|
} from "../../utils/Constants.js";
|
|
18
16
|
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
|
19
17
|
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
|
@@ -107,12 +105,13 @@ export class MachineLearning extends BaseManagedIdentitySource {
|
|
|
107
105
|
this.msiEndpoint
|
|
108
106
|
);
|
|
109
107
|
|
|
110
|
-
request.headers[METADATA_HEADER_NAME] = "true";
|
|
111
|
-
request.headers[ML_AND_SF_SECRET_HEADER_NAME] =
|
|
108
|
+
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
|
109
|
+
request.headers[ManagedIdentityHeaders.ML_AND_SF_SECRET_HEADER_NAME] =
|
|
110
|
+
this.secret;
|
|
112
111
|
|
|
113
|
-
request.queryParameters[
|
|
112
|
+
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
|
114
113
|
MACHINE_LEARNING_MSI_API_VERSION;
|
|
115
|
-
request.queryParameters[
|
|
114
|
+
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
|
116
115
|
resource;
|
|
117
116
|
|
|
118
117
|
if (
|
|
@@ -10,16 +10,14 @@ import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
|
|
10
10
|
import { NodeStorage } from "../../cache/NodeStorage.js";
|
|
11
11
|
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
|
12
12
|
import {
|
|
13
|
-
API_VERSION_QUERY_PARAMETER_NAME,
|
|
14
13
|
HttpMethod,
|
|
15
14
|
ManagedIdentityEnvironmentVariableNames,
|
|
16
15
|
ManagedIdentityIdType,
|
|
17
16
|
ManagedIdentitySourceNames,
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
ManagedIdentityQueryParameters,
|
|
18
|
+
ManagedIdentityHeaders,
|
|
20
19
|
} from "../../utils/Constants.js";
|
|
21
20
|
|
|
22
|
-
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
23
21
|
const SERVICE_FABRIC_MSI_API_VERSION: string = "2019-07-01-preview";
|
|
24
22
|
|
|
25
23
|
/**
|
|
@@ -29,6 +27,16 @@ export class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
29
27
|
private identityEndpoint: string;
|
|
30
28
|
private identityHeader: string;
|
|
31
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a new ServiceFabric managed identity source.
|
|
32
|
+
* @param logger Logger instance for logging
|
|
33
|
+
* @param nodeStorage NodeStorage instance for caching
|
|
34
|
+
* @param networkClient Network client for HTTP requests
|
|
35
|
+
* @param cryptoProvider Crypto provider for cryptographic operations
|
|
36
|
+
* @param disableInternalRetries Whether to disable internal retry logic
|
|
37
|
+
* @param identityEndpoint The Service Fabric managed identity endpoint
|
|
38
|
+
* @param identityHeader The Service Fabric managed identity secret header
|
|
39
|
+
*/
|
|
32
40
|
constructor(
|
|
33
41
|
logger: Logger,
|
|
34
42
|
nodeStorage: NodeStorage,
|
|
@@ -50,6 +58,10 @@ export class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
50
58
|
this.identityHeader = identityHeader;
|
|
51
59
|
}
|
|
52
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves the environment variables required for Service Fabric managed identity.
|
|
63
|
+
* @returns An array containing the identity endpoint, identity header, and identity server thumbprint.
|
|
64
|
+
*/
|
|
53
65
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
54
66
|
const identityEndpoint: string | undefined =
|
|
55
67
|
process.env[
|
|
@@ -68,6 +80,16 @@ export class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
68
80
|
return [identityEndpoint, identityHeader, identityServerThumbprint];
|
|
69
81
|
}
|
|
70
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Attempts to create a ServiceFabric managed identity source if all required environment variables are present.
|
|
85
|
+
* @param logger Logger instance for logging
|
|
86
|
+
* @param nodeStorage NodeStorage instance for caching
|
|
87
|
+
* @param networkClient Network client for HTTP requests
|
|
88
|
+
* @param cryptoProvider Crypto provider for cryptographic operations
|
|
89
|
+
* @param disableInternalRetries Whether to disable internal retry logic
|
|
90
|
+
* @param managedIdentityId Managed identity identifier
|
|
91
|
+
* @returns A ServiceFabric instance if environment variables are set, otherwise null
|
|
92
|
+
*/
|
|
71
93
|
public static tryCreate(
|
|
72
94
|
logger: Logger,
|
|
73
95
|
nodeStorage: NodeStorage,
|
|
@@ -79,10 +101,6 @@ export class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
79
101
|
const [identityEndpoint, identityHeader, identityServerThumbprint] =
|
|
80
102
|
ServiceFabric.getEnvironmentVariables();
|
|
81
103
|
|
|
82
|
-
/*
|
|
83
|
-
* if either of the identity endpoint, identity header, or identity server thumbprint
|
|
84
|
-
* environment variables are undefined, this MSI provider is unavailable.
|
|
85
|
-
*/
|
|
86
104
|
if (!identityEndpoint || !identityHeader || !identityServerThumbprint) {
|
|
87
105
|
logger.info(
|
|
88
106
|
`[Managed Identity] ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity is unavailable because one or all of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}', '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' or '${ManagedIdentityEnvironmentVariableNames.IDENTITY_SERVER_THUMBPRINT}' environment variables are not defined.`
|
|
@@ -121,6 +139,12 @@ export class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
121
139
|
);
|
|
122
140
|
}
|
|
123
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Creates the request parameters for acquiring a token from the Service Fabric cluster.
|
|
144
|
+
* @param resource - The resource URI for which the token is requested.
|
|
145
|
+
* @param managedIdentityId - The managed identity ID (system-assigned or user-assigned).
|
|
146
|
+
* @returns A ManagedIdentityRequestParameters object configured for Service Fabric.
|
|
147
|
+
*/
|
|
124
148
|
public createRequest(
|
|
125
149
|
resource: string,
|
|
126
150
|
managedIdentityId: ManagedIdentityId
|
|
@@ -131,11 +155,12 @@ export class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
131
155
|
this.identityEndpoint
|
|
132
156
|
);
|
|
133
157
|
|
|
134
|
-
request.headers[ML_AND_SF_SECRET_HEADER_NAME] =
|
|
158
|
+
request.headers[ManagedIdentityHeaders.ML_AND_SF_SECRET_HEADER_NAME] =
|
|
159
|
+
this.identityHeader;
|
|
135
160
|
|
|
136
|
-
request.queryParameters[
|
|
161
|
+
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
|
137
162
|
SERVICE_FABRIC_MSI_API_VERSION;
|
|
138
|
-
request.queryParameters[
|
|
163
|
+
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
|
139
164
|
resource;
|
|
140
165
|
|
|
141
166
|
if (
|
|
@@ -134,6 +134,7 @@ export type ManagedIdentityIdParams = {
|
|
|
134
134
|
|
|
135
135
|
/** @public */
|
|
136
136
|
export type ManagedIdentityConfiguration = {
|
|
137
|
+
clientCapabilities?: Array<string>;
|
|
137
138
|
managedIdentityIdParams?: ManagedIdentityIdParams;
|
|
138
139
|
system?: NodeSystemOptions;
|
|
139
140
|
};
|
|
@@ -246,14 +247,16 @@ export function buildAppConfiguration({
|
|
|
246
247
|
|
|
247
248
|
/** @internal */
|
|
248
249
|
export type ManagedIdentityNodeConfiguration = {
|
|
250
|
+
clientCapabilities?: Array<string>;
|
|
251
|
+
disableInternalRetries: boolean;
|
|
249
252
|
managedIdentityId: ManagedIdentityId;
|
|
250
253
|
system: Required<
|
|
251
254
|
Pick<NodeSystemOptions, "loggerOptions" | "networkClient">
|
|
252
255
|
>;
|
|
253
|
-
disableInternalRetries: boolean;
|
|
254
256
|
};
|
|
255
257
|
|
|
256
258
|
export function buildManagedIdentityConfiguration({
|
|
259
|
+
clientCapabilities,
|
|
257
260
|
managedIdentityIdParams,
|
|
258
261
|
system,
|
|
259
262
|
}: ManagedIdentityConfiguration): ManagedIdentityNodeConfiguration {
|
|
@@ -277,6 +280,7 @@ export function buildManagedIdentityConfiguration({
|
|
|
277
280
|
}
|
|
278
281
|
|
|
279
282
|
return {
|
|
283
|
+
clientCapabilities: clientCapabilities || [],
|
|
280
284
|
managedIdentityId: managedIdentityId,
|
|
281
285
|
system: {
|
|
282
286
|
loggerOptions,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { ICrypto, PkceCodes } from "@azure/msal-common/node";
|
|
6
|
+
import { EncodingTypes, ICrypto, PkceCodes } from "@azure/msal-common/node";
|
|
7
7
|
import { GuidGenerator } from "./GuidGenerator.js";
|
|
8
8
|
import { EncodingUtils } from "../utils/EncodingUtils.js";
|
|
9
9
|
import { PkceGenerator } from "./PkceGenerator.js";
|
|
@@ -106,8 +106,8 @@ export class CryptoProvider implements ICrypto {
|
|
|
106
106
|
*/
|
|
107
107
|
async hashString(plainText: string): Promise<string> {
|
|
108
108
|
return EncodingUtils.base64EncodeUrl(
|
|
109
|
-
this.hashUtils.sha256(plainText).toString(
|
|
110
|
-
|
|
109
|
+
this.hashUtils.sha256(plainText).toString(EncodingTypes.BASE64),
|
|
110
|
+
EncodingTypes.BASE64
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Constants, PkceCodes } from "@azure/msal-common/node";
|
|
6
|
+
import { Constants, EncodingTypes, PkceCodes } from "@azure/msal-common/node";
|
|
7
7
|
import { CharSet, RANDOM_OCTET_SIZE } from "../utils/Constants.js";
|
|
8
8
|
import { EncodingUtils } from "../utils/EncodingUtils.js";
|
|
9
9
|
import { HashUtils } from "./HashUtils.js";
|
|
@@ -56,8 +56,8 @@ export class PkceGenerator {
|
|
|
56
56
|
*/
|
|
57
57
|
private generateCodeChallengeFromVerifier(codeVerifier: string): string {
|
|
58
58
|
return EncodingUtils.base64EncodeUrl(
|
|
59
|
-
this.hashUtils.sha256(codeVerifier).toString(
|
|
60
|
-
|
|
59
|
+
this.hashUtils.sha256(codeVerifier).toString(EncodingTypes.BASE64),
|
|
60
|
+
EncodingTypes.BASE64
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/packageMetadata.ts
CHANGED
|
@@ -8,8 +8,11 @@ import { ManagedIdentityRequestParams } from "./ManagedIdentityRequestParams.js"
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* ManagedIdentityRequest
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
11
|
+
* - clientCapabilities - an array of capabilities to be added to all network requests as part of the `xms_cc` claim
|
|
12
|
+
* - revokedTokenSha256Hash - a SHA256 hash of the token that was revoked. The managed identity will revoke the token based on the SHA256 hash of the token, not the token itself. This is to prevent the token from being leaked in transit.
|
|
13
13
|
*/
|
|
14
14
|
export type ManagedIdentityRequest = ManagedIdentityRequestParams &
|
|
15
|
-
CommonClientCredentialRequest
|
|
15
|
+
CommonClientCredentialRequest & {
|
|
16
|
+
clientCapabilities?: Array<string>;
|
|
17
|
+
revokedTokenSha256Hash?: string;
|
|
18
|
+
};
|
package/src/utils/Constants.ts
CHANGED
|
@@ -8,16 +8,34 @@ import { DefaultManagedIdentityRetryPolicy } from "../retry/DefaultManagedIdenti
|
|
|
8
8
|
import { ImdsRetryPolicy } from "../retry/ImdsRetryPolicy.js";
|
|
9
9
|
|
|
10
10
|
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
11
|
-
export const AUTHORIZATION_HEADER_NAME: string = "Authorization";
|
|
12
|
-
export const METADATA_HEADER_NAME: string = "Metadata";
|
|
13
|
-
export const APP_SERVICE_SECRET_HEADER_NAME: string = "X-IDENTITY-HEADER";
|
|
14
|
-
export const ML_AND_SF_SECRET_HEADER_NAME: string = "secret";
|
|
15
|
-
export const API_VERSION_QUERY_PARAMETER_NAME: string = "api-version";
|
|
16
|
-
export const RESOURCE_BODY_OR_QUERY_PARAMETER_NAME: string = "resource";
|
|
17
11
|
export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
|
|
18
12
|
export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
|
|
19
13
|
export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
|
|
20
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Managed Identity Headers - used in network requests
|
|
17
|
+
*/
|
|
18
|
+
export const ManagedIdentityHeaders = {
|
|
19
|
+
AUTHORIZATION_HEADER_NAME: "Authorization",
|
|
20
|
+
METADATA_HEADER_NAME: "Metadata",
|
|
21
|
+
APP_SERVICE_SECRET_HEADER_NAME: "X-IDENTITY-HEADER",
|
|
22
|
+
ML_AND_SF_SECRET_HEADER_NAME: "secret",
|
|
23
|
+
} as const;
|
|
24
|
+
export type ManagedIdentityHeaders =
|
|
25
|
+
(typeof ManagedIdentityHeaders)[keyof typeof ManagedIdentityHeaders];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Managed Identity Query Parameters - used in network requests
|
|
29
|
+
*/
|
|
30
|
+
export const ManagedIdentityQueryParameters = {
|
|
31
|
+
API_VERSION: "api-version",
|
|
32
|
+
RESOURCE: "resource",
|
|
33
|
+
SHA256_TOKEN_TO_REFRESH: "token_sha256_to_refresh",
|
|
34
|
+
XMS_CC: "xms_cc",
|
|
35
|
+
} as const;
|
|
36
|
+
export type ManagedIdentityQueryParameters =
|
|
37
|
+
(typeof ManagedIdentityQueryParameters)[keyof typeof ManagedIdentityQueryParameters];
|
|
38
|
+
|
|
21
39
|
/**
|
|
22
40
|
* Managed Identity Environment Variable Names
|
|
23
41
|
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Constants } from "@azure/msal-common/node";
|
|
6
|
+
import { Constants, EncodingTypes } from "@azure/msal-common/node";
|
|
7
7
|
|
|
8
8
|
export class EncodingUtils {
|
|
9
9
|
/**
|
|
@@ -13,7 +13,7 @@ export class EncodingUtils {
|
|
|
13
13
|
* @param str text
|
|
14
14
|
*/
|
|
15
15
|
static base64Encode(str: string, encoding?: BufferEncoding): string {
|
|
16
|
-
return Buffer.from(str, encoding).toString(
|
|
16
|
+
return Buffer.from(str, encoding).toString(EncodingTypes.BASE64);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -34,7 +34,7 @@ export class EncodingUtils {
|
|
|
34
34
|
* @param base64Str Base64 encoded text
|
|
35
35
|
*/
|
|
36
36
|
static base64Decode(base64Str: string): string {
|
|
37
|
-
return Buffer.from(base64Str,
|
|
37
|
+
return Buffer.from(base64Str, EncodingTypes.BASE64).toString("utf8");
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|