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: docs/azure/sdk/authentication/credential-chains.md
+35-12Lines changed: 35 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: 'Credential chains in the Azure Identity library for .NET'
3
3
description: 'This article describes the DefaultAzureCredential and ChainedTokenCredential classes in the Azure Identity library.'
4
4
ms.topic: concept-article
5
-
ms.date: 05/30/2025
5
+
ms.date: 08/13/2025
6
6
---
7
7
8
8
# Credential chains in the Azure Identity library for .NET
@@ -13,7 +13,7 @@ The Azure Identity library provides *credentials*—public classes derived f
13
13
14
14
At runtime, a credential chain attempts to authenticate using the sequence's first credential. If that credential fails to acquire an access token, the next credential in the sequence is attempted, and so on, until an access token is successfully obtained. The following sequence diagram illustrates this behavior:
@@ -37,7 +37,7 @@ There are two disparate philosophies to credential chaining:
37
37
38
38
[DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet&preserve-view=true) 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:
:::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":::
41
41
42
42
The order in which `DefaultAzureCredential` attempts credentials follows.
43
43
@@ -47,19 +47,24 @@ The order in which `DefaultAzureCredential` attempts credentials follows.
47
47
| 2 |[Workload Identity][wi-cred]|If the app is deployed to an Azure host with Workload Identity enabled, authenticate that account. | Yes |
48
48
| 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 |
49
49
| 4 |[Visual Studio][vs-cred]|If the developer authenticated to Azure by logging into Visual Studio, authenticate the app to Azure using that same account. | Yes |
50
-
| 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 |
51
-
| 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 |
52
-
| 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 |
53
-
| 8 |[Interactive browser][int-cred]|If enabled, interactively authenticate the developer via the current system's default browser. | No |
50
+
| 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 |
51
+
| 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 |
52
+
| 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 |
53
+
| 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 |
54
+
| 9 |[Interactive browser][int-cred]|If enabled, interactively authenticate the developer via the current system's default browser. | No |
55
+
| 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. | Yes |
In its simplest form, you can use the parameterless version of `DefaultAzureCredential` as follows:
65
70
@@ -70,7 +75,7 @@ In its simplest form, you can use the parameterless version of `DefaultAzureCred
70
75
71
76
### How to customize DefaultAzureCredential
72
77
73
-
The following sections describe strategies for omitting credentials from the chain.
78
+
The following sections describe strategies for controlling which credentials are included in the chain.
74
79
75
80
#### Exclude an individual credential
76
81
@@ -80,7 +85,7 @@ To exclude an individual credential from `DefaultAzureCredential`, use the corre
80
85
81
86
In the preceding code sample, `EnvironmentCredential`, `ManagedIdentityCredential`, and `WorkloadIdentityCredential` are removed from the credential chain. As a result, the first credential to be attempted is `VisualStudioCredential`. The modified chain contains only development-time credentials and looks like this:
82
87
83
-
:::image type="content" source="../media/mermaidjs/DefaultAzureCredentialExcludes.svg" alt-text="DefaultAzureCredential using Excludes properties":::
88
+
:::image type="content" source="../media/mermaidjs/default-azure-credential-excludes.svg" alt-text="DefaultAzureCredential using Excludes properties":::
84
89
85
90
> [!NOTE]
86
91
> `InteractiveBrowserCredential` is excluded by default and therefore isn't shown in the preceding diagram. To include `InteractiveBrowserCredential`, either pass `true` to constructor <xref:Azure.Identity.DefaultAzureCredential.%23ctor%28System.Boolean%29> or set property <xref:Azure.Identity.DefaultAzureCredentialOptions.ExcludeInteractiveBrowserCredential%2A?displayProperty=nameWithType> to `false`.
@@ -101,15 +106,33 @@ As more `Exclude`-prefixed properties are set to `true` (credential exclusions a
101
106
102
107
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
108
104
-
:::image type="content" source="../media/mermaidjs/DefaultAzureCredentialEnvVarProd.svg" alt-text="DefaultAzureCredential with AZURE_TOKEN_CREDENTIALS set to 'prod'":::
109
+
:::image type="content" source="../media/mermaidjs/default-azure-credential-environment-variable-production.svg" alt-text="DefaultAzureCredential with AZURE_TOKEN_CREDENTIALS set to 'prod'":::
105
110
106
111
When a value of `dev` is used, the chain looks as follows:
107
112
108
-
:::image type="content" source="../media/mermaidjs/DefaultAzureCredentialEnvVarDev.svg" alt-text="DefaultAzureCredential with AZURE_TOKEN_CREDENTIALS set to 'dev'":::
113
+
:::image type="content" source="../media/mermaidjs/default-azure-credential-environment-variable-development.svg" alt-text="DefaultAzureCredential with AZURE_TOKEN_CREDENTIALS set to 'dev'":::
109
114
110
115
> [!IMPORTANT]
111
116
> The `AZURE_TOKEN_CREDENTIALS` environment variable is supported in `Azure.Identity` package versions 1.14.0 and later.
112
117
118
+
#### Use a specific credential
119
+
120
+
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 `VisualStudioCredential` by setting `AZURE_TOKEN_CREDENTIALS` to `VisualStudioCredential`. The string comparison is performed in a case-insensitive manner. Valid string values for the environment variable include:
121
+
122
+
-`AzureCliCredential`
123
+
-`AzureDeveloperCliCredential`
124
+
-`AzurePowerShellCredential`
125
+
-`BrokerCredential`
126
+
-`EnvironmentCredential`
127
+
-`InteractiveBrowserCredential`
128
+
-`ManagedIdentityCredential`
129
+
-`VisualStudioCredential`
130
+
-`VisualStudioCodeCredential`
131
+
-`WorkloadIdentityCredential`
132
+
133
+
> [!IMPORTANT]
134
+
> The `AZURE_TOKEN_CREDENTIALS` environment variable supports individual credential names in `Azure.Identity` package versions 1.15.0 and later.
135
+
113
136
## ChainedTokenCredential overview
114
137
115
138
[ChainedTokenCredential](/dotnet/api/azure.identity.chainedtokencredential?view=azure-dotnet&preserve-view=true) is an empty chain to which you add credentials to suit your app's needs. For example:
@@ -118,7 +141,7 @@ When a value of `dev` is used, the chain looks as follows:
118
141
119
142
The preceding code sample creates a tailored credential chain comprised of two development-time credentials. `AzurePowerShellCredential` is attempted first, followed by `VisualStudioCredential`, if necessary. In graphical form, the chain looks like this:
0 commit comments