EnvironmentCredentialBuilder Class
- java.
lang. Object - com.
azure. identity. CredentialBuilderBase<T> - com.
azure. identity. EnvironmentCredentialBuilder
- com.
- com.
public class EnvironmentCredentialBuilder
extends CredentialBuilderBase<EnvironmentCredentialBuilder>
Fluent credential builder for instantiating a EnvironmentCredential.
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.
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();
Constructor Summary
Constructor | Description |
---|---|
EnvironmentCredentialBuilder() |
Constructs an instance of Environment |
Method Summary
Modifier and Type | Method and Description |
---|---|
Environment |
authorityHost(String authorityHost)
Specifies the Microsoft Entra endpoint to acquire tokens. |
Environment |
build()
Creates a new EnvironmentCredential with the current configurations. |
Environment |
executorService(ExecutorService executorService)
Specifies the Executor |
Methods inherited from CredentialBuilderBase
Methods inherited from java.lang.Object
Constructor Details
EnvironmentCredentialBuilder
public EnvironmentCredentialBuilder()
Constructs an instance of EnvironmentCredentialBuilder.
Method Details
authorityHost
public EnvironmentCredentialBuilder authorityHost(String authorityHost)
Specifies the Microsoft Entra endpoint to acquire tokens.
Parameters:
Returns:
build
public EnvironmentCredential build()
Creates a new EnvironmentCredential with the current configurations.
Returns:
executorService
public EnvironmentCredentialBuilder executorService(ExecutorService executorService)
Specifies the ExecutorService to be used to execute the authentication requests. Developer is responsible for maintaining the lifecycle of the ExecutorService.
If this is not configured, the ForkJoinPool#commonPool() will be used which is also shared with other application tasks. If the common pool is heavily used for other tasks, authentication requests might starve and setting up this executor service should be considered.
The executor service and can be safely shutdown if the TokenCredential is no longer being used by the Azure SDK clients and should be shutdown before the application exits.
Parameters:
Returns:
Applies to
Azure SDK for Java