You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/java/sdk/authentication/credential-chains.md
+29-6Lines changed: 29 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: 'Credential chains in the Azure Identity library for Java'
3
3
description: 'This article describes the DefaultAzureCredential and ChainedTokenCredential classes in the Azure Identity library.'
4
-
ms.date: 06/02/2025
4
+
ms.date: 08/05/2025
5
5
ms.topic: article
6
6
author: KarlErickson
7
7
ms.author: karler
@@ -70,20 +70,24 @@ The order in which `DefaultAzureCredential` attempts credentials follows.
70
70
| 1 | [Environment][env-cred] | Reads a collection of [environment variables][env-vars] to determine if an application service principal (application user) is configured for the app. If so, `DefaultAzureCredential` uses these values to authenticate the app to Azure. This method is most often used in server environments but can also be used when developing locally. |
71
71
| 2 | [Workload Identity][wi-cred] | If the app is deployed to an Azure host with Workload Identity enabled, authenticate that account. |
72
72
| 3 | [Managed Identity][mi-cred] | If the app is deployed to an Azure host with Managed Identity enabled, authenticate the app to Azure using that Managed Identity. |
73
-
| 4 | [Shared Token Cache][stc-cred] | If the developer authenticated to Azure by logging into Visual Studio, authenticate the app to Azure using that same account. (Windows only.) |
74
-
| 5 | [IntelliJ][ij-cred] | If the developer authenticated via Azure Toolkit for IntelliJ, authenticate that account. |
73
+
| 4 | [IntelliJ][ij-cred] | If the developer authenticated via Azure Toolkit for IntelliJ, authenticate that account. |
74
+
| 5 | [Visual Studio Code][vsc-cred] | If the developer authenticated via Visual Studio Code's [AzureResources extension][vsc-ext] and the [azure-identity-broker package][broker-pkg] is installed, authenticate that account.|
75
75
|6| [AzureCLI][az-cred] |If the developer authenticated to Azure using AzureCLI's `az login` command, authenticate the app to Azure using that same account. |
76
76
| 7 | [Azure PowerShell][pwsh-cred] | If the developer authenticated to Azure using Azure PowerShell's `Connect-AzAccount` cmdlet, authenticate the app to Azure using that same account. |
77
77
|8| [AzureDeveloperCLI][azd-cred] |If the developer authenticated to Azure using AzureDeveloperCLI's `azd auth login` command, authenticate with that account. |
78
+
| 9 | [Broker][broker-cred] | Authenticates using the default account logged into the OS via a broker. Requires that the [azure-identity-broker package][broker-pkg] is installed, since a broker-enabled instance of `InteractiveBrowserCredential` is used. |
In its simplest form, you can use the parameterless version of `DefaultAzureCredential` as follows:
89
93
@@ -99,6 +103,10 @@ DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
99
103
100
104
### How to customize DefaultAzureCredential
101
105
106
+
The following sections describe strategies for controlling which credentials are included in the chain.
107
+
108
+
#### Exclude a credential type category
109
+
102
110
To exclude all `Developer tool` or `Deployed service` credentials, set environment variable `AZURE_TOKEN_CREDENTIALS` to `prod` or `dev`, respectively. When a value of `prod` is used, the underlying credential chain looks as follows:
103
111
104
112
:::image type="content" source="../media/mermaidjs/default-azure-credential-environment-variable-production.svg" alt-text="Diagram that shows DefaultAzureCredential with AZURE_TOKEN_CREDENTIALS set to 'prod'.":::
@@ -110,6 +118,22 @@ When a value of `dev` is used, the chain looks as follows:
110
118
> [!IMPORTANT]
111
119
> The `AZURE_TOKEN_CREDENTIALS` environment variable is supported in `azure-identity` package versions 1.16.1 and later.
112
120
121
+
#### Use a specific credential
122
+
123
+
To exclude all credentials except for one, set environment variable `AZURE_TOKEN_CREDENTIALS` to the credential name. For example, you can reduce the `DefaultAzureCredential` chain to `AzureCliCredential` by setting `AZURE_TOKEN_CREDENTIALS` to `AzureCliCredential`. The string comparison is performed in a case-insensitive manner. Valid string values for the environment variable include:
124
+
125
+
- `AzureCliCredential`
126
+
- `AzureDeveloperCliCredential`
127
+
- `AzurePowerShellCredential`
128
+
- `EnvironmentCredential`
129
+
- `IntelliJCredential`
130
+
- `ManagedIdentityCredential`
131
+
- `VisualStudioCodeCredential`
132
+
- `WorkloadIdentityCredential`
133
+
134
+
> [!IMPORTANT]
135
+
> The `AZURE_TOKEN_CREDENTIALS` environment variable supports individual credential names in `azure-identity` package versions 1.17.0 and later.
136
+
113
137
## ChainedTokenCredential overview
114
138
115
139
[ChainedTokenCredential](/java/api/com.azure.identity.chainedtokencredential) is an empty chain to which you add credentials to suit your app's needs. For example:
@@ -163,14 +187,13 @@ For illustration purposes, assume the parameterless form of `DefaultAzureCredent
163
187
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential WorkloadIdentityCredential is unavailable.
164
188
[ForkJoinPool.commonPool-worker-1] WARN com.microsoft.aad.msal4j.ConfidentialClientApplication - [Correlation ID: aaaa0000-bb11-2222-33cc-444444dddddd] Execution of class com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier failed: java.util.concurrent.ExecutionException: com.azure.identity.CredentialUnavailableException: ManagedIdentityCredential authentication unavailable. Connection to IMDS endpoint cannot be established.
165
189
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential ManagedIdentityCredential is unavailable.
166
-
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential SharedTokenCacheCredential is unavailable.
167
190
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential IntelliJCredential is unavailable.
168
191
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential AzureCliCredential returns a token
169
192
```
170
193
171
194
In the preceding output, notice that:
172
195
173
-
-`EnvironmentCredential`, `WorkloadIdentityCredential`, `ManagedIdentityCredential`, `SharedTokenCacheCredential`, and `IntelliJCredential` each failed to acquire a Microsoft Entra access token, in that order.
196
+
-`EnvironmentCredential`, `WorkloadIdentityCredential`, `ManagedIdentityCredential`, and `IntelliJCredential` each failed to acquire a Microsoft Entra access token, in that order.
174
197
- The `AzureCliCredential.getToken` call succeeds, as indicated by the `returns a token`-suffixed entry. Since `AzureCliCredential` succeeded, no credentials beyond it were tried.
0 commit comments