![]() |
VOOZH | about |
dotnet add package Azure.Identity --version 1.21.0
NuGet\Install-Package Azure.Identity -Version 1.21.0
<PackageReference Include="Azure.Identity" Version="1.21.0" />
<PackageVersion Include="Azure.Identity" Version="1.21.0" />Directory.Packages.props
<PackageReference Include="Azure.Identity" />Project file
paket add Azure.Identity --version 1.21.0
#r "nuget: Azure.Identity, 1.21.0"
#:package Azure.Identity@1.21.0
#addin nuget:?package=Azure.Identity&version=1.21.0Install as a Cake Addin
#tool nuget:?package=Azure.Identity&version=1.21.0Install as a Cake Tool
The Azure Identity library provides Microsoft Entra ID token-based authentication support across the Azure SDK. It provides a set of TokenCredential implementations that can be used to construct Azure SDK clients that support Microsoft Entra token authentication.
Source code | Package (NuGet) | API reference documentation | Microsoft Entra ID documentation
Install the Azure Identity client library for .NET with NuGet:
dotnet add package Azure.Identity
When debugging and executing code locally, it's typical for a developer to use their own account for authenticating calls to Azure services. There are several developer tools that can be used to perform this authentication in your development environment. For more information, see Authentication during local development.
A credential is a class that contains or can obtain the data needed for a service client to authenticate requests. Service clients across the Azure SDK accept credentials when they're constructed. Service clients use those credentials to authenticate requests to the service.
The Azure Identity library focuses on OAuth authentication with Microsoft Entra ID. It offers numerous credentials capable of acquiring a Microsoft Entra token to authenticate service requests. Each credential in this library is an implementation of the TokenCredential abstract class in Azure.Core, and any of them can be used to construct service clients capable of authenticating with a TokenCredential.
See Credential classes for a complete listing of available credential types.
DefaultAzureCredential simplifies authentication while developing apps that deploy to Azure by combining credentials used in Azure hosting environments with credentials used in local development. For more information, see DefaultAzureCredential overview.
As of version 1.10.1, DefaultAzureCredential attempts to authenticate with all developer tool credentials until one succeeds, regardless of any errors previous developer tool credentials experienced. For example, a developer tool credential may attempt to get a token and fail, so DefaultAzureCredential will continue to the next credential in the flow. Deployed service credentials stop the flow with a thrown exception if they're able to attempt token retrieval but don't receive one. Prior to version 1.10.1, developer tool credentials would similarly stop the authentication flow if token retrieval failed.
This behavior allows for trying all of the developer tool credentials on your machine while having predictable deployed behavior.
DefaultAzureCredentialMany Azure hosts allow the assignment of a user-assigned managed identity. The following examples demonstrate configuring DefaultAzureCredential to authenticate a user-assigned managed identity when deployed to an Azure host. The sample code uses the credential to authenticate a BlobClient from the Azure.Storage.Blobs client library. It also demonstrates how you can specify a user-assigned managed identity either by a client ID or a resource ID.
To use a client ID, take one of the following approaches:
// When deployed to an Azure host, DefaultAzureCredential will authenticate the specified user-assigned managed identity.
string userAssignedClientId = "<your managed identity client ID>";
var credential = new DefaultAzureCredential(
new DefaultAzureCredentialOptions
{
ManagedIdentityClientId = userAssignedClientId
});
var blobClient = new BlobClient(
new Uri("https://myaccount.blob.core.windows.net/mycontainer/myblob"),
credential);
AZURE_CLIENT_ID environment variable.To use a resource ID, set the DefaultAzureCredentialOptions.ManagedIdentityResourceId property. The resource ID takes the form /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. Because resource IDs can be built by convention, they can be more convenient when there are a large number of user-assigned managed identities in your environment. For example:
string userAssignedResourceId = "<your managed identity resource ID>";
var credential = new DefaultAzureCredential(
new DefaultAzureCredentialOptions
{
ManagedIdentityResourceId = new ResourceIdentifier(userAssignedResourceId)
});
var blobClient = new BlobClient(
new Uri("https://myaccount.blob.core.windows.net/mycontainer/myblob"),
credential);
ChainedTokenCredentialWhile DefaultAzureCredential is generally the quickest way to authenticate apps for Azure, you can create a customized chain of credentials to be considered. ChainedTokenCredential enables users to combine multiple credential instances to define a customized chain of credentials. For more information, see ChainedTokenCredential overview.
Managed identity authentication is supported either indirectly via DefaultAzureCredential or directly via ManagedIdentityCredential for the following Azure services:
As of version 1.8.0, ManagedIdentityCredential supports token caching.
WorkloadIdentityCredential supports an opt-in identity binding mode to work around Entra ID's limit on federated identity credentials (FICs) per managed identity. When enabled via the IsAzureProxyEnabled option, the credential redirects token requests to an AKS-provided proxy that handles the FIC exchange centrally, allowing multiple pods to share the same identity without hitting FIC limits.
Note: This feature is only available when using WorkloadIdentityCredential directly. It is not supported by DefaultAzureCredential or ManagedIdentityCredential.
var credential = new WorkloadIdentityCredential(new WorkloadIdentityCredentialOptions
{
IsAzureProxyEnabled = true // Enable identity binding mode
});
When enabled, the credential reads these environment variables (typically configured by AKS):
AZURE_KUBERNETES_TOKEN_PROXY - Base HTTPS URL for the proxy endpointAZURE_KUBERNETES_CA_FILE - Path to PEM bundle with proxy CA certificatesAZURE_KUBERNETES_CA_DATA - PEM-encoded CA bundle (mutually exclusive with AZURE_KUBERNETES_CA_FILE )AZURE_KUBERNETES_SNI_NAME - TLS Server Name Indication (optional)The credential validates the configuration at construction time and throws InvalidOperationException if the configuration is invalid or incomplete.
If you're currently using ManagedIdentityCredential for workload identity in AKS and need to use identity binding mode, migrate to WorkloadIdentityCredential:
// Before (no identity binding support):
// var credential = new ManagedIdentityCredential(ManagedIdentityId.SystemAssigned);
// After (with identity binding support):
var credential = new WorkloadIdentityCredential(new WorkloadIdentityCredentialOptions
{
IsAzureProxyEnabled = true
});
By default, credentials authenticate to the Microsoft Entra endpoint for the Azure Public Cloud. To access resources in other clouds, such as Azure US Government or a private cloud, use one of the following solutions:
var credential = new DefaultAzureCredential(
new DefaultAzureCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzureGovernment
});
AzureAuthorityHosts defines authorities for well-known clouds.
AZURE_AUTHORITY_HOST environment variable to the appropriate authority host URL. For example, https://login.microsoftonline.us/. Note that this setting affects all credentials in the environment. Use the previous solution to set the authority host on a specific credential.Not all credentials require this configuration. Credentials that authenticate through a developer tool, such as AzureCliCredential, use that tool's configuration.
| Credential | Usage | Reference |
|---|---|---|
DefaultAzureCredential |
Provides a simplified authentication experience to quickly start developing apps run in Azure. | DefaultAzureCredential overview |
ChainedTokenCredential |
Allows users to define custom authentication flows comprised of multiple credentials. | ChainedTokenCredential overview |
| Credential | Usage | Reference |
|---|---|---|
EnvironmentCredential |
Authenticates a service principal or user via credential information specified in environment variables. | |
ManagedIdentityCredential |
Authenticates the managed identity of an Azure resource. | user-assigned managed identity<br>system-assigned managed identity |
WorkloadIdentityCredential |
Supports Microsoft Entra Workload ID on Kubernetes. Supports identity binding mode to work around FIC limits in AKS. |
| Credential | Usage | Reference |
|---|---|---|
AzurePipelinesCredential |
Supports Microsoft Entra Workload ID on Azure Pipelines. | example |
ClientAssertionCredential |
Authenticates a service principal using a signed client assertion. | |
ClientCertificateCredential |
Authenticates a service principal using a certificate. | Service principal authentication |
ClientSecretCredential |
Authenticates a service principal using a secret. | Service principal authentication |
| Credential | Usage | Reference |
|---|---|---|
AuthorizationCodeCredential |
Authenticates a user with a previously obtained authorization code. | OAuth2 authorization code |
DeviceCodeCredential |
Interactively authenticates a user on devices with limited UI. | Device code authentication |
InteractiveBrowserCredential |
Interactively authenticates a user with the default system browser. | Interactive browser authentication |
OnBehalfOfCredential |
Propagates the delegated user identity and permissions through the request chain. | On-behalf-of authentication |
| Credential | Usage | Reference |
|---|---|---|
AzureCliCredential |
Authenticates in a development environment with the Azure CLI. | Azure CLI authentication |
AzureDeveloperCliCredential |
Authenticates in a development environment with the Azure Developer CLI. | Azure Developer CLI Reference |
AzurePowerShellCredential |
Authenticates in a development environment with the Azure PowerShell. | Azure PowerShell authentication |
VisualStudioCredential |
Authenticates in a development environment with Visual Studio. | Visual Studio configuration |
VisualStudioCodeCredential |
Authenticates in a development environment with Visual Studio Code. | Visual Studio Code configuration |
Note: All credential implementations in the Azure Identity library are threadsafe, and a single credential instance can be used by multiple service clients.
DefaultAzureCredential and EnvironmentCredential can be configured with environment variables. Each type of authentication requires values for specific variables. Configuration is attempted in the order in which these environment variables are listed. For example, if values for a client secret and certificate are both present, the client secret is used by EnvironmentCredential.
| Variable name | Value |
|---|---|
AZURE_CLIENT_ID |
ID of a Microsoft Entra application |
AZURE_TENANT_ID |
ID of the application's Microsoft Entra tenant |
AZURE_CLIENT_SECRET |
one of the application's client secrets |
| Variable name | Value |
|---|---|
AZURE_CLIENT_ID |
ID of a Microsoft Entra application |
AZURE_TENANT_ID |
ID of the application's Microsoft Entra tenant |
AZURE_CLIENT_CERTIFICATE_PATH |
Path to the client certificate, including the private key. The path must be to either a "pfx"- or "pem"-encoded certificate on disk, or a certificate in the platform certificate store by thumbprint.<br>For example:<ul><li>c:\data\certificate.pfx</li><li>/etc/app/cert.pem</li><li>cert:/CurrentUser/My/E661583E8FABEF4C0BEF694CBC41C28FB81CD870</li></ul> |
AZURE_CLIENT_CERTIFICATE_PASSWORD |
(optional) the password protecting the certificate file (currently only supported for PFX (PKCS12) certificates) |
AZURE_CLIENT_SEND_CERTIFICATE_CHAIN |
(optional) send certificate chain in x5c header to support subject name / issuer based authentication |
DefaultAzureCredential)| Variable name | Value |
|---|---|
AZURE_CLIENT_ID |
The client ID of the application the workload identity will authenticate. If defined, used as the default value for WorkloadIdentityClientId in DefaultAzureCredentialOptions. |
DefaultAzureCredential)| Variable name | Value |
|---|---|
AZURE_CLIENT_ID |
The client ID for the user-assigned managed identity. If defined, used as the default value for ManagedIdentityClientId in DefaultAzureCredentialOptions. |
As of version 1.10.0, accessing resources protected by Continuous Access Evaluation (CAE) is possible on a per-request basis. This behavior can be enabled by setting the IsCaeEnabled property of TokenRequestContext via its constructor. CAE isn't supported for developer credentials.
Token caching is a feature provided by the Azure Identity library. The feature allows apps to:
The Azure Identity library offers both in-memory and persistent disk caching. For more information, see the token caching documentation.
An authentication broker is an app that runs on a user's machine and manages the authentication handshakes and token maintenance for connected accounts. To enable support, use the Azure.Identity.Broker package.
See the troubleshooting guide.
Errors arising from authentication can be raised on any service client method that makes a request to the service. This is because the first time the token is requested from the credential is on the first call to the service. Any subsequent calls might need to refresh the token. To distinguish these failures from failures in the service client, Azure Identity classes raise the AuthenticationFailedException with details on the error source in the exception message and possibly the error message. Depending upon the app, these errors may or may not be recoverable.
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
// Create a secret client using the DefaultAzureCredential
var client = new SecretClient(new Uri("https://myvault.vault.azure.net/"), new DefaultAzureCredential());
try
{
KeyVaultSecret secret = await client.GetSecretAsync("secret1");
}
catch (AuthenticationFailedException e)
{
Console.WriteLine($"Authentication Failed. {e.Message}");
}
For more information on handling errors from failed requests to Microsoft Entra ID or managed identity endpoints, see the Microsoft Entra ID documentation on authorization error codes.
See Enable and configure logging.
We guarantee that all credential instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing credential instances is always safe, even across threads.
Client options | Accessing the response | Diagnostics | Mocking | Client lifetime
Many of Azure.Core-dependent client libraries support authenticating with TokenCredential and therefore the Azure Identity library. To learn more, see the library-specific docs.
This library doesn't currently support scenarios relating to the Azure AD B2C service.
Open issues for the Azure.Identity library can be found here.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You'll only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Azure.Identity:
| Package | Downloads |
|---|---|
|
Microsoft.Identity.Web.Certificate
This package brings certificate management for MSAL.NET. |
|
|
Microsoft.Extensions.Caching.SqlServer
Distributed cache implementation of Microsoft.Extensions.Caching.Distributed.IDistributedCache using Microsoft SQL Server. This package was built from the source code at https://github.com/dotnet/dotnet/tree/f7b4c5716faaee8fb8a289aed29118cad955c45f |
|
|
Microsoft.Diagnostics.Runtime
ClrMD is a set of advanced APIs for programmatically inspecting a crash dump of a .NET program much in the same way that the SOS Debugging Extensions (SOS) do. This allows you to write automated crash analysis for your applications as well as automate many common debugger tasks. In addition to reading crash dumps ClrMD also allows supports attaching to live processes. |
|
|
WindowsAzure.ServiceBus
Please note, for Azure Service Bus, Azure Event Hubs and Azure Relay, newer packages Azure.Messaging.ServiceBus, Azure.Messaging.EventHubs and Microsoft.Azure.Relay are available as of November 2020, February 2020 and March 2017 respectively. While WindowsAzure.ServiceBus will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read https://aka.ms/azsdk/blog/msging/intro for more details. It adds Microsoft.ServiceBus.dll along with related configuration files to your project. This library allows AMQP 1.0 to be used as one of the protocols for communication with Microsoft Azure Service Bus. For more information on Messaging features, please visit: http://azure.microsoft.com/en-us/documentation/services/service-bus/ For more information on Event Hub features, please visit: http://go.microsoft.com/fwlink/?LinkID=403957 Please note that this package requires at least .Net Framework 4.6.2. |
|
|
Microsoft.Azure.SignalR
.NET Standard SDK for Azure SignalR. |
Showing the top 20 popular GitHub repositories that depend on Azure.Identity:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
jasontaylordev/CleanArchitecture
Clean Architecture Solution Template for ASP.NET Core
|
|
|
DapperLib/Dapper
Dapper - a simple object mapper for .Net
|
|
|
ardalis/CleanArchitecture
Clean Architecture Solution Template: A proven Clean Architecture Template for ASP.NET Core 10
|
|
|
dotnet/efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
|
|
|
duplicati/duplicati
Store securely encrypted backups in the cloud!
|
|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
|
microsoft/garnet
Garnet is a remote cache-store from Microsoft Research that offers strong performance (throughput and latency), scalability, storage, recovery, cluster sharding, key migration, and replication features. Garnet can work with existing Redis clients.
|
|
|
dotnet/orleans
Cloud Native application framework for .NET
|
|
|
dotnet-architecture/eShopOnWeb
Sample ASP.NET Core 8.0 reference application, now community supported: https://github.com/NimblePros/eShopOnWeb
|
|
|
dodyg/practical-aspnetcore
Practical samples of ASP.NET Core 11, 10, 9, 8.0, 7.0, 6.0, 5.0, 3.1, 2.2, and 2.1,projects you can use. Readme contains explanations on all projects.
|
|
|
nopSolutions/nopCommerce
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
|
|
|
OrchardCMS/OrchardCore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
|
|
|
MassTransit/MassTransit
Distributed Application Framework for .NET
|
|
|
EduardoPires/EquinoxProject
Web Application ASP.NET 9 using Clean Architecture, DDD, CQRS, Event Sourcing and a lot of good practices
|
|
|
microsoft/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
danielgerlag/workflow-core
Lightweight workflow engine for .NET Standard
|
|
|
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
|
|
|
win-acme/win-acme
Automate SSL/TLS certificates on Windows with ease
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.21.0 | 11,658,189 | 4/11/2026 | |
| 1.20.0 | 2,670,657 | 3/31/2026 | |
| 1.19.0 | 4,367,727 | 3/11/2026 | |
| 1.18.0 | 8,084,370 | 2/26/2026 | |
| 1.18.0-beta.3 | 5,486 | 2/20/2026 | |
| 1.18.0-beta.2 | 192,602 | 11/19/2025 | |
| 1.18.0-beta.1 | 9,670 | 11/15/2025 | 1.18.0-beta.1 is deprecated. |
| 1.17.2 | 2,433,823 | 4/15/2026 | |
| 1.17.1 | 46,206,476 | 11/19/2025 | |
| 1.17.0 | 20,623,292 | 10/7/2025 | 1.17.0 is deprecated. |
| 1.16.0 | 18,502,520 | 9/9/2025 | 1.16.0 is deprecated. |
| 1.15.0 | 10,632,150 | 8/11/2025 | 1.15.0 is deprecated. |
| 1.15.0-beta.1 | 146,397 | 7/17/2025 | 1.15.0-beta.1 is deprecated. |
| 1.14.2 | 60,766,598 | 7/11/2025 | 1.14.2 is deprecated. |
| 1.14.1 | 6,141,575 | 6/24/2025 | 1.14.1 is deprecated. |
| 1.14.0 | 14,827,099 | 5/13/2025 | 1.14.0 is deprecated. |
| 1.14.0-beta.4 | 12,935 | 5/1/2025 | 1.14.0-beta.4 is deprecated. |
| 1.14.0-beta.3 | 60,804 | 4/8/2025 | 1.14.0-beta.3 is deprecated. |
| 1.14.0-beta.2 | 41,587 | 3/11/2025 | 1.14.0-beta.2 is deprecated. |
| 1.14.0-beta.1 | 62,048 | 2/11/2025 | 1.14.0-beta.1 is deprecated. |