@@ -51,13 +51,30 @@ export const ManagedIdentityUserAssignedIdQueryParameterNames = {
5151export type ManagedIdentityUserAssignedIdQueryParameterNames =
5252 ( typeof ManagedIdentityUserAssignedIdQueryParameterNames ) [ keyof typeof ManagedIdentityUserAssignedIdQueryParameterNames ] ;
5353
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+ */
5462export abstract class BaseManagedIdentitySource {
5563 protected logger : Logger ;
5664 private nodeStorage : NodeStorage ;
5765 private networkClient : INetworkModule ;
5866 private cryptoProvider : CryptoProvider ;
5967 private disableInternalRetries : boolean ;
6068
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+ */
6178 constructor (
6279 logger : Logger ,
6380 nodeStorage : NodeStorage ,
@@ -72,11 +89,33 @@ export abstract class BaseManagedIdentitySource {
7289 this . disableInternalRetries = disableInternalRetries ;
7390 }
7491
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+ */
75102 abstract createRequest (
76- request : string ,
103+ resource : string ,
77104 managedIdentityId : ManagedIdentityId
78105 ) : ManagedIdentityRequestParameters ;
79106
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+ */
80119 public async getServerTokenResponseAsync (
81120 response : NetworkResponse < ManagedIdentityTokenResponse > ,
82121 // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -89,6 +128,15 @@ export abstract class BaseManagedIdentitySource {
89128 return this . getServerTokenResponse ( response ) ;
90129 }
91130
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+ */
92140 public getServerTokenResponse (
93141 response : NetworkResponse < ManagedIdentityTokenResponse >
94142 ) : ServerAuthorizationTokenResponse {
@@ -138,6 +186,21 @@ export abstract class BaseManagedIdentitySource {
138186 return serverTokenResponse ;
139187 }
140188
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+ */
141204 public async acquireTokenWithManagedIdentity (
142205 managedIdentityRequest : ManagedIdentityRequest ,
143206 managedIdentityId : ManagedIdentityId ,
@@ -253,6 +316,19 @@ export abstract class BaseManagedIdentitySource {
253316 ) ;
254317 }
255318
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+ */
256332 public getManagedIdentityUserAssignedIdQueryParameterKey (
257333 managedIdentityIdType : ManagedIdentityIdType ,
258334 isImds ?: boolean ,
@@ -290,6 +366,20 @@ export abstract class BaseManagedIdentitySource {
290366 }
291367 }
292368
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+ */
293383 public static getValidatedEnvVariableUrlString = (
294384 envVariableStringName : keyof typeof ManagedIdentityErrorCodes . MsiEnvironmentVariableUrlMalformedErrorCodes ,
295385 envVariable : string ,
0 commit comments