Skip to content

Commit bd62ba6

Browse files
committed
React to feedback
1 parent 9dafb48 commit bd62ba6

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
ms.topic: include
3-
ms.date: 07/25/2025
3+
ms.date: 08/01/2025
44
---
55

66
## Authenticate to Azure services from your app
@@ -11,29 +11,30 @@ The [Azure Identity library](/dotnet/api/azure.identity?view=azure-dotnet&preser
1111

1212
[DefaultAzureCredential](../authentication/credential-chains.md#defaultazurecredential-overview) is an opinionated, ordered sequence of mechanisms for authenticating to Microsoft Entra ID. Each authentication mechanism is a class derived from the [TokenCredential](/dotnet/api/azure.core.tokencredential?view=azure-dotnet&preserve-view=true) class and is known as a *credential*. At runtime, `DefaultAzureCredential` attempts to authenticate using the 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. In this way, your app can use different credentials in different environments without writing environment-specific code.
1313

14-
To use `DefaultAzureCredential`, add the [Azure.Identity](/dotnet/api/azure.identity) and optionally the [Microsoft.Extensions.Azure](/dotnet/api/microsoft.extensions.azure) packages to your application:
14+
To use `DefaultAzureCredential`:
1515

16-
### [Command Line](#tab/command-line)
16+
1. Add the [Microsoft.Extensions.Azure](/dotnet/api/microsoft.extensions.azure) package to your application:
1717

18-
In a terminal of your choice, navigate to the application project directory and run the following commands:
18+
```dotnetcli
19+
dotnet add package Microsoft.Extensions.Azure
20+
```
1921
20-
```dotnetcli
21-
dotnet add package Azure.Identity
22-
dotnet add package Microsoft.Extensions.Azure
23-
```
22+
1. Azure services are accessed using specialized client classes from the various Azure SDK client libraries. These classes and your own custom services should be registered so they can be accessed via dependency injection throughout your app. In `Program.cs`, complete the following steps to register a client class and `DefaultAzureCredential`:
2423
25-
### [NuGet Package Manager](#tab/nuget-package)
24+
1. Include the `Microsoft.Extensions.Azure` namespace via a `using` directive.
25+
1. Register the Azure service client using the corresponding `Add`-prefixed extension method.
2626
27-
Right-click your project in Visual Studio's **Solution Explorer** window and select **Manage NuGet Packages**. Search for **Azure.Identity**, and install the matching package. Repeat this process for the **Microsoft.Extensions.Azure** package.
27+
:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_DefaultAzureCredential":::
2828
29-
:::image type="content" source="../media/nuget-azure-identity.png" alt-text="Install a package using the package manager.":::
29+
By default, the client builder creates a `DefaultAzureCredential` instance on your behalf. For production usage, register a [deterministic credential](../authentication/best-practices.md#use-deterministic-credentials-in-production-environments) instance with the builder instead of using `DefaultAzureCredential`. To use a different credential for Azure SDK clients:
3030
31-
---
31+
1. Add the [Azure.Identity](/dotnet/api/azure.identity) package to your application:
3232
33-
Azure services are accessed using specialized client classes from the various Azure SDK client libraries. These classes and your own custom services should be registered so they can be accessed via dependency injection throughout your app. In `Program.cs`, complete the following steps to register a client class and `DefaultAzureCredential`:
33+
```dotnetcli
34+
dotnet add package Azure.Identity
35+
```
3436
35-
1. Include the `Azure.Identity` and `Microsoft.Extensions.Azure` namespaces via `using` directives.
36-
1. Register the Azure service client using the corresponding `Add`-prefixed extension method.
37-
1. Pass an instance of `DefaultAzureCredential` to the `UseCredential` method.
37+
1. Include the `Azure.Identity` namespace via a `using` directive.
38+
1. Register a custom credential instance with the builder. For example:
3839
39-
:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_DefaultAzureCredential_UseCredential":::
40+
:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_DefaultAzureCredential_UseCredential" highlight="6":::
-77.9 KB
Binary file not shown.

docs/azure/sdk/snippets/authentication/local-dev-account/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@
4444

4545
void registerUsingServicePrincipal(WebApplicationBuilder builder)
4646
{
47+
#region snippet_DefaultAzureCredential
48+
builder.Services.AddAzureClients(clientBuilder =>
49+
{
50+
clientBuilder.AddBlobServiceClient(
51+
new Uri("https://<account-name>.blob.core.windows.net"));
52+
});
53+
#endregion snippet_DefaultAzureCredential
54+
4755
#region snippet_DefaultAzureCredential_UseCredential
4856
builder.Services.AddAzureClients(clientBuilder =>
4957
{
5058
clientBuilder.AddBlobServiceClient(
5159
new Uri("https://<account-name>.blob.core.windows.net"));
5260

53-
clientBuilder.UseCredential(new DefaultAzureCredential());
61+
clientBuilder.UseCredential(new AzureCliCredential());
5462
});
5563
#endregion snippet_DefaultAzureCredential_UseCredential
5664
}

0 commit comments

Comments
 (0)