@azure/msal-node 3.8.0 → 3.8.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 +1 -1
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/NodeStorage.mjs +2 -2
- package/dist/cache/NodeStorage.mjs.map +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.mjs +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.mjs +1 -1
- package/dist/client/ManagedIdentityClient.mjs +1 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts +54 -0
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +55 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +82 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +81 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +55 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +44 -22
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +44 -22
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
- package/dist/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs +66 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +57 -23
- 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.mjs +1 -1
- package/dist/config/ManagedIdentityId.mjs +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
- package/dist/crypto/CryptoProvider.mjs +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/error/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/retry/DefaultManagedIdentityRetryPolicy.mjs +1 -1
- package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
- package/dist/retry/ImdsRetryPolicy.mjs +1 -1
- package/dist/retry/LinearRetryStrategy.mjs +1 -1
- package/dist/utils/Constants.mjs +1 -1
- package/dist/utils/EncodingUtils.mjs +1 -1
- package/dist/utils/NetworkUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/lib/msal-node.cjs +914 -503
- package/lib/msal-node.cjs.map +1 -1
- package/lib/types/cache/NodeStorage.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/AppService.d.ts +54 -0
- package/lib/types/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
- package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
- package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
- package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/Imds.d.ts +44 -22
- package/lib/types/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
- package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
- package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/lib/types/packageMetadata.d.ts +1 -1
- package/package.json +2 -2
- package/src/cache/NodeStorage.ts +3 -1
- package/src/client/ManagedIdentitySources/AppService.ts +54 -0
- package/src/client/ManagedIdentitySources/AzureArc.ts +81 -0
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +92 -2
- package/src/client/ManagedIdentitySources/CloudShell.ts +54 -0
- package/src/client/ManagedIdentitySources/Imds.ts +43 -21
- package/src/client/ManagedIdentitySources/MachineLearning.ts +65 -0
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +56 -22
- package/src/packageMetadata.ts +1 -1
|
@@ -11,37 +11,71 @@ export declare class ServiceFabric extends BaseManagedIdentitySource {
|
|
|
11
11
|
private identityEndpoint;
|
|
12
12
|
private identityHeader;
|
|
13
13
|
/**
|
|
14
|
-
* Constructs a new ServiceFabric managed identity source.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
14
|
+
* Constructs a new ServiceFabric managed identity source for acquiring tokens from Azure Service Fabric clusters.
|
|
15
|
+
*
|
|
16
|
+
* Service Fabric managed identity allows applications running in Service Fabric clusters to authenticate
|
|
17
|
+
* without storing credentials in code. This source handles token acquisition using the Service Fabric
|
|
18
|
+
* Managed Identity Token Service (MITS).
|
|
19
|
+
*
|
|
20
|
+
* @param logger - Logger instance for logging authentication events and debugging information
|
|
21
|
+
* @param nodeStorage - NodeStorage instance for caching tokens and other authentication artifacts
|
|
22
|
+
* @param networkClient - Network client for making HTTP requests to the Service Fabric identity endpoint
|
|
23
|
+
* @param cryptoProvider - Crypto provider for cryptographic operations like token validation
|
|
24
|
+
* @param disableInternalRetries - Whether to disable internal retry logic for failed requests
|
|
25
|
+
* @param identityEndpoint - The Service Fabric managed identity endpoint URL
|
|
26
|
+
* @param identityHeader - The Service Fabric managed identity secret header value
|
|
22
27
|
*/
|
|
23
28
|
constructor(logger: Logger, nodeStorage: NodeStorage, networkClient: INetworkModule, cryptoProvider: CryptoProvider, disableInternalRetries: boolean, identityEndpoint: string, identityHeader: string);
|
|
24
29
|
/**
|
|
25
|
-
* Retrieves the environment variables required for Service Fabric managed identity.
|
|
26
|
-
*
|
|
30
|
+
* Retrieves the environment variables required for Service Fabric managed identity authentication.
|
|
31
|
+
*
|
|
32
|
+
* Service Fabric managed identity requires three specific environment variables to be set by the
|
|
33
|
+
* Service Fabric runtime:
|
|
34
|
+
* - IDENTITY_ENDPOINT: The endpoint URL for the Managed Identity Token Service (MITS)
|
|
35
|
+
* - IDENTITY_HEADER: A secret value used for authentication with the MITS
|
|
36
|
+
* - IDENTITY_SERVER_THUMBPRINT: The thumbprint of the MITS server certificate for secure communication
|
|
37
|
+
*
|
|
38
|
+
* @returns An array containing the identity endpoint, identity header, and identity server thumbprint values.
|
|
39
|
+
* Elements will be undefined if the corresponding environment variables are not set.
|
|
27
40
|
*/
|
|
28
41
|
static getEnvironmentVariables(): Array<string | undefined>;
|
|
29
42
|
/**
|
|
30
|
-
* Attempts to create a ServiceFabric managed identity source if
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
43
|
+
* Attempts to create a ServiceFabric managed identity source if the runtime environment supports it.
|
|
44
|
+
*
|
|
45
|
+
* Checks for the presence of all required Service Fabric environment variables
|
|
46
|
+
* and validates the endpoint URL format. It will only create a ServiceFabric instance if the application
|
|
47
|
+
* is running in a properly configured Service Fabric cluster with managed identity enabled.
|
|
48
|
+
*
|
|
49
|
+
* Note: User-assigned managed identities must be configured at the cluster level, not at runtime.
|
|
50
|
+
* This method will log a warning if a user-assigned identity is requested.
|
|
51
|
+
*
|
|
52
|
+
* @param logger - Logger instance for logging creation events and validation results
|
|
53
|
+
* @param nodeStorage - NodeStorage instance for caching tokens and authentication artifacts
|
|
54
|
+
* @param networkClient - Network client for making HTTP requests to the identity endpoint
|
|
55
|
+
* @param cryptoProvider - Crypto provider for cryptographic operations
|
|
56
|
+
* @param disableInternalRetries - Whether to disable internal retry logic for failed requests
|
|
57
|
+
* @param managedIdentityId - Managed identity identifier specifying system-assigned or user-assigned identity
|
|
58
|
+
*
|
|
59
|
+
* @returns A ServiceFabric instance if all environment variables are valid and present, otherwise null
|
|
38
60
|
*/
|
|
39
61
|
static tryCreate(logger: Logger, nodeStorage: NodeStorage, networkClient: INetworkModule, cryptoProvider: CryptoProvider, disableInternalRetries: boolean, managedIdentityId: ManagedIdentityId): ServiceFabric | null;
|
|
40
62
|
/**
|
|
41
|
-
* Creates
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
63
|
+
* Creates HTTP request parameters for acquiring an access token from the Service Fabric Managed Identity Token Service (MITS).
|
|
64
|
+
*
|
|
65
|
+
* This method constructs a properly formatted HTTP GET request that includes:
|
|
66
|
+
* - The secret header for authentication with MITS
|
|
67
|
+
* - API version parameter for the Service Fabric MSI endpoint
|
|
68
|
+
* - Resource parameter specifying the target Azure service
|
|
69
|
+
* - Optional identity parameters for user-assigned managed identities
|
|
70
|
+
*
|
|
71
|
+
* The request follows the Service Fabric managed identity protocol and uses the 2019-07-01-preview API version.
|
|
72
|
+
* For user-assigned identities, the appropriate query parameter (client_id, object_id, or resource_id) is added
|
|
73
|
+
* based on the identity type.
|
|
74
|
+
*
|
|
75
|
+
* @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
|
|
76
|
+
* @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
|
|
77
|
+
*
|
|
78
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
45
79
|
*/
|
|
46
80
|
createRequest(resource: string, managedIdentityId: ManagedIdentityId): ManagedIdentityRequestParameters;
|
|
47
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceFabric.d.ts","sourceRoot":"","sources":["../../../../src/client/ManagedIdentitySources/ServiceFabric.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,kDAAkD,CAAC;AACpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAYhE;;GAEG;AACH,qBAAa,aAAc,SAAQ,yBAAyB;IACxD,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,cAAc,CAAS;IAE/B
|
|
1
|
+
{"version":3,"file":"ServiceFabric.d.ts","sourceRoot":"","sources":["../../../../src/client/ManagedIdentitySources/ServiceFabric.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,kDAAkD,CAAC;AACpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAYhE;;GAEG;AACH,qBAAa,aAAc,SAAQ,yBAAyB;IACxD,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,cAAc,CAAS;IAE/B;;;;;;;;;;;;;;OAcG;gBAEC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,cAAc,EAC7B,cAAc,EAAE,cAAc,EAC9B,sBAAsB,EAAE,OAAO,EAC/B,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM;IAc1B;;;;;;;;;;;OAWG;WACW,uBAAuB,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;IAkBlE;;;;;;;;;;;;;;;;;;OAkBG;WACW,SAAS,CACnB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,cAAc,EAC7B,cAAc,EAAE,cAAc,EAC9B,sBAAsB,EAAE,OAAO,EAC/B,iBAAiB,EAAE,iBAAiB,GACrC,aAAa,GAAG,IAAI;IA0CvB;;;;;;;;;;;;;;;;;OAiBG;IACI,aAAa,CAChB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,iBAAiB,GACrC,gCAAgC;CA6BtC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@azure/msal-node",
|
|
4
|
-
"version": "3.8.
|
|
4
|
+
"version": "3.8.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Microsoft",
|
|
7
7
|
"email": "nugetaad@microsoft.com",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"yargs": "^17.3.1"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@azure/msal-common": "15.13.
|
|
86
|
+
"@azure/msal-common": "15.13.1",
|
|
87
87
|
"jsonwebtoken": "^9.0.0",
|
|
88
88
|
"uuid": "^8.3.0"
|
|
89
89
|
},
|
package/src/cache/NodeStorage.ts
CHANGED
|
@@ -248,7 +248,9 @@ export class NodeStorage extends CacheManager {
|
|
|
248
248
|
* @param account - cache value to be set of type AccountEntity
|
|
249
249
|
*/
|
|
250
250
|
async setAccount(account: AccountEntity): Promise<void> {
|
|
251
|
-
const accountKey = this.generateAccountKey(
|
|
251
|
+
const accountKey = this.generateAccountKey(
|
|
252
|
+
AccountEntity.getAccountInfo(account)
|
|
253
|
+
);
|
|
252
254
|
this.setItem(accountKey, account);
|
|
253
255
|
}
|
|
254
256
|
|
|
@@ -22,12 +22,29 @@ import { NodeStorage } from "../../cache/NodeStorage.js";
|
|
|
22
22
|
const APP_SERVICE_MSI_API_VERSION: string = "2019-08-01";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
+
* Azure App Service Managed Identity Source implementation.
|
|
26
|
+
*
|
|
27
|
+
* This class provides managed identity authentication for applications running in Azure App Service.
|
|
28
|
+
* It uses the local metadata service endpoint available within App Service environments to obtain
|
|
29
|
+
* access tokens without requiring explicit credentials.
|
|
30
|
+
*
|
|
25
31
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AppServiceManagedIdentitySource.cs
|
|
26
32
|
*/
|
|
27
33
|
export class AppService extends BaseManagedIdentitySource {
|
|
28
34
|
private identityEndpoint: string;
|
|
29
35
|
private identityHeader: string;
|
|
30
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new instance of the AppService managed identity source.
|
|
39
|
+
*
|
|
40
|
+
* @param logger - Logger instance for diagnostic output
|
|
41
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
42
|
+
* @param networkClient - Network client for making HTTP requests
|
|
43
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
44
|
+
* @param disableInternalRetries - Whether to disable internal retry logic
|
|
45
|
+
* @param identityEndpoint - The App Service identity endpoint URL
|
|
46
|
+
* @param identityHeader - The secret header value required for authentication
|
|
47
|
+
*/
|
|
31
48
|
constructor(
|
|
32
49
|
logger: Logger,
|
|
33
50
|
nodeStorage: NodeStorage,
|
|
@@ -49,6 +66,16 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
49
66
|
this.identityHeader = identityHeader;
|
|
50
67
|
}
|
|
51
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves the required environment variables for App Service managed identity.
|
|
71
|
+
*
|
|
72
|
+
* App Service managed identity requires two environment variables:
|
|
73
|
+
* - IDENTITY_ENDPOINT: The URL of the local metadata service
|
|
74
|
+
* - IDENTITY_HEADER: A secret header value for authentication
|
|
75
|
+
*
|
|
76
|
+
* @returns An array containing [identityEndpoint, identityHeader] values from environment variables.
|
|
77
|
+
* Either value may be undefined if the environment variable is not set.
|
|
78
|
+
*/
|
|
52
79
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
53
80
|
const identityEndpoint: string | undefined =
|
|
54
81
|
process.env[
|
|
@@ -62,6 +89,21 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
62
89
|
return [identityEndpoint, identityHeader];
|
|
63
90
|
}
|
|
64
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Attempts to create an AppService managed identity source if the environment supports it.
|
|
94
|
+
*
|
|
95
|
+
* This method checks for the presence of required environment variables and validates
|
|
96
|
+
* the identity endpoint URL. If the environment is not suitable for App Service managed
|
|
97
|
+
* identity (missing environment variables or invalid endpoint), it returns null.
|
|
98
|
+
*
|
|
99
|
+
* @param logger - Logger instance for diagnostic output
|
|
100
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
101
|
+
* @param networkClient - Network client for making HTTP requests
|
|
102
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
103
|
+
* @param disableInternalRetries - Whether to disable internal retry logic
|
|
104
|
+
*
|
|
105
|
+
* @returns A new AppService instance if the environment is suitable, null otherwise
|
|
106
|
+
*/
|
|
65
107
|
public static tryCreate(
|
|
66
108
|
logger: Logger,
|
|
67
109
|
nodeStorage: NodeStorage,
|
|
@@ -103,6 +145,18 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
103
145
|
);
|
|
104
146
|
}
|
|
105
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Creates a managed identity token request for the App Service environment.
|
|
150
|
+
*
|
|
151
|
+
* This method constructs an HTTP GET request to the App Service identity endpoint
|
|
152
|
+
* with the required headers, query parameters, and managed identity configuration.
|
|
153
|
+
* The request includes the secret header for authentication and appropriate API version.
|
|
154
|
+
*
|
|
155
|
+
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
|
156
|
+
* @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
|
|
157
|
+
*
|
|
158
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
159
|
+
*/
|
|
106
160
|
public createRequest(
|
|
107
161
|
resource: string,
|
|
108
162
|
managedIdentityId: ManagedIdentityId
|
|
@@ -63,11 +63,27 @@ export const AZURE_ARC_FILE_DETECTION: FilePathMap = {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
+
* Azure Arc managed identity source implementation for acquiring tokens from Azure Arc-enabled servers.
|
|
67
|
+
*
|
|
68
|
+
* This class provides managed identity authentication for applications running on Azure Arc-enabled servers
|
|
69
|
+
* by communicating with the local Hybrid Instance Metadata Service (HIMDS). It supports both environment
|
|
70
|
+
* variable-based configuration and automatic detection through the HIMDS executable.
|
|
71
|
+
*
|
|
66
72
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
|
|
67
73
|
*/
|
|
68
74
|
export class AzureArc extends BaseManagedIdentitySource {
|
|
69
75
|
private identityEndpoint: string;
|
|
70
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new instance of the AzureArc managed identity source.
|
|
79
|
+
*
|
|
80
|
+
* @param logger - Logger instance for capturing telemetry and diagnostic information
|
|
81
|
+
* @param nodeStorage - Storage implementation for caching tokens and metadata
|
|
82
|
+
* @param networkClient - Network client for making HTTP requests to the identity endpoint
|
|
83
|
+
* @param cryptoProvider - Cryptographic operations provider for token validation and encryption
|
|
84
|
+
* @param disableInternalRetries - Flag to disable automatic retry logic for failed requests
|
|
85
|
+
* @param identityEndpoint - The Azure Arc identity endpoint URL for token requests
|
|
86
|
+
*/
|
|
71
87
|
constructor(
|
|
72
88
|
logger: Logger,
|
|
73
89
|
nodeStorage: NodeStorage,
|
|
@@ -87,6 +103,17 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
87
103
|
this.identityEndpoint = identityEndpoint;
|
|
88
104
|
}
|
|
89
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves and validates Azure Arc environment variables for managed identity configuration.
|
|
108
|
+
*
|
|
109
|
+
* This method checks for IDENTITY_ENDPOINT and IMDS_ENDPOINT environment variables.
|
|
110
|
+
* If either is missing, it attempts to detect the Azure Arc environment by checking for
|
|
111
|
+
* the HIMDS executable at platform-specific paths. On successful detection, it returns
|
|
112
|
+
* the default identity endpoint and a helper string indicating file-based detection.
|
|
113
|
+
*
|
|
114
|
+
* @returns An array containing [identityEndpoint, imdsEndpoint] where both values are
|
|
115
|
+
* strings if Azure Arc is available, or undefined if not available.
|
|
116
|
+
*/
|
|
90
117
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
91
118
|
let identityEndpoint: string | undefined =
|
|
92
119
|
process.env[
|
|
@@ -123,6 +150,25 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
123
150
|
return [identityEndpoint, imdsEndpoint];
|
|
124
151
|
}
|
|
125
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Attempts to create an AzureArc managed identity source instance.
|
|
155
|
+
*
|
|
156
|
+
* Validates the Azure Arc environment by checking environment variables
|
|
157
|
+
* and performing file-based detection. It ensures that only system-assigned managed identities
|
|
158
|
+
* are supported for Azure Arc scenarios. The method performs comprehensive validation of
|
|
159
|
+
* endpoint URLs and logs detailed information about the detection process.
|
|
160
|
+
*
|
|
161
|
+
* @param logger - Logger instance for capturing creation and validation steps
|
|
162
|
+
* @param nodeStorage - Storage implementation for the managed identity source
|
|
163
|
+
* @param networkClient - Network client for HTTP communication
|
|
164
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
165
|
+
* @param disableInternalRetries - Whether to disable automatic retry mechanisms
|
|
166
|
+
* @param managedIdentityId - The managed identity configuration, must be system-assigned
|
|
167
|
+
*
|
|
168
|
+
* @returns AzureArc instance if the environment supports Azure Arc managed identity, null otherwise
|
|
169
|
+
*
|
|
170
|
+
* @throws {ManagedIdentityError} When a user-assigned managed identity is specified (not supported for Azure Arc)
|
|
171
|
+
*/
|
|
126
172
|
public static tryCreate(
|
|
127
173
|
logger: Logger,
|
|
128
174
|
nodeStorage: NodeStorage,
|
|
@@ -193,6 +239,17 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
193
239
|
);
|
|
194
240
|
}
|
|
195
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Creates a properly formatted HTTP request for acquiring tokens from the Azure Arc identity endpoint.
|
|
244
|
+
*
|
|
245
|
+
* This method constructs a GET request to the Azure Arc HIMDS endpoint with the required metadata header
|
|
246
|
+
* and query parameters. The endpoint URL is normalized to use 127.0.0.1 instead of localhost for
|
|
247
|
+
* consistency. Additional body parameters are calculated by the base class during token acquisition.
|
|
248
|
+
*
|
|
249
|
+
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
|
250
|
+
*
|
|
251
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
252
|
+
*/
|
|
196
253
|
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
197
254
|
const request: ManagedIdentityRequestParameters =
|
|
198
255
|
new ManagedIdentityRequestParameters(
|
|
@@ -212,6 +269,30 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
212
269
|
return request;
|
|
213
270
|
}
|
|
214
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Processes the server response and handles Azure Arc-specific authentication challenges.
|
|
274
|
+
*
|
|
275
|
+
* This method implements the Azure Arc authentication flow which may require reading a secret file
|
|
276
|
+
* for authorization. When the initial request returns HTTP 401 Unauthorized, it extracts the file
|
|
277
|
+
* path from the WWW-Authenticate header, validates the file location and size, reads the secret,
|
|
278
|
+
* and retries the request with Basic authentication. The method includes comprehensive security
|
|
279
|
+
* validations to prevent path traversal and ensure file integrity.
|
|
280
|
+
*
|
|
281
|
+
* @param originalResponse - The initial HTTP response from the identity endpoint
|
|
282
|
+
* @param networkClient - Network client for making the retry request if needed
|
|
283
|
+
* @param networkRequest - The original request parameters (modified with auth header for retry)
|
|
284
|
+
* @param networkRequestOptions - Additional options for network requests
|
|
285
|
+
*
|
|
286
|
+
* @returns A promise that resolves to the server token response with access token and metadata
|
|
287
|
+
*
|
|
288
|
+
* @throws {ManagedIdentityError} When:
|
|
289
|
+
* - WWW-Authenticate header is missing or has unsupported format
|
|
290
|
+
* - Platform is not supported (not Windows or Linux)
|
|
291
|
+
* - Secret file has invalid extension (not .key)
|
|
292
|
+
* - Secret file path doesn't match expected platform path
|
|
293
|
+
* - Secret file cannot be read or is too large (>4096 bytes)
|
|
294
|
+
* @throws {ClientAuthError} When network errors occur during retry request
|
|
295
|
+
*/
|
|
215
296
|
public async getServerTokenResponseAsync(
|
|
216
297
|
originalResponse: NetworkResponse<ManagedIdentityTokenResponse>,
|
|
217
298
|
networkClient: INetworkModule,
|
|
@@ -51,6 +51,14 @@ export const ManagedIdentityUserAssignedIdQueryParameterNames = {
|
|
|
51
51
|
export type ManagedIdentityUserAssignedIdQueryParameterNames =
|
|
52
52
|
(typeof ManagedIdentityUserAssignedIdQueryParameterNames)[keyof typeof ManagedIdentityUserAssignedIdQueryParameterNames];
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Base class for all Managed Identity sources. Provides common functionality for
|
|
56
|
+
* authenticating with Azure Managed Identity endpoints across different Azure services
|
|
57
|
+
* including IMDS, App Service, Azure Arc, Service Fabric, Cloud Shell, and Machine Learning.
|
|
58
|
+
*
|
|
59
|
+
* This abstract class handles token acquisition, response processing, and network communication
|
|
60
|
+
* while allowing concrete implementations to define source-specific request creation logic.
|
|
61
|
+
*/
|
|
54
62
|
export abstract class BaseManagedIdentitySource {
|
|
55
63
|
protected logger: Logger;
|
|
56
64
|
private nodeStorage: NodeStorage;
|
|
@@ -58,6 +66,15 @@ export abstract class BaseManagedIdentitySource {
|
|
|
58
66
|
private cryptoProvider: CryptoProvider;
|
|
59
67
|
private disableInternalRetries: boolean;
|
|
60
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance of BaseManagedIdentitySource.
|
|
71
|
+
*
|
|
72
|
+
* @param logger - Logger instance for diagnostic information
|
|
73
|
+
* @param nodeStorage - Storage interface for caching tokens
|
|
74
|
+
* @param networkClient - Network client for making HTTP requests
|
|
75
|
+
* @param cryptoProvider - Cryptographic provider for token operations
|
|
76
|
+
* @param disableInternalRetries - Whether to disable automatic retry logic
|
|
77
|
+
*/
|
|
61
78
|
constructor(
|
|
62
79
|
logger: Logger,
|
|
63
80
|
nodeStorage: NodeStorage,
|
|
@@ -72,11 +89,33 @@ export abstract class BaseManagedIdentitySource {
|
|
|
72
89
|
this.disableInternalRetries = disableInternalRetries;
|
|
73
90
|
}
|
|
74
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Creates a managed identity request with source-specific parameters.
|
|
94
|
+
* This method must be implemented by concrete managed identity sources to define
|
|
95
|
+
* how requests are constructed for their specific endpoint requirements.
|
|
96
|
+
*
|
|
97
|
+
* @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
|
|
98
|
+
* @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
|
|
99
|
+
*
|
|
100
|
+
* @returns Request parameters configured for the specific managed identity source
|
|
101
|
+
*/
|
|
75
102
|
abstract createRequest(
|
|
76
|
-
|
|
103
|
+
resource: string,
|
|
77
104
|
managedIdentityId: ManagedIdentityId
|
|
78
105
|
): ManagedIdentityRequestParameters;
|
|
79
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Processes the network response and converts it to a standardized server token response.
|
|
109
|
+
* This async version allows for source-specific response processing logic while maintaining
|
|
110
|
+
* backward compatibility with the synchronous version.
|
|
111
|
+
*
|
|
112
|
+
* @param response - The network response containing the managed identity token
|
|
113
|
+
* @param _networkClient - Network client used for the request (unused in base implementation)
|
|
114
|
+
* @param _networkRequest - The original network request parameters (unused in base implementation)
|
|
115
|
+
* @param _networkRequestOptions - The network request options (unused in base implementation)
|
|
116
|
+
*
|
|
117
|
+
* @returns Promise resolving to a standardized server authorization token response
|
|
118
|
+
*/
|
|
80
119
|
public async getServerTokenResponseAsync(
|
|
81
120
|
response: NetworkResponse<ManagedIdentityTokenResponse>,
|
|
82
121
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -89,6 +128,15 @@ export abstract class BaseManagedIdentitySource {
|
|
|
89
128
|
return this.getServerTokenResponse(response);
|
|
90
129
|
}
|
|
91
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Converts a managed identity token response to a standardized server authorization token response.
|
|
133
|
+
* Handles time format conversion, expiration calculation, and error mapping to ensure
|
|
134
|
+
* compatibility with the MSAL response handling pipeline.
|
|
135
|
+
*
|
|
136
|
+
* @param response - The network response containing the managed identity token
|
|
137
|
+
*
|
|
138
|
+
* @returns Standardized server authorization token response with normalized fields
|
|
139
|
+
*/
|
|
92
140
|
public getServerTokenResponse(
|
|
93
141
|
response: NetworkResponse<ManagedIdentityTokenResponse>
|
|
94
142
|
): ServerAuthorizationTokenResponse {
|
|
@@ -138,6 +186,21 @@ export abstract class BaseManagedIdentitySource {
|
|
|
138
186
|
return serverTokenResponse;
|
|
139
187
|
}
|
|
140
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Acquires an access token using the managed identity endpoint for the specified resource.
|
|
191
|
+
* This is the primary method for token acquisition, handling the complete flow from
|
|
192
|
+
* request creation through response processing and token caching.
|
|
193
|
+
*
|
|
194
|
+
* @param managedIdentityRequest - The managed identity request containing resource and optional parameters
|
|
195
|
+
* @param managedIdentityId - The managed identity configuration (system or user-assigned)
|
|
196
|
+
* @param fakeAuthority - Authority instance used for token caching (managed identity uses a placeholder authority)
|
|
197
|
+
* @param refreshAccessToken - Whether this is a token refresh operation
|
|
198
|
+
*
|
|
199
|
+
* @returns Promise resolving to an authentication result containing the access token and metadata
|
|
200
|
+
*
|
|
201
|
+
* @throws {AuthError} When network requests fail or token validation fails
|
|
202
|
+
* @throws {ClientAuthError} When network errors occur during the request
|
|
203
|
+
*/
|
|
141
204
|
public async acquireTokenWithManagedIdentity(
|
|
142
205
|
managedIdentityRequest: ManagedIdentityRequest,
|
|
143
206
|
managedIdentityId: ManagedIdentityId,
|
|
@@ -253,6 +316,19 @@ export abstract class BaseManagedIdentitySource {
|
|
|
253
316
|
);
|
|
254
317
|
}
|
|
255
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Determines the appropriate query parameter name for user-assigned managed identity
|
|
321
|
+
* based on the identity type, API version, and endpoint characteristics.
|
|
322
|
+
* Different Azure services and API versions use different parameter names for the same identity types.
|
|
323
|
+
*
|
|
324
|
+
* @param managedIdentityIdType - The type of user-assigned managed identity (client ID, object ID, or resource ID)
|
|
325
|
+
* @param isImds - Whether the request is being made to the IMDS (Instance Metadata Service) endpoint
|
|
326
|
+
* @param usesApi2017 - Whether the endpoint uses the 2017-09-01 API version (affects client ID parameter name)
|
|
327
|
+
*
|
|
328
|
+
* @returns The correct query parameter name for the specified identity type and endpoint
|
|
329
|
+
*
|
|
330
|
+
* @throws {ManagedIdentityError} When an invalid managed identity ID type is provided
|
|
331
|
+
*/
|
|
256
332
|
public getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
257
333
|
managedIdentityIdType: ManagedIdentityIdType,
|
|
258
334
|
isImds?: boolean,
|
|
@@ -290,8 +366,22 @@ export abstract class BaseManagedIdentitySource {
|
|
|
290
366
|
}
|
|
291
367
|
}
|
|
292
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Validates and normalizes an environment variable containing a URL string.
|
|
371
|
+
* This static utility method ensures that environment variables used for managed identity
|
|
372
|
+
* endpoints contain properly formatted URLs and provides informative error messages when validation fails.
|
|
373
|
+
*
|
|
374
|
+
* @param envVariableStringName - The name of the environment variable being validated (for error reporting)
|
|
375
|
+
* @param envVariable - The environment variable value containing the URL string
|
|
376
|
+
* @param sourceName - The name of the managed identity source (for error reporting)
|
|
377
|
+
* @param logger - Logger instance for diagnostic information
|
|
378
|
+
*
|
|
379
|
+
* @returns The validated and normalized URL string
|
|
380
|
+
*
|
|
381
|
+
* @throws {ManagedIdentityError} When the environment variable contains a malformed URL
|
|
382
|
+
*/
|
|
293
383
|
public static getValidatedEnvVariableUrlString = (
|
|
294
|
-
envVariableStringName:
|
|
384
|
+
envVariableStringName: keyof typeof ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes,
|
|
295
385
|
envVariable: string,
|
|
296
386
|
sourceName: string,
|
|
297
387
|
logger: Logger
|
|
@@ -23,11 +23,27 @@ import {
|
|
|
23
23
|
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
+
* Azure Cloud Shell managed identity source implementation.
|
|
27
|
+
*
|
|
28
|
+
* This class handles authentication for applications running in Azure Cloud Shell environment.
|
|
29
|
+
* Cloud Shell provides a browser-accessible shell for managing Azure resources and includes
|
|
30
|
+
* a pre-configured managed identity for authentication.
|
|
31
|
+
*
|
|
26
32
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/CloudShellManagedIdentitySource.cs
|
|
27
33
|
*/
|
|
28
34
|
export class CloudShell extends BaseManagedIdentitySource {
|
|
29
35
|
private msiEndpoint: string;
|
|
30
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new CloudShell managed identity source instance.
|
|
39
|
+
*
|
|
40
|
+
* @param logger - Logger instance for diagnostic logging
|
|
41
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
42
|
+
* @param networkClient - HTTP client for making requests to the managed identity endpoint
|
|
43
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
44
|
+
* @param disableInternalRetries - Whether to disable automatic retry logic for failed requests
|
|
45
|
+
* @param msiEndpoint - The MSI endpoint URL obtained from environment variables
|
|
46
|
+
*/
|
|
31
47
|
constructor(
|
|
32
48
|
logger: Logger,
|
|
33
49
|
nodeStorage: NodeStorage,
|
|
@@ -47,6 +63,14 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
47
63
|
this.msiEndpoint = msiEndpoint;
|
|
48
64
|
}
|
|
49
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the required environment variables for Cloud Shell managed identity.
|
|
68
|
+
*
|
|
69
|
+
* Cloud Shell requires the MSI_ENDPOINT environment variable to be set, which
|
|
70
|
+
* contains the URL of the managed identity service endpoint.
|
|
71
|
+
*
|
|
72
|
+
* @returns An array containing the MSI_ENDPOINT environment variable value (or undefined if not set)
|
|
73
|
+
*/
|
|
50
74
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
51
75
|
const msiEndpoint: string | undefined =
|
|
52
76
|
process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
|
|
@@ -54,6 +78,25 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
54
78
|
return [msiEndpoint];
|
|
55
79
|
}
|
|
56
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Attempts to create a CloudShell managed identity source instance.
|
|
83
|
+
*
|
|
84
|
+
* This method validates that the required environment variables are present and
|
|
85
|
+
* creates a CloudShell instance if the environment is properly configured.
|
|
86
|
+
* Cloud Shell only supports system-assigned managed identities.
|
|
87
|
+
*
|
|
88
|
+
* @param logger - Logger instance for diagnostic logging
|
|
89
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
90
|
+
* @param networkClient - HTTP client for making requests
|
|
91
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
92
|
+
* @param disableInternalRetries - Whether to disable automatic retry logic
|
|
93
|
+
* @param managedIdentityId - The managed identity configuration (must be system-assigned)
|
|
94
|
+
*
|
|
95
|
+
* @returns A CloudShell instance if the environment is valid, null otherwise
|
|
96
|
+
*
|
|
97
|
+
* @throws {ManagedIdentityError} When a user-assigned managed identity is requested,
|
|
98
|
+
* as Cloud Shell only supports system-assigned identities
|
|
99
|
+
*/
|
|
57
100
|
public static tryCreate(
|
|
58
101
|
logger: Logger,
|
|
59
102
|
nodeStorage: NodeStorage,
|
|
@@ -102,6 +145,17 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
102
145
|
);
|
|
103
146
|
}
|
|
104
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Creates an HTTP request to acquire an access token from the Cloud Shell managed identity endpoint.
|
|
150
|
+
*
|
|
151
|
+
* This method constructs a POST request to the MSI endpoint with the required headers and
|
|
152
|
+
* body parameters for Cloud Shell authentication. The request includes the target resource
|
|
153
|
+
* for which the access token is being requested.
|
|
154
|
+
*
|
|
155
|
+
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
|
156
|
+
*
|
|
157
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
158
|
+
*/
|
|
105
159
|
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
106
160
|
const request: ManagedIdentityRequestParameters =
|
|
107
161
|
new ManagedIdentityRequestParameters(
|