Class ManagedIdentityCredential
Attempts authentication using a managed identity that has been assigned to the deployment environment.This authentication type works in Azure VMs, App Service and Azure Functions applications, as well as inside of Azure Cloud Shell. More information about configuring managed identities can be found here: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
Namespace: Azure.Identity
Assembly: Azure.Identity.dll
Syntax
public class ManagedIdentityCredential : Azure.Core.TokenCredential
Constructors
ManagedIdentityCredential()
Protected constructor for mocking.
Declaration
protected ManagedIdentityCredential ();
ManagedIdentityCredential(String, TokenCredentialOptions)
Creates an instance of the ManagedIdentityCredential capable of authenticating a resource with a managed identity.
Declaration
public ManagedIdentityCredential (string clientId = null, Azure.Identity.TokenCredentialOptions options = null);
Parameters
String
clientId
The client id to authenticate for a user assigned managed identity. More information on user assigned managed identities cam be found here: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview#how-a-user-assigned-managed-identity-works-with-an-azure-vm |
TokenCredentialOptions
options
Options that allow to configure the management of the requests sent to the Azure Active Directory service. |
Methods
GetToken(TokenRequestContext, CancellationToken)
Obtains an AccessToken from the Managed Identity service if available. This method is called by Azure SDK clients. It isn't intended for use in application code.
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. |
CancellationToken
cancellationToken
A CancellationToken controlling the request lifetime. |
Returns
AccessToken
An AccessToken which can be used to authenticate service client calls, or a default AccessToken if no managed identity is available. |
GetTokenAsync(TokenRequestContext, CancellationToken)
Obtains an AccessToken from the Managed Identity service if available. This method is called by Azure SDK clients. It isn't intended for use in application code.
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. |
CancellationToken
cancellationToken
A CancellationToken controlling the request lifetime. |
Returns
ValueTask<AccessToken>
An AccessToken which can be used to authenticate service client calls, or a default AccessToken if no managed identity is available. |