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/python/sdk/authentication/credential-chains.md
+31-8Lines changed: 31 additions & 8 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 Python
3
3
description: This article describes the DefaultAzureCredential and ChainedTokenCredential classes in the Azure Identity client library.
4
-
ms.date: 06/02/2025
4
+
ms.date: 08/06/2025
5
5
ms.topic: article
6
6
ms.custom: devx-track-python
7
7
---
@@ -44,7 +44,7 @@ There are two disparate philosophies to credential chaining:
44
44
45
45
[DefaultAzureCredential](/python/api/azure-identity/azure.identity.defaultazurecredential) is an opinionated, preconfigured chain of credentials. It's designed to support many environments, along with the most common authentication flows and developer tools. In graphical form, the underlying chain looks like this:
46
46
47
-
:::image type="content"source="../media/mermaidjs/default-azure-credential-auth-flow.svg" alt-text="Diagram that shows DefaultAzureCredential authentication flow."lightbox="../media/mermaidjs/default-azure-credential-auth-flow-big.png":::
47
+
:::image type="content"source="../media/mermaidjs/default-azure-credential-authentication-flow-inline.svg" alt-text="Diagram that shows DefaultAzureCredential authentication flow."lightbox="../media/mermaidjs/default-azure-credential-authentication-flow-expanded.png":::
48
48
49
49
The order in which `DefaultAzureCredential` attempts credentials follows.
50
50
@@ -54,19 +54,24 @@ The order in which `DefaultAzureCredential` attempts credentials follows.
54
54
|2| [Workload Identity][wi-cred] | If the app is deployed to an Azure host with Workload Identity enabled, authenticate that account. | Yes |
55
55
|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. | Yes |
56
56
|4| [Shared Token Cache][vs-cred] | On Windows only, if the developer authenticated to Azure by logging into Visual Studio, authenticate the app to Azure using that same account. | Yes |
57
-
|5| [Azure CLI][az-cred] | If the developer authenticated to Azure using Azure CLI's `az login` command, authenticate the app to Azure using that same account. | Yes |
58
-
|6| [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. | Yes |
59
-
|7| [Azure Developer CLI][azd-cred] | If the developer authenticated to Azure using Azure Developer CLI's `azd auth login` command, authenticate with that account. | Yes |
60
-
|8| [Interactive browser][int-cred] | If enabled, interactively authenticate the developer via the current system's default browser. | No |
57
+
|5| [Visual Studio Code][vsc-cred] | If the developer authenticated via Visual Studio Code's [Azure Resources extension][vsc-ext] and the [azure-identity-broker package][broker-pkg] is installed, authenticate that account. | Yes |
58
+
|6| [Azure CLI][az-cred] | If the developer authenticated to Azure using Azure CLI's `az login` command, authenticate the app to Azure using that same account. | Yes |
59
+
|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. | Yes |
60
+
|8| [Azure Developer CLI][azd-cred] | If the developer authenticated to Azure using Azure Developer CLI's `azd auth login` command, authenticate with that account. | Yes |
61
+
|9| [Interactive browser][int-cred] | If enabled, interactively authenticate the developer via the current system's default browser. | No |
62
+
|10| [Broker][int-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 an instance of `InteractiveBrowserBrokerCredential`is used. | Yes |
@@ -145,6 +152,22 @@ When a value of `dev` is used, the chain looks as follows:
145
152
> [!IMPORTANT]
146
153
> The `AZURE_TOKEN_CREDENTIALS` environment variable is supported in`azure-identity` package versions 1.23.0 and later.
147
154
155
+
#### Use a specific credential
156
+
157
+
To exclude all credentials exceptfor 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:
158
+
159
+
-`AzureCliCredential`
160
+
-`AzureDeveloperCliCredential`
161
+
-`AzurePowerShellCredential`
162
+
-`EnvironmentCredential`
163
+
-`InteractiveBrowserCredential`
164
+
-`ManagedIdentityCredential`
165
+
-`VisualStudioCodeCredential`
166
+
-`WorkloadIdentityCredential`
167
+
168
+
> [!IMPORTANT]
169
+
> The `AZURE_TOKEN_CREDENTIALS` environment variable supports individual credential names in`azure-identity` package versions 1.24.0 and later.
170
+
148
171
## ChainedTokenCredential overview
149
172
150
173
[ChainedTokenCredential](/python/api/azure-identity/azure.identity.chainedtokencredential) is an empty chain to which you add credentials to suit your app's needs. For example:
The preceding code sample creates a tailored credential chain comprised of two development-time credentials. `AzureCliCredential`is attempted first, followed by `AzureDeveloperCliCredential`, if necessary. In graphical form, the chain looks like this:
160
183
161
-
:::image type="content"source="../media/mermaidjs/chained-token-credential-auth-flow.svg" alt-text="Diagram that shows authentication flow for a ChainedTokenCredential instance that is composed of Azure CLI and Azure Developer CLI credentials.":::
184
+
:::image type="content"source="../media/mermaidjs/chained-token-credential-authentication-flow.svg" alt-text="Diagram that shows authentication flow for a ChainedTokenCredential instance that is composed of Azure CLI and Azure Developer CLI credentials.":::
162
185
163
186
> [!TIP]
164
187
> For improved performance, optimize credential ordering in`ChainedTokenCredential`from most to least used credential.
0 commit comments