Skip to content

Commit 9c600fb

Browse files
scottaddiealexwolfmsftchristothes
authored
Update local dev accounts doc (#50129)
* Update local dev accounts doc * Update docs/azure/sdk/authentication/local-development-dev-accounts.md Co-authored-by: alexwolfmsft <93200798+alexwolfmsft@users.noreply.github.com> * React to feedback * Apply suggestions from code review Co-authored-by: Christopher Scott <chriscott@hotmail.com> * Update docs/azure/sdk/authentication/local-development-dev-accounts.md Co-authored-by: Christopher Scott <chriscott@hotmail.com> --------- Co-authored-by: alexwolfmsft <93200798+alexwolfmsft@users.noreply.github.com> Co-authored-by: Christopher Scott <chriscott@hotmail.com>
1 parent 7173eca commit 9c600fb

File tree

5 files changed

+58
-62
lines changed

5 files changed

+58
-62
lines changed

docs/azure/sdk/authentication/local-development-dev-accounts.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Authenticate .NET apps to Azure using developer accounts
33
description: Learn how to authenticate your application to Azure services when using the Azure SDK for .NET during local development using developer accounts.
44
ms.topic: how-to
5-
ms.date: 03/14/2025
5+
ms.date: 11/25/2025
66
ms.custom:
77
- devx-track-dotnet
88
- engagement-fy23
@@ -122,4 +122,36 @@ Connect-AzAccount -UseDeviceAuthentication
122122

123123
---
124124

125-
[!INCLUDE [Implement DefaultAzureCredential](<../includes/implement-defaultazurecredential.md>)]
125+
## Authenticate to Azure services from your app
126+
127+
The [Azure Identity library](/dotnet/api/azure.identity?view=azure-dotnet&preserve-view=true) provides implementations of <xref:Azure.Core.TokenCredential> that support various scenarios and Microsoft Entra authentication flows. The steps ahead demonstrate how to use <xref:Azure.Identity.DefaultAzureCredential> or a specific development tool credential when working with user accounts locally.
128+
129+
### Implement the code
130+
131+
Complete the following steps:
132+
133+
1. Add references to the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) and the [Microsoft.Extensions.Azure](https://www.nuget.org/packages/Microsoft.Extensions.Azure) packages in your project:
134+
135+
```dotnetcli
136+
dotnet add package Azure.Identity
137+
dotnet add package Microsoft.Extensions.Azure
138+
```
139+
140+
1. In `Program.cs`, add `using` directives for the `Azure.Identity` and `Microsoft.Extensions.Azure` namespaces.
141+
142+
1. Register the Azure service client using the corresponding `Add`-prefixed extension method.
143+
144+
Azure services are accessed using specialized client classes from the Azure SDK client libraries. Register these client types so you can access them through dependency injection across your app.
145+
146+
1. Pass a `TokenCredential` instance to the `UseCredential` method. Common `TokenCredential` examples include:
147+
148+
- A `DefaultAzureCredential` instance optimized for local development. This example sets environment variable `AZURE_TOKEN_CREDENTIALS` to `dev`. For more information, see [Exclude a credential type category](credential-chains.md#exclude-a-credential-type-category).
149+
150+
:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_DefaultAzureCredentialDev":::
151+
152+
- An instance of a credential corresponding to a specific development tool, such as `VisualStudioCredential`.
153+
154+
:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_VisualStudioCredential":::
155+
156+
> [!TIP]
157+
> When your team uses multiple development tools to authenticate with Azure, prefer a local development-optimized instance of `DefaultAzureCredential` over tool-specific credentials.

docs/azure/sdk/includes/implement-defaultazurecredential.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/azure/sdk/snippets/authentication/Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<PackageVersion Include="Azure.AI.OpenAI" Version="2.1.0" />
88
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
99
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
10-
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.13.0" />
11-
<PackageVersion Include="Azure.Identity" Version="1.17.0" />
12-
<PackageVersion Include="Azure.Identity.Broker" Version="1.3.0" />
10+
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.13.1" />
11+
<PackageVersion Include="Azure.Identity" Version="1.17.1" />
12+
<PackageVersion Include="Azure.Identity.Broker" Version="1.3.1" />
1313
<PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.8.0" />
1414
<PackageVersion Include="Azure.Storage.Blobs" Version="12.26.0" />
1515
<!-- ASP.NET Core packages -->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using Azure.Identity;
2-
using Microsoft.Extensions.Azure;
1+
using Microsoft.Extensions.Azure;
32
using Azure.Storage.Blobs;
4-
using Azure.Core;
3+
using Azure.Identity;
54

65
var builder = WebApplication.CreateBuilder(args);
76

8-
registerUsingServicePrincipal(builder);
7+
registerUsingUserPrincipal(builder);
98

109
var app = builder.Build();
1110

@@ -43,22 +42,30 @@
4342

4443
app.Run();
4544

46-
void registerUsingServicePrincipal(WebApplicationBuilder builder)
45+
void registerUsingUserPrincipal(WebApplicationBuilder builder)
4746
{
48-
#region snippet_DefaultAzureCredential_UseCredential
47+
#region snippet_VisualStudioCredential
4948
builder.Services.AddAzureClients(clientBuilder =>
5049
{
5150
clientBuilder.AddBlobServiceClient(
5251
new Uri("https://<account-name>.blob.core.windows.net"));
52+
53+
VisualStudioCredential credential = new();
54+
clientBuilder.UseCredential(credential);
5355
});
54-
#endregion snippet_DefaultAzureCredential_UseCredential
56+
#endregion snippet_VisualStudioCredential
5557

56-
#region snippet_DefaultAzureCredential
57-
builder.Services.AddSingleton<BlobServiceClient>(_ =>
58-
new BlobServiceClient(
59-
new Uri("https://<account-name>.blob.core.windows.net"),
60-
new DefaultAzureCredential()));
61-
#endregion snippet_DefaultAzureCredential
58+
#region snippet_DefaultAzureCredentialDev
59+
builder.Services.AddAzureClients(clientBuilder =>
60+
{
61+
clientBuilder.AddBlobServiceClient(
62+
new Uri("https://<account-name>.blob.core.windows.net"));
63+
64+
DefaultAzureCredential credential = new(
65+
DefaultAzureCredential.DefaultEnvironmentVariableName);
66+
clientBuilder.UseCredential(credential);
67+
});
68+
#endregion snippet_DefaultAzureCredentialDev
6269
}
6370

6471
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)

0 commit comments

Comments
 (0)