你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

EnvironmentCredential Class

  • java.lang.Object
    • com.azure.identity.EnvironmentCredential

Implements

public class EnvironmentCredential
implements 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 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();

Methods inherited from java.lang.Object

Method Details

getToken

public Mono getToken(TokenRequestContext request)

Parameters:

request

getTokenSync

public AccessToken getTokenSync(TokenRequestContext request)

Parameters:

request

Applies to