Class ManagedIdentityCredential
Attempts authentication using a managed identity that has been assigned to the deployment environment. This authentication type works for all Azure-hosted environments that support managed identity. More information about configuring managed identities can be found at .
Inheritance
Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Identity.dll
Syntax
public class ManagedIdentityCredential : Azure.Core.TokenCredential
Constructors
ManagedIdentityCredential()
ManagedIdentityCredential(ManagedIdentityCredentialOptions)
Creates an instance of ManagedIdentityCredential configured with the specified options.
Declaration
public ManagedIdentityCredential (Azure.Identity.ManagedIdentityCredentialOptions options);
Parameters
ManagedIdentityCredentialOptions
options
The options used to configure the credential. |
ManagedIdentityCredential(ManagedIdentityId)
Creates an instance of ManagedIdentityCredential capable of authenticating using the specified ManagedIdentityId.
Declaration
public ManagedIdentityCredential (Azure.Identity.ManagedIdentityId id);
Parameters
ManagedIdentityId
id
The ManagedIdentityId specifying which managed identity will be configured. |
ManagedIdentityCredential(ResourceIdentifier, TokenCredentialOptions)
Creates an instance of ManagedIdentityCredential capable of authenticating a resource with a user-assigned managed identity.
Declaration
[System.ComponentModel.EditorBrowsable]
public ManagedIdentityCredential (Azure.Core.ResourceIdentifier resourceId, Azure.Identity.TokenCredentialOptions options = null);
Parameters
Azure.Core.ResourceIdentifier
resourceId
The resource ID to authenticate for a user-assigned managed identity. |
TokenCredentialOptions
options
Options to configure the management of the requests sent to Microsoft Entra ID. |
ManagedIdentityCredential(String, TokenCredentialOptions)
Creates an instance of ManagedIdentityCredential capable of authenticating a resource with a user-assigned or a system-assigned managed identity.
Declaration
[System.ComponentModel.EditorBrowsable]
public ManagedIdentityCredential (string clientId = null, Azure.Identity.TokenCredentialOptions options = null);
Parameters
System.String
clientId
The client ID to authenticate for a user-assigned managed identity. If not provided, a system-assigned managed identity is used. |
TokenCredentialOptions
options
Options to configure the management of the requests sent to Microsoft Entra ID. |
Methods
GetToken(TokenRequestContext, CancellationToken)
Obtains an Azure.Core.AccessToken from the Managed Identity service, if available. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
Declaration
public override Azure.Core.AccessToken GetToken (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken controlling the request lifetime. |
Returns
Azure.Core.AccessToken
An Azure.Core.AccessToken which can be used to authenticate service client calls, or a default Azure.Core.AccessToken if no managed identity is available. |
Exceptions
AuthenticationFailedException
Thrown when the authentication failed. |
GetTokenAsync(TokenRequestContext, CancellationToken)
Obtains an Azure.Core.AccessToken from the Managed Identity service, if available. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public override System.Threading.Tasks.ValueTask<Azure.Core.AccessToken> GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken controlling the request lifetime. |
Returns
System.Threading.Tasks.ValueTask<Azure.Core.AccessToken>
An Azure.Core.AccessToken which can be used to authenticate service client calls, or a default Azure.Core.AccessToken if no managed identity is available. |
Exceptions
AuthenticationFailedException
Thrown when the authentication failed. |