@azure/msal-node 3.7.4 → 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.
Files changed (100) hide show
  1. package/dist/cache/CacheHelpers.mjs +1 -1
  2. package/dist/cache/NodeStorage.d.ts.map +1 -1
  3. package/dist/cache/NodeStorage.mjs +2 -2
  4. package/dist/cache/NodeStorage.mjs.map +1 -1
  5. package/dist/cache/TokenCache.mjs +1 -1
  6. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  7. package/dist/cache/serializer/Deserializer.mjs +1 -1
  8. package/dist/cache/serializer/Serializer.mjs +1 -1
  9. package/dist/client/ClientApplication.mjs +1 -1
  10. package/dist/client/ClientAssertion.mjs +1 -1
  11. package/dist/client/ClientCredentialClient.mjs +1 -1
  12. package/dist/client/ConfidentialClientApplication.mjs +1 -1
  13. package/dist/client/DeviceCodeClient.mjs +1 -1
  14. package/dist/client/ManagedIdentityApplication.mjs +1 -1
  15. package/dist/client/ManagedIdentityClient.mjs +1 -1
  16. package/dist/client/ManagedIdentitySources/AppService.d.ts +54 -0
  17. package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  18. package/dist/client/ManagedIdentitySources/AppService.mjs +55 -1
  19. package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
  20. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
  21. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  22. package/dist/client/ManagedIdentitySources/AzureArc.mjs +82 -1
  23. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  24. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
  25. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  26. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +81 -1
  27. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  28. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
  29. package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
  30. package/dist/client/ManagedIdentitySources/CloudShell.mjs +55 -1
  31. package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
  32. package/dist/client/ManagedIdentitySources/Imds.d.ts +44 -22
  33. package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  34. package/dist/client/ManagedIdentitySources/Imds.mjs +44 -22
  35. package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
  36. package/dist/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
  37. package/dist/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
  38. package/dist/client/ManagedIdentitySources/MachineLearning.mjs +66 -1
  39. package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
  40. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
  41. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  42. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +57 -23
  43. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -1
  44. package/dist/client/OnBehalfOfClient.mjs +1 -1
  45. package/dist/client/PublicClientApplication.mjs +1 -1
  46. package/dist/client/UsernamePasswordClient.mjs +1 -1
  47. package/dist/config/Configuration.mjs +1 -1
  48. package/dist/config/ManagedIdentityId.mjs +1 -1
  49. package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
  50. package/dist/crypto/CryptoProvider.mjs +1 -1
  51. package/dist/crypto/GuidGenerator.mjs +1 -1
  52. package/dist/crypto/HashUtils.mjs +1 -1
  53. package/dist/crypto/PkceGenerator.mjs +1 -1
  54. package/dist/error/ManagedIdentityError.mjs +1 -1
  55. package/dist/error/ManagedIdentityErrorCodes.mjs +1 -1
  56. package/dist/error/NodeAuthError.mjs +1 -1
  57. package/dist/index.mjs +1 -1
  58. package/dist/internals.mjs +1 -1
  59. package/dist/network/HttpClient.mjs +1 -1
  60. package/dist/network/HttpClientWithRetries.mjs +1 -1
  61. package/dist/network/LoopbackClient.mjs +1 -1
  62. package/dist/packageMetadata.d.ts +1 -1
  63. package/dist/packageMetadata.mjs +2 -2
  64. package/dist/protocol/Authorize.mjs +1 -1
  65. package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs +1 -1
  66. package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
  67. package/dist/retry/ImdsRetryPolicy.mjs +1 -1
  68. package/dist/retry/LinearRetryStrategy.mjs +1 -1
  69. package/dist/utils/Constants.mjs +1 -1
  70. package/dist/utils/EncodingUtils.mjs +1 -1
  71. package/dist/utils/NetworkUtils.mjs +1 -1
  72. package/dist/utils/TimeUtils.mjs +1 -1
  73. package/lib/msal-node.cjs +919 -502
  74. package/lib/msal-node.cjs.map +1 -1
  75. package/lib/types/cache/NodeStorage.d.ts.map +1 -1
  76. package/lib/types/client/ManagedIdentitySources/AppService.d.ts +54 -0
  77. package/lib/types/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  78. package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
  79. package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  80. package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
  81. package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  82. package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
  83. package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
  84. package/lib/types/client/ManagedIdentitySources/Imds.d.ts +44 -22
  85. package/lib/types/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  86. package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
  87. package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
  88. package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
  89. package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  90. package/lib/types/packageMetadata.d.ts +1 -1
  91. package/package.json +2 -2
  92. package/src/cache/NodeStorage.ts +3 -1
  93. package/src/client/ManagedIdentitySources/AppService.ts +54 -0
  94. package/src/client/ManagedIdentitySources/AzureArc.ts +81 -0
  95. package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +92 -2
  96. package/src/client/ManagedIdentitySources/CloudShell.ts +54 -0
  97. package/src/client/ManagedIdentitySources/Imds.ts +43 -21
  98. package/src/client/ManagedIdentitySources/MachineLearning.ts +65 -0
  99. package/src/client/ManagedIdentitySources/ServiceFabric.ts +56 -22
  100. package/src/packageMetadata.ts +1 -1
@@ -26,19 +26,26 @@ const DEFAULT_IMDS_ENDPOINT: string = `http://169.254.169.254${IMDS_TOKEN_PATH}`
26
26
  const IMDS_API_VERSION: string = "2018-02-01";
27
27
 
28
28
  /**
29
+ * Managed Identity source implementation for Azure Instance Metadata Service (IMDS).
30
+ *
31
+ * IMDS is available on Azure Virtual Machines and Virtual Machine Scale Sets and provides
32
+ * a REST endpoint to obtain OAuth tokens for managed identities. This implementation
33
+ * handles both system-assigned and user-assigned managed identities.
34
+ *
29
35
  * Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
30
36
  */
31
37
  export class Imds extends BaseManagedIdentitySource {
32
38
  private identityEndpoint: string;
33
39
 
34
40
  /**
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.
41
+ * Constructs an Imds instance with the specified configuration.
42
+ *
43
+ * @param logger - Logger instance for recording debug information and errors
44
+ * @param nodeStorage - NodeStorage instance used for token caching operations
45
+ * @param networkClient - Network client implementation for making HTTP requests to IMDS
46
+ * @param cryptoProvider - CryptoProvider for generating correlation IDs and other cryptographic operations
47
+ * @param disableInternalRetries - When true, disables the built-in retry logic for IMDS requests
48
+ * @param identityEndpoint - The complete IMDS endpoint URL including the token path
42
49
  */
43
50
  constructor(
44
51
  logger: Logger,
@@ -60,16 +67,20 @@ export class Imds extends BaseManagedIdentitySource {
60
67
  }
61
68
 
62
69
  /**
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.
70
+ * Creates an Imds instance with the appropriate endpoint configuration.
71
+ *
72
+ * This method checks for the presence of the AZURE_POD_IDENTITY_AUTHORITY_HOST environment
73
+ * variable, which is used in Azure Kubernetes Service (AKS) environments with Azure AD
74
+ * Pod Identity. If found, it uses that endpoint; otherwise, it falls back to the standard
75
+ * IMDS endpoint (169.254.169.254).
76
+ *
77
+ * @param logger - Logger instance for recording endpoint discovery and validation
78
+ * @param nodeStorage - NodeStorage instance for token caching
79
+ * @param networkClient - Network client for HTTP requests
80
+ * @param cryptoProvider - CryptoProvider for cryptographic operations
81
+ * @param disableInternalRetries - Whether to disable built-in retry logic
66
82
  *
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.
83
+ * @returns A configured Imds instance ready to make token requests
73
84
  */
74
85
  public static tryCreate(
75
86
  logger: Logger,
@@ -125,12 +136,23 @@ export class Imds extends BaseManagedIdentitySource {
125
136
  }
126
137
 
127
138
  /**
128
- * Creates a ManagedIdentityRequestParameters object for acquiring a token from IMDS.
129
- * Sets the required headers and query parameters for the IMDS token request.
139
+ * Creates a properly configured HTTP request for acquiring an access token from IMDS.
140
+ *
141
+ * This method builds a complete request object with all necessary headers, query parameters,
142
+ * and retry policies required by the Azure Instance Metadata Service.
143
+ *
144
+ * Key request components:
145
+ * - HTTP GET method to the IMDS token endpoint
146
+ * - Metadata header set to "true" (required by IMDS)
147
+ * - API version parameter (currently "2018-02-01")
148
+ * - Resource parameter specifying the target audience
149
+ * - Identity-specific parameters for user-assigned managed identities
150
+ * - IMDS-specific retry policy
151
+ *
152
+ * @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
153
+ * @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
130
154
  *
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.
155
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
134
156
  */
135
157
  public createRequest(
136
158
  resource: string,
@@ -25,10 +25,28 @@ const MACHINE_LEARNING_MSI_API_VERSION: string = "2017-09-01";
25
25
 
26
26
  export const MANAGED_IDENTITY_MACHINE_LEARNING_UNSUPPORTED_ID_TYPE_ERROR = `Only client id is supported for user-assigned managed identity in ${ManagedIdentitySourceNames.MACHINE_LEARNING}.`; // referenced in unit test
27
27
 
28
+ /**
29
+ * Machine Learning Managed Identity Source implementation for Azure Machine Learning environments.
30
+ *
31
+ * This class handles managed identity authentication specifically for Azure Machine Learning services.
32
+ * It supports both system-assigned and user-assigned managed identities, using the MSI_ENDPOINT
33
+ * and MSI_SECRET environment variables that are automatically provided in Azure ML environments.
34
+ */
28
35
  export class MachineLearning extends BaseManagedIdentitySource {
29
36
  private msiEndpoint: string;
30
37
  private secret: string;
31
38
 
39
+ /**
40
+ * Creates a new MachineLearning managed identity source instance.
41
+ *
42
+ * @param logger - Logger instance for diagnostic information
43
+ * @param nodeStorage - Node storage implementation for caching
44
+ * @param networkClient - Network client for making HTTP requests
45
+ * @param cryptoProvider - Cryptographic operations provider
46
+ * @param disableInternalRetries - Whether to disable automatic request retries
47
+ * @param msiEndpoint - The MSI endpoint URL from environment variables
48
+ * @param secret - The MSI secret from environment variables
49
+ */
32
50
  constructor(
33
51
  logger: Logger,
34
52
  nodeStorage: NodeStorage,
@@ -50,6 +68,16 @@ export class MachineLearning extends BaseManagedIdentitySource {
50
68
  this.secret = secret;
51
69
  }
52
70
 
71
+ /**
72
+ * Retrieves the required environment variables for Azure Machine Learning managed identity.
73
+ *
74
+ * This method checks for the presence of MSI_ENDPOINT and MSI_SECRET environment variables
75
+ * that are automatically set by the Azure Machine Learning platform when managed identity
76
+ * is enabled for the compute instance or cluster.
77
+ *
78
+ * @returns An array containing [msiEndpoint, secret] where either value may be undefined
79
+ * if the corresponding environment variable is not set
80
+ */
53
81
  public static getEnvironmentVariables(): Array<string | undefined> {
54
82
  const msiEndpoint: string | undefined =
55
83
  process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
@@ -60,6 +88,23 @@ export class MachineLearning extends BaseManagedIdentitySource {
60
88
  return [msiEndpoint, secret];
61
89
  }
62
90
 
91
+ /**
92
+ * Attempts to create a MachineLearning managed identity source.
93
+ *
94
+ * This method validates the Azure Machine Learning environment by checking for the required
95
+ * MSI_ENDPOINT and MSI_SECRET environment variables. If both are present and valid,
96
+ * it creates and returns a MachineLearning instance. If either is missing or invalid,
97
+ * it returns null, indicating that this managed identity source is not available
98
+ * in the current environment.
99
+ *
100
+ * @param logger - Logger instance for diagnostic information
101
+ * @param nodeStorage - Node storage implementation for caching
102
+ * @param networkClient - Network client for making HTTP requests
103
+ * @param cryptoProvider - Cryptographic operations provider
104
+ * @param disableInternalRetries - Whether to disable automatic request retries
105
+ *
106
+ * @returns A new MachineLearning instance if the environment is valid, null otherwise
107
+ */
63
108
  public static tryCreate(
64
109
  logger: Logger,
65
110
  nodeStorage: NodeStorage,
@@ -100,6 +145,26 @@ export class MachineLearning extends BaseManagedIdentitySource {
100
145
  );
101
146
  }
102
147
 
148
+ /**
149
+ * Creates a managed identity token request for Azure Machine Learning environments.
150
+ *
151
+ * This method constructs the HTTP request parameters needed to acquire an access token
152
+ * from the Azure Machine Learning managed identity endpoint. It handles both system-assigned
153
+ * and user-assigned managed identities with specific logic for each type:
154
+ *
155
+ * - System-assigned: Uses the DEFAULT_IDENTITY_CLIENT_ID environment variable
156
+ * - User-assigned: Only supports client ID-based identification (not object ID or resource ID)
157
+ *
158
+ * The request uses the 2017-09-01 API version and includes the required secret header
159
+ * for authentication with the MSI endpoint.
160
+ *
161
+ * @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
162
+ * @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
163
+ *
164
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
165
+ *
166
+ * @throws Error if an unsupported managed identity ID type is specified (only client ID is supported for user-assigned)
167
+ */
103
168
  public createRequest(
104
169
  resource: string,
105
170
  managedIdentityId: ManagedIdentityId
@@ -28,14 +28,19 @@ export class ServiceFabric extends BaseManagedIdentitySource {
28
28
  private identityHeader: string;
29
29
 
30
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
31
+ * Constructs a new ServiceFabric managed identity source for acquiring tokens from Azure Service Fabric clusters.
32
+ *
33
+ * Service Fabric managed identity allows applications running in Service Fabric clusters to authenticate
34
+ * without storing credentials in code. This source handles token acquisition using the Service Fabric
35
+ * Managed Identity Token Service (MITS).
36
+ *
37
+ * @param logger - Logger instance for logging authentication events and debugging information
38
+ * @param nodeStorage - NodeStorage instance for caching tokens and other authentication artifacts
39
+ * @param networkClient - Network client for making HTTP requests to the Service Fabric identity endpoint
40
+ * @param cryptoProvider - Crypto provider for cryptographic operations like token validation
41
+ * @param disableInternalRetries - Whether to disable internal retry logic for failed requests
42
+ * @param identityEndpoint - The Service Fabric managed identity endpoint URL
43
+ * @param identityHeader - The Service Fabric managed identity secret header value
39
44
  */
40
45
  constructor(
41
46
  logger: Logger,
@@ -59,8 +64,16 @@ export class ServiceFabric extends BaseManagedIdentitySource {
59
64
  }
60
65
 
61
66
  /**
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.
67
+ * Retrieves the environment variables required for Service Fabric managed identity authentication.
68
+ *
69
+ * Service Fabric managed identity requires three specific environment variables to be set by the
70
+ * Service Fabric runtime:
71
+ * - IDENTITY_ENDPOINT: The endpoint URL for the Managed Identity Token Service (MITS)
72
+ * - IDENTITY_HEADER: A secret value used for authentication with the MITS
73
+ * - IDENTITY_SERVER_THUMBPRINT: The thumbprint of the MITS server certificate for secure communication
74
+ *
75
+ * @returns An array containing the identity endpoint, identity header, and identity server thumbprint values.
76
+ * Elements will be undefined if the corresponding environment variables are not set.
64
77
  */
65
78
  public static getEnvironmentVariables(): Array<string | undefined> {
66
79
  const identityEndpoint: string | undefined =
@@ -81,14 +94,23 @@ export class ServiceFabric extends BaseManagedIdentitySource {
81
94
  }
82
95
 
83
96
  /**
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
97
+ * Attempts to create a ServiceFabric managed identity source if the runtime environment supports it.
98
+ *
99
+ * Checks for the presence of all required Service Fabric environment variables
100
+ * and validates the endpoint URL format. It will only create a ServiceFabric instance if the application
101
+ * is running in a properly configured Service Fabric cluster with managed identity enabled.
102
+ *
103
+ * Note: User-assigned managed identities must be configured at the cluster level, not at runtime.
104
+ * This method will log a warning if a user-assigned identity is requested.
105
+ *
106
+ * @param logger - Logger instance for logging creation events and validation results
107
+ * @param nodeStorage - NodeStorage instance for caching tokens and authentication artifacts
108
+ * @param networkClient - Network client for making HTTP requests to the identity endpoint
109
+ * @param cryptoProvider - Crypto provider for cryptographic operations
110
+ * @param disableInternalRetries - Whether to disable internal retry logic for failed requests
111
+ * @param managedIdentityId - Managed identity identifier specifying system-assigned or user-assigned identity
112
+ *
113
+ * @returns A ServiceFabric instance if all environment variables are valid and present, otherwise null
92
114
  */
93
115
  public static tryCreate(
94
116
  logger: Logger,
@@ -140,10 +162,22 @@ export class ServiceFabric extends BaseManagedIdentitySource {
140
162
  }
141
163
 
142
164
  /**
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.
165
+ * Creates HTTP request parameters for acquiring an access token from the Service Fabric Managed Identity Token Service (MITS).
166
+ *
167
+ * This method constructs a properly formatted HTTP GET request that includes:
168
+ * - The secret header for authentication with MITS
169
+ * - API version parameter for the Service Fabric MSI endpoint
170
+ * - Resource parameter specifying the target Azure service
171
+ * - Optional identity parameters for user-assigned managed identities
172
+ *
173
+ * The request follows the Service Fabric managed identity protocol and uses the 2019-07-01-preview API version.
174
+ * For user-assigned identities, the appropriate query parameter (client_id, object_id, or resource_id) is added
175
+ * based on the identity type.
176
+ *
177
+ * @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
178
+ * @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
179
+ *
180
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
147
181
  */
148
182
  public createRequest(
149
183
  resource: string,
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-node";
3
- export const version = "3.7.4";
3
+ export const version = "3.8.1";