Class EnvironmentCredential

java.lang.Object
com.azure.identity.EnvironmentCredential
All Implemented Interfaces:
com.azure.core.credential.TokenCredential

public class EnvironmentCredential extends Object implements com.azure.core.credential.TokenCredential

The EnvironmentCredential is appropriate for scenarios where the application is looking to read credential information from environment variables. The credential supports service principal and user credential based authentication and requires a set of environment variables to be configured for each scenario.

The required environment variables for service principal authentication using client secret are as follows:

  • AZURE_CLIENT_ID
  • AZURE_CLIENT_SECRET
  • AZURE_TENANT_ID

The required environment variables for service principal authentication using client certificate are as follows:

  • AZURE_CLIENT_ID
  • AZURE_CLIENT_CERTIFICATE_PATH
  • AZURE_CLIENT_CERTIFICATE_PASSWORD
  • AZURE_TENANT_ID

The required environment variables for username password authentication are as follows:

  • AZURE_CLIENT_ID
  • AZURE_USERNAME
  • AZURE_PASSWORD
  • AZURE_TENANT_ID

The credential looks for authentication scenarios in the order above, so ensure that only targeted authentication scenario's environment variables are configured.

Sample: Construct EnvironmentCredential

The following code sample demonstrates the creation of a EnvironmentCredential, using the EnvironmentCredentialBuilder to configure it. Once this credential is created, it may be passed into the builder of many of the Azure SDK for Java client builders as the 'credential' parameter.

 TokenCredential environmentCredential = new EnvironmentCredentialBuilder()
     .build();
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Mono<com.azure.core.credential.AccessToken>
    getToken(com.azure.core.credential.TokenRequestContext request)
    Asynchronously get a token for a given resource/audience.
    com.azure.core.credential.AccessToken
    getTokenSync(com.azure.core.credential.TokenRequestContext request)
    Synchronously get a token for a given resource/audience.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getToken

      public Mono<com.azure.core.credential.AccessToken> getToken(com.azure.core.credential.TokenRequestContext request)
      Description copied from interface: com.azure.core.credential.TokenCredential
      Asynchronously get a token for a given resource/audience. 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.
      Specified by:
      getToken in interface com.azure.core.credential.TokenCredential
      Parameters:
      request - the details of the token request
      Returns:
      a Publisher that emits a single access token
    • getTokenSync

      public com.azure.core.credential.AccessToken getTokenSync(com.azure.core.credential.TokenRequestContext request)
      Description copied from interface: com.azure.core.credential.TokenCredential
      Synchronously get a token for a given resource/audience. 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.
      Specified by:
      getTokenSync in interface com.azure.core.credential.TokenCredential
      Parameters:
      request - the details of the token request
      Returns:
      The Access Token