Class AzureDeveloperCliCredential
- All Implemented Interfaces:
com.azure.core.credential.TokenCredential
Azure Developer CLI is a command-line interface tool that allows developers to create, manage, and deploy resources in Azure. It's built on top of the Azure CLI and provides additional functionality specific to Azure developers. It allows users to authenticate as a user and/or a service principal against Microsoft Entra ID. The AzureDeveloperCliCredential authenticates in a development environment and acquires a token on behalf of the logged-in user or service principal in Azure Developer CLI. It acts as the Azure Developer CLI logged in user or service principal and executes an Azure CLI command underneath to authenticate the application against Microsoft Entra ID.
Configure AzureDeveloperCliCredential
To use this credential, the developer needs to authenticate locally in Azure Developer CLI using one of the commands below:
- Run "azd auth login" in Azure Developer CLI to authenticate interactively as a user.
- Run "azd auth login --client-id
clientID
--client-secretclientSecret
--tenant-idtenantID
" to authenticate as a service principal.
You may need to repeat this process after a certain time period, depending on the refresh token validity in your organization. Generally, the refresh token validity period is a few weeks to a few months. AzureDeveloperCliCredential will prompt you to sign in again.
Sample: Construct AzureDeveloperCliCredential
The following code sample demonstrates the creation of a AzureDeveloperCliCredential
,
using the AzureDeveloperCliCredentialBuilder
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 azureDevCliCredential = new AzureDeveloperCliCredentialBuilder() .build();
-
Method Summary
Modifier and TypeMethodDescriptionMono<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.
-
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 interfacecom.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 interfacecom.azure.core.credential.TokenCredential
- Parameters:
request
- the details of the token request- Returns:
- The Access Token
-