Class EnvironmentCredential | Azure SDK for .NET

Enables authentication to Azure Active Directory using client secret, or username and password, details configured in the following environment variables: Azure.Core.TokenCredential EnvironmentCredential

Enables authentication to Azure Active Directory using client secret, or username and password, details configured in the following environment variables:

VariableDescription
AZURE_TENANT_IDThe Azure Active Directory tenant(directory) ID.
AZURE_CLIENT_IDThe client(application) ID of an App Registration in the tenant.
AZURE_CLIENT_SECRETA client secret that was generated for the App Registration.
AZURE_CLIENT_CERTIFICATE_PATHA path to certificate and private key pair in PEM or PFX format, which can authenticate the App Registration.
AZURE_USERNAMEThe username, also known as upn, of an Azure Active Directory user account.
AZURE_PASSWORDThe password of the Azure Active Directory user account. Note this does not support accounts with MFA enabled.
This credential ultimately uses a ClientSecretCredential, ClientCertificateCredential, or UsernamePasswordCredential to perform the authentication using these details. Please consult the documentation of that class for more details.
Inheritance

Azure.Core.TokenCredential

EnvironmentCredential

Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Identity.dll
Syntax
public class EnvironmentCredential : Azure.Core.TokenCredential

Constructors

EnvironmentCredential()

Creates an instance of the EnvironmentCredential class and reads client secret details from environment variables. If the expected environment variables are not found at this time, the GetToken method will return the default Azure.Core.AccessToken when invoked.

Declaration
public EnvironmentCredential ();

EnvironmentCredential(TokenCredentialOptions)

Creates an instance of the EnvironmentCredential class and reads client secret details from environment variables. If the expected environment variables are not found at this time, the GetToken method will return the default Azure.Core.AccessToken when invoked.

Declaration
public EnvironmentCredential (Azure.Identity.TokenCredentialOptions options);
Parameters
TokenCredentialOptions options

Options that allow to configure the management of the requests sent to the Azure Active Directory service.

Methods

GetToken(TokenRequestContext, CancellationToken)

Obtains a token from the Azure Active Directory service, using the specified client details specified in the environment variables AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET or AZURE_USERNAME and AZURE_PASSWORD to authenticate. This method is called automatically by Azure SDK client libraries. You may call this method directly, but you must also handle token caching and token refreshing.

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.

GetTokenAsync(TokenRequestContext, CancellationToken)

Obtains a token from the Azure Active Directory service, using the specified client details specified in the environment variables AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET or AZURE_USERNAME and AZURE_PASSWORD to authenticate. This method is called automatically by Azure SDK client libraries. You may call this method directly, but you must also handle token caching and token refreshing.

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.

ncG1vNJzZmiZqqq%2Fpr%2FDpJuom6Njr627wWeaqKqVY8SqusOorqxmnprBcHDWnplonJ%2Bpu6bAjnqxrqqVY5alsc2toK2xX2Z7dnqPaJipoV92x7a%2BxGeAnZ2eqba1xY56sa6qlWOWpbHNraCtsV56u7e10ailpp2eqZCzscOepa2hkaF7qcDMpQ%3D%3D

 Share!