@azure/msal-node 5.0.0-alpha.0 → 5.0.0-beta.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.
Files changed (252) hide show
  1. package/dist/cache/CacheHelpers.mjs +1 -1
  2. package/dist/cache/NodeStorage.mjs +1 -1
  3. package/dist/cache/NodeStorage.mjs.map +1 -1
  4. package/dist/cache/TokenCache.mjs +1 -1
  5. package/dist/cache/TokenCache.mjs.map +1 -1
  6. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  7. package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
  8. package/dist/cache/serializer/Deserializer.mjs +1 -1
  9. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  10. package/dist/cache/serializer/Serializer.mjs +1 -1
  11. package/dist/cache/serializer/Serializer.mjs.map +1 -1
  12. package/dist/client/BaseClient.d.ts +42 -0
  13. package/dist/client/BaseClient.d.ts.map +1 -0
  14. package/dist/client/BaseClient.mjs +68 -0
  15. package/dist/client/BaseClient.mjs.map +1 -0
  16. package/dist/client/ClientApplication.mjs +1 -1
  17. package/dist/client/ClientApplication.mjs.map +1 -1
  18. package/dist/client/ClientAssertion.mjs +1 -1
  19. package/dist/client/ClientAssertion.mjs.map +1 -1
  20. package/dist/client/ClientCredentialClient.d.ts +2 -1
  21. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  22. package/dist/client/ClientCredentialClient.mjs +4 -3
  23. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  24. package/dist/client/ConfidentialClientApplication.mjs +1 -1
  25. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  26. package/dist/client/DeviceCodeClient.d.ts +2 -1
  27. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  28. package/dist/client/DeviceCodeClient.mjs +6 -5
  29. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  30. package/dist/client/ManagedIdentityApplication.mjs +1 -1
  31. package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
  32. package/dist/client/ManagedIdentityClient.mjs +1 -1
  33. package/dist/client/ManagedIdentityClient.mjs.map +1 -1
  34. package/dist/client/ManagedIdentitySources/AppService.d.ts +54 -0
  35. package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  36. package/dist/client/ManagedIdentitySources/AppService.mjs +55 -1
  37. package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
  38. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
  39. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  40. package/dist/client/ManagedIdentitySources/AzureArc.mjs +82 -1
  41. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  42. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
  43. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  44. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +81 -1
  45. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  46. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
  47. package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
  48. package/dist/client/ManagedIdentitySources/CloudShell.mjs +55 -1
  49. package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
  50. package/dist/client/ManagedIdentitySources/Imds.d.ts +44 -22
  51. package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  52. package/dist/client/ManagedIdentitySources/Imds.mjs +44 -22
  53. package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
  54. package/dist/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
  55. package/dist/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
  56. package/dist/client/ManagedIdentitySources/MachineLearning.mjs +66 -1
  57. package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
  58. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
  59. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  60. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +57 -23
  61. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -1
  62. package/dist/client/OnBehalfOfClient.d.ts +2 -1
  63. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  64. package/dist/client/OnBehalfOfClient.mjs +4 -3
  65. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  66. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  67. package/dist/client/PublicClientApplication.mjs +21 -5
  68. package/dist/client/PublicClientApplication.mjs.map +1 -1
  69. package/dist/client/UsernamePasswordClient.d.ts +2 -1
  70. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  71. package/dist/client/UsernamePasswordClient.mjs +4 -3
  72. package/dist/client/UsernamePasswordClient.mjs.map +1 -1
  73. package/dist/config/Configuration.d.ts +0 -6
  74. package/dist/config/Configuration.d.ts.map +1 -1
  75. package/dist/config/Configuration.mjs +3 -5
  76. package/dist/config/Configuration.mjs.map +1 -1
  77. package/dist/config/ManagedIdentityId.mjs +1 -1
  78. package/dist/config/ManagedIdentityId.mjs.map +1 -1
  79. package/dist/config/ManagedIdentityRequestParameters.mjs +3 -3
  80. package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -1
  81. package/dist/crypto/CryptoProvider.mjs +1 -1
  82. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  83. package/dist/crypto/GuidGenerator.mjs +1 -1
  84. package/dist/crypto/GuidGenerator.mjs.map +1 -1
  85. package/dist/crypto/HashUtils.mjs +1 -1
  86. package/dist/crypto/HashUtils.mjs.map +1 -1
  87. package/dist/crypto/PkceGenerator.mjs +1 -1
  88. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  89. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  90. package/dist/error/ManagedIdentityError.mjs +1 -1
  91. package/dist/error/ManagedIdentityError.mjs.map +1 -1
  92. package/dist/error/ManagedIdentityErrorCodes.mjs +1 -1
  93. package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
  94. package/dist/error/NodeAuthError.d.ts +8 -0
  95. package/dist/error/NodeAuthError.d.ts.map +1 -1
  96. package/dist/error/NodeAuthError.mjs +11 -1
  97. package/dist/error/NodeAuthError.mjs.map +1 -1
  98. package/dist/index.d.ts +0 -6
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.mjs +1 -7
  101. package/dist/index.mjs.map +1 -1
  102. package/dist/internals.mjs +1 -1
  103. package/dist/network/HttpClient.d.ts +54 -14
  104. package/dist/network/HttpClient.d.ts.map +1 -1
  105. package/dist/network/HttpClient.mjs +140 -262
  106. package/dist/network/HttpClient.mjs.map +1 -1
  107. package/dist/network/HttpClientWithRetries.mjs +1 -1
  108. package/dist/network/HttpClientWithRetries.mjs.map +1 -1
  109. package/dist/network/LoopbackClient.mjs +1 -1
  110. package/dist/network/LoopbackClient.mjs.map +1 -1
  111. package/dist/packageMetadata.d.ts +1 -1
  112. package/dist/packageMetadata.d.ts.map +1 -1
  113. package/dist/packageMetadata.mjs +2 -2
  114. package/dist/protocol/Authorize.mjs +2 -2
  115. package/dist/protocol/Authorize.mjs.map +1 -1
  116. package/dist/request/AuthorizationCodeRequest.d.ts +2 -1
  117. package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -1
  118. package/dist/request/AuthorizationUrlRequest.d.ts +2 -2
  119. package/dist/request/ClientCredentialRequest.d.ts +0 -1
  120. package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
  121. package/dist/request/CommonClientCredentialRequest.d.ts +3 -2
  122. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  123. package/dist/request/CommonDeviceCodeRequest.d.ts +3 -2
  124. package/dist/request/CommonDeviceCodeRequest.d.ts.map +1 -1
  125. package/dist/request/CommonOnBehalfOfRequest.d.ts +1 -2
  126. package/dist/request/CommonOnBehalfOfRequest.d.ts.map +1 -1
  127. package/dist/request/CommonUsernamePasswordRequest.d.ts +2 -1
  128. package/dist/request/CommonUsernamePasswordRequest.d.ts.map +1 -1
  129. package/dist/request/InteractiveRequest.d.ts +1 -1
  130. package/dist/request/InteractiveRequest.d.ts.map +1 -1
  131. package/dist/request/OnBehalfOfRequest.d.ts +0 -1
  132. package/dist/request/OnBehalfOfRequest.d.ts.map +1 -1
  133. package/dist/request/RefreshTokenRequest.d.ts +2 -1
  134. package/dist/request/RefreshTokenRequest.d.ts.map +1 -1
  135. package/dist/request/SilentFlowRequest.d.ts +2 -1
  136. package/dist/request/SilentFlowRequest.d.ts.map +1 -1
  137. package/dist/request/UsernamePasswordRequest.d.ts +2 -1
  138. package/dist/request/UsernamePasswordRequest.d.ts.map +1 -1
  139. package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs +1 -1
  140. package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs.map +1 -1
  141. package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
  142. package/dist/retry/ExponentialRetryStrategy.mjs.map +1 -1
  143. package/dist/retry/ImdsRetryPolicy.mjs +1 -1
  144. package/dist/retry/ImdsRetryPolicy.mjs.map +1 -1
  145. package/dist/retry/LinearRetryStrategy.mjs +1 -1
  146. package/dist/retry/LinearRetryStrategy.mjs.map +1 -1
  147. package/dist/utils/Constants.d.ts +2 -9
  148. package/dist/utils/Constants.d.ts.map +1 -1
  149. package/dist/utils/Constants.mjs +4 -12
  150. package/dist/utils/Constants.mjs.map +1 -1
  151. package/dist/utils/EncodingUtils.mjs +1 -1
  152. package/dist/utils/EncodingUtils.mjs.map +1 -1
  153. package/dist/utils/TimeUtils.mjs +1 -1
  154. package/dist/utils/TimeUtils.mjs.map +1 -1
  155. package/lib/msal-node.cjs +5747 -5335
  156. package/lib/msal-node.cjs.map +1 -1
  157. package/lib/types/client/BaseClient.d.ts +42 -0
  158. package/lib/types/client/BaseClient.d.ts.map +1 -0
  159. package/lib/types/client/ClientCredentialClient.d.ts +2 -1
  160. package/lib/types/client/ClientCredentialClient.d.ts.map +1 -1
  161. package/lib/types/client/DeviceCodeClient.d.ts +2 -1
  162. package/lib/types/client/DeviceCodeClient.d.ts.map +1 -1
  163. package/lib/types/client/ManagedIdentitySources/AppService.d.ts +54 -0
  164. package/lib/types/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  165. package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
  166. package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  167. package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
  168. package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  169. package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
  170. package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
  171. package/lib/types/client/ManagedIdentitySources/Imds.d.ts +44 -22
  172. package/lib/types/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  173. package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
  174. package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
  175. package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
  176. package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  177. package/lib/types/client/OnBehalfOfClient.d.ts +2 -1
  178. package/lib/types/client/OnBehalfOfClient.d.ts.map +1 -1
  179. package/lib/types/client/PublicClientApplication.d.ts.map +1 -1
  180. package/lib/types/client/UsernamePasswordClient.d.ts +2 -1
  181. package/lib/types/client/UsernamePasswordClient.d.ts.map +1 -1
  182. package/lib/types/config/Configuration.d.ts +0 -6
  183. package/lib/types/config/Configuration.d.ts.map +1 -1
  184. package/lib/types/error/NodeAuthError.d.ts +8 -0
  185. package/lib/types/error/NodeAuthError.d.ts.map +1 -1
  186. package/lib/types/index.d.ts +0 -6
  187. package/lib/types/index.d.ts.map +1 -1
  188. package/lib/types/network/HttpClient.d.ts +54 -14
  189. package/lib/types/network/HttpClient.d.ts.map +1 -1
  190. package/lib/types/packageMetadata.d.ts +1 -1
  191. package/lib/types/packageMetadata.d.ts.map +1 -1
  192. package/lib/types/request/AuthorizationCodeRequest.d.ts +2 -1
  193. package/lib/types/request/AuthorizationCodeRequest.d.ts.map +1 -1
  194. package/lib/types/request/AuthorizationUrlRequest.d.ts +2 -2
  195. package/lib/types/request/ClientCredentialRequest.d.ts +0 -1
  196. package/lib/types/request/ClientCredentialRequest.d.ts.map +1 -1
  197. package/lib/types/request/CommonClientCredentialRequest.d.ts +3 -2
  198. package/lib/types/request/CommonClientCredentialRequest.d.ts.map +1 -1
  199. package/lib/types/request/CommonDeviceCodeRequest.d.ts +3 -2
  200. package/lib/types/request/CommonDeviceCodeRequest.d.ts.map +1 -1
  201. package/lib/types/request/CommonOnBehalfOfRequest.d.ts +1 -2
  202. package/lib/types/request/CommonOnBehalfOfRequest.d.ts.map +1 -1
  203. package/lib/types/request/CommonUsernamePasswordRequest.d.ts +2 -1
  204. package/lib/types/request/CommonUsernamePasswordRequest.d.ts.map +1 -1
  205. package/lib/types/request/InteractiveRequest.d.ts +1 -1
  206. package/lib/types/request/InteractiveRequest.d.ts.map +1 -1
  207. package/lib/types/request/OnBehalfOfRequest.d.ts +0 -1
  208. package/lib/types/request/OnBehalfOfRequest.d.ts.map +1 -1
  209. package/lib/types/request/RefreshTokenRequest.d.ts +2 -1
  210. package/lib/types/request/RefreshTokenRequest.d.ts.map +1 -1
  211. package/lib/types/request/SilentFlowRequest.d.ts +2 -1
  212. package/lib/types/request/SilentFlowRequest.d.ts.map +1 -1
  213. package/lib/types/request/UsernamePasswordRequest.d.ts +2 -1
  214. package/lib/types/request/UsernamePasswordRequest.d.ts.map +1 -1
  215. package/lib/types/utils/Constants.d.ts +2 -9
  216. package/lib/types/utils/Constants.d.ts.map +1 -1
  217. package/package.json +88 -88
  218. package/src/client/BaseClient.ts +158 -0
  219. package/src/client/ClientCredentialClient.ts +2 -3
  220. package/src/client/DeviceCodeClient.ts +4 -5
  221. package/src/client/ManagedIdentitySources/AppService.ts +54 -0
  222. package/src/client/ManagedIdentitySources/AzureArc.ts +81 -0
  223. package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +92 -2
  224. package/src/client/ManagedIdentitySources/CloudShell.ts +54 -0
  225. package/src/client/ManagedIdentitySources/Imds.ts +43 -21
  226. package/src/client/ManagedIdentitySources/MachineLearning.ts +65 -0
  227. package/src/client/ManagedIdentitySources/ServiceFabric.ts +56 -22
  228. package/src/client/OnBehalfOfClient.ts +2 -3
  229. package/src/client/PublicClientApplication.ts +22 -4
  230. package/src/client/UsernamePasswordClient.ts +2 -3
  231. package/src/config/Configuration.ts +2 -14
  232. package/src/config/ManagedIdentityRequestParameters.ts +2 -2
  233. package/src/error/NodeAuthError.ts +14 -0
  234. package/src/index.ts +0 -8
  235. package/src/network/HttpClient.ts +166 -372
  236. package/src/packageMetadata.ts +1 -1
  237. package/src/protocol/Authorize.ts +1 -1
  238. package/src/request/AuthorizationCodeRequest.ts +2 -1
  239. package/src/request/AuthorizationUrlRequest.ts +2 -2
  240. package/src/request/ClientCredentialRequest.ts +0 -1
  241. package/src/request/CommonClientCredentialRequest.ts +6 -2
  242. package/src/request/CommonDeviceCodeRequest.ts +3 -6
  243. package/src/request/CommonOnBehalfOfRequest.ts +4 -2
  244. package/src/request/CommonUsernamePasswordRequest.ts +2 -1
  245. package/src/request/InteractiveRequest.ts +1 -4
  246. package/src/request/OnBehalfOfRequest.ts +0 -1
  247. package/src/request/RefreshTokenRequest.ts +2 -1
  248. package/src/request/SilentFlowRequest.ts +2 -1
  249. package/src/request/UsernamePasswordRequest.ts +2 -1
  250. package/src/utils/Constants.ts +2 -11
  251. package/dist/utils/NetworkUtils.mjs +0 -43
  252. package/dist/utils/NetworkUtils.mjs.map +0 -1
@@ -62,11 +62,27 @@ export const AZURE_ARC_FILE_DETECTION: FilePathMap = {
62
62
  };
63
63
 
64
64
  /**
65
+ * Azure Arc managed identity source implementation for acquiring tokens from Azure Arc-enabled servers.
66
+ *
67
+ * This class provides managed identity authentication for applications running on Azure Arc-enabled servers
68
+ * by communicating with the local Hybrid Instance Metadata Service (HIMDS). It supports both environment
69
+ * variable-based configuration and automatic detection through the HIMDS executable.
70
+ *
65
71
  * Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
66
72
  */
67
73
  export class AzureArc extends BaseManagedIdentitySource {
68
74
  private identityEndpoint: string;
69
75
 
76
+ /**
77
+ * Creates a new instance of the AzureArc managed identity source.
78
+ *
79
+ * @param logger - Logger instance for capturing telemetry and diagnostic information
80
+ * @param nodeStorage - Storage implementation for caching tokens and metadata
81
+ * @param networkClient - Network client for making HTTP requests to the identity endpoint
82
+ * @param cryptoProvider - Cryptographic operations provider for token validation and encryption
83
+ * @param disableInternalRetries - Flag to disable automatic retry logic for failed requests
84
+ * @param identityEndpoint - The Azure Arc identity endpoint URL for token requests
85
+ */
70
86
  constructor(
71
87
  logger: Logger,
72
88
  nodeStorage: NodeStorage,
@@ -86,6 +102,17 @@ export class AzureArc extends BaseManagedIdentitySource {
86
102
  this.identityEndpoint = identityEndpoint;
87
103
  }
88
104
 
105
+ /**
106
+ * Retrieves and validates Azure Arc environment variables for managed identity configuration.
107
+ *
108
+ * This method checks for IDENTITY_ENDPOINT and IMDS_ENDPOINT environment variables.
109
+ * If either is missing, it attempts to detect the Azure Arc environment by checking for
110
+ * the HIMDS executable at platform-specific paths. On successful detection, it returns
111
+ * the default identity endpoint and a helper string indicating file-based detection.
112
+ *
113
+ * @returns An array containing [identityEndpoint, imdsEndpoint] where both values are
114
+ * strings if Azure Arc is available, or undefined if not available.
115
+ */
89
116
  public static getEnvironmentVariables(): Array<string | undefined> {
90
117
  let identityEndpoint: string | undefined =
91
118
  process.env[
@@ -122,6 +149,25 @@ export class AzureArc extends BaseManagedIdentitySource {
122
149
  return [identityEndpoint, imdsEndpoint];
123
150
  }
124
151
 
152
+ /**
153
+ * Attempts to create an AzureArc managed identity source instance.
154
+ *
155
+ * Validates the Azure Arc environment by checking environment variables
156
+ * and performing file-based detection. It ensures that only system-assigned managed identities
157
+ * are supported for Azure Arc scenarios. The method performs comprehensive validation of
158
+ * endpoint URLs and logs detailed information about the detection process.
159
+ *
160
+ * @param logger - Logger instance for capturing creation and validation steps
161
+ * @param nodeStorage - Storage implementation for the managed identity source
162
+ * @param networkClient - Network client for HTTP communication
163
+ * @param cryptoProvider - Cryptographic operations provider
164
+ * @param disableInternalRetries - Whether to disable automatic retry mechanisms
165
+ * @param managedIdentityId - The managed identity configuration, must be system-assigned
166
+ *
167
+ * @returns AzureArc instance if the environment supports Azure Arc managed identity, null otherwise
168
+ *
169
+ * @throws {ManagedIdentityError} When a user-assigned managed identity is specified (not supported for Azure Arc)
170
+ */
125
171
  public static tryCreate(
126
172
  logger: Logger,
127
173
  nodeStorage: NodeStorage,
@@ -195,6 +241,17 @@ export class AzureArc extends BaseManagedIdentitySource {
195
241
  );
196
242
  }
197
243
 
244
+ /**
245
+ * Creates a properly formatted HTTP request for acquiring tokens from the Azure Arc identity endpoint.
246
+ *
247
+ * This method constructs a GET request to the Azure Arc HIMDS endpoint with the required metadata header
248
+ * and query parameters. The endpoint URL is normalized to use 127.0.0.1 instead of localhost for
249
+ * consistency. Additional body parameters are calculated by the base class during token acquisition.
250
+ *
251
+ * @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
252
+ *
253
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
254
+ */
198
255
  public createRequest(resource: string): ManagedIdentityRequestParameters {
199
256
  const request: ManagedIdentityRequestParameters =
200
257
  new ManagedIdentityRequestParameters(
@@ -214,6 +271,30 @@ export class AzureArc extends BaseManagedIdentitySource {
214
271
  return request;
215
272
  }
216
273
 
274
+ /**
275
+ * Processes the server response and handles Azure Arc-specific authentication challenges.
276
+ *
277
+ * This method implements the Azure Arc authentication flow which may require reading a secret file
278
+ * for authorization. When the initial request returns HTTP 401 Unauthorized, it extracts the file
279
+ * path from the WWW-Authenticate header, validates the file location and size, reads the secret,
280
+ * and retries the request with Basic authentication. The method includes comprehensive security
281
+ * validations to prevent path traversal and ensure file integrity.
282
+ *
283
+ * @param originalResponse - The initial HTTP response from the identity endpoint
284
+ * @param networkClient - Network client for making the retry request if needed
285
+ * @param networkRequest - The original request parameters (modified with auth header for retry)
286
+ * @param networkRequestOptions - Additional options for network requests
287
+ *
288
+ * @returns A promise that resolves to the server token response with access token and metadata
289
+ *
290
+ * @throws {ManagedIdentityError} When:
291
+ * - WWW-Authenticate header is missing or has unsupported format
292
+ * - Platform is not supported (not Windows or Linux)
293
+ * - Secret file has invalid extension (not .key)
294
+ * - Secret file path doesn't match expected platform path
295
+ * - Secret file cannot be read or is too large (>4096 bytes)
296
+ * @throws {ClientAuthError} When network errors occur during retry request
297
+ */
217
298
  public async getServerTokenResponseAsync(
218
299
  originalResponse: NetworkResponse<ManagedIdentityTokenResponse>,
219
300
  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
- request: string,
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,
@@ -258,6 +321,19 @@ export abstract class BaseManagedIdentitySource {
258
321
  );
259
322
  }
260
323
 
324
+ /**
325
+ * Determines the appropriate query parameter name for user-assigned managed identity
326
+ * based on the identity type, API version, and endpoint characteristics.
327
+ * Different Azure services and API versions use different parameter names for the same identity types.
328
+ *
329
+ * @param managedIdentityIdType - The type of user-assigned managed identity (client ID, object ID, or resource ID)
330
+ * @param isImds - Whether the request is being made to the IMDS (Instance Metadata Service) endpoint
331
+ * @param usesApi2017 - Whether the endpoint uses the 2017-09-01 API version (affects client ID parameter name)
332
+ *
333
+ * @returns The correct query parameter name for the specified identity type and endpoint
334
+ *
335
+ * @throws {ManagedIdentityError} When an invalid managed identity ID type is provided
336
+ */
261
337
  public getManagedIdentityUserAssignedIdQueryParameterKey(
262
338
  managedIdentityIdType: ManagedIdentityIdType,
263
339
  isImds?: boolean,
@@ -298,8 +374,22 @@ export abstract class BaseManagedIdentitySource {
298
374
  }
299
375
  }
300
376
 
377
+ /**
378
+ * Validates and normalizes an environment variable containing a URL string.
379
+ * This static utility method ensures that environment variables used for managed identity
380
+ * endpoints contain properly formatted URLs and provides informative error messages when validation fails.
381
+ *
382
+ * @param envVariableStringName - The name of the environment variable being validated (for error reporting)
383
+ * @param envVariable - The environment variable value containing the URL string
384
+ * @param sourceName - The name of the managed identity source (for error reporting)
385
+ * @param logger - Logger instance for diagnostic information
386
+ *
387
+ * @returns The validated and normalized URL string
388
+ *
389
+ * @throws {ManagedIdentityError} When the environment variable contains a malformed URL
390
+ */
301
391
  public static getValidatedEnvVariableUrlString = (
302
- envVariableStringName: string,
392
+ envVariableStringName: keyof typeof ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes,
303
393
  envVariable: string,
304
394
  sourceName: string,
305
395
  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,
@@ -104,6 +147,17 @@ export class CloudShell extends BaseManagedIdentitySource {
104
147
  );
105
148
  }
106
149
 
150
+ /**
151
+ * Creates an HTTP request to acquire an access token from the Cloud Shell managed identity endpoint.
152
+ *
153
+ * This method constructs a POST request to the MSI endpoint with the required headers and
154
+ * body parameters for Cloud Shell authentication. The request includes the target resource
155
+ * for which the access token is being requested.
156
+ *
157
+ * @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
158
+ *
159
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
160
+ */
107
161
  public createRequest(resource: string): ManagedIdentityRequestParameters {
108
162
  const request: ManagedIdentityRequestParameters =
109
163
  new ManagedIdentityRequestParameters(
@@ -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,
@@ -127,12 +138,23 @@ export class Imds extends BaseManagedIdentitySource {
127
138
  }
128
139
 
129
140
  /**
130
- * Creates a ManagedIdentityRequestParameters object for acquiring a token from IMDS.
131
- * Sets the required headers and query parameters for the IMDS token request.
141
+ * Creates a properly configured HTTP request for acquiring an access token from IMDS.
142
+ *
143
+ * This method builds a complete request object with all necessary headers, query parameters,
144
+ * and retry policies required by the Azure Instance Metadata Service.
145
+ *
146
+ * Key request components:
147
+ * - HTTP GET method to the IMDS token endpoint
148
+ * - Metadata header set to "true" (required by IMDS)
149
+ * - API version parameter (currently "2018-02-01")
150
+ * - Resource parameter specifying the target audience
151
+ * - Identity-specific parameters for user-assigned managed identities
152
+ * - IMDS-specific retry policy
153
+ *
154
+ * @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
155
+ * @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
132
156
  *
133
- * @param resource - The resource URI for which the token is requested.
134
- * @param managedIdentityId - The managed identity ID (system-assigned or user-assigned).
135
- * @returns A ManagedIdentityRequestParameters object configured for IMDS.
157
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
136
158
  */
137
159
  public createRequest(
138
160
  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,
@@ -102,6 +147,26 @@ export class MachineLearning extends BaseManagedIdentitySource {
102
147
  );
103
148
  }
104
149
 
150
+ /**
151
+ * Creates a managed identity token request for Azure Machine Learning environments.
152
+ *
153
+ * This method constructs the HTTP request parameters needed to acquire an access token
154
+ * from the Azure Machine Learning managed identity endpoint. It handles both system-assigned
155
+ * and user-assigned managed identities with specific logic for each type:
156
+ *
157
+ * - System-assigned: Uses the DEFAULT_IDENTITY_CLIENT_ID environment variable
158
+ * - User-assigned: Only supports client ID-based identification (not object ID or resource ID)
159
+ *
160
+ * The request uses the 2017-09-01 API version and includes the required secret header
161
+ * for authentication with the MSI endpoint.
162
+ *
163
+ * @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
164
+ * @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
165
+ *
166
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
167
+ *
168
+ * @throws Error if an unsupported managed identity ID type is specified (only client ID is supported for user-assigned)
169
+ */
105
170
  public createRequest(
106
171
  resource: string,
107
172
  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,
@@ -143,10 +165,22 @@ export class ServiceFabric extends BaseManagedIdentitySource {
143
165
  }
144
166
 
145
167
  /**
146
- * Creates the request parameters for acquiring a token from the Service Fabric cluster.
147
- * @param resource - The resource URI for which the token is requested.
148
- * @param managedIdentityId - The managed identity ID (system-assigned or user-assigned).
149
- * @returns A ManagedIdentityRequestParameters object configured for Service Fabric.
168
+ * Creates HTTP request parameters for acquiring an access token from the Service Fabric Managed Identity Token Service (MITS).
169
+ *
170
+ * This method constructs a properly formatted HTTP GET request that includes:
171
+ * - The secret header for authentication with MITS
172
+ * - API version parameter for the Service Fabric MSI endpoint
173
+ * - Resource parameter specifying the target Azure service
174
+ * - Optional identity parameters for user-assigned managed identities
175
+ *
176
+ * The request follows the Service Fabric managed identity protocol and uses the 2019-07-01-preview API version.
177
+ * For user-assigned identities, the appropriate query parameter (client_id, object_id, or resource_id) is added
178
+ * based on the identity type.
179
+ *
180
+ * @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
181
+ * @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
182
+ *
183
+ * @returns A configured ManagedIdentityRequestParameters object ready for network execution
150
184
  */
151
185
  public createRequest(
152
186
  resource: string,