| Crates.io | azure_identity |
| lib.rs | azure_identity |
| version | 0.31.0 |
| created_at | 2022-01-24 20:24:27.85507+00 |
| updated_at | 2026-01-21 16:07:35.236946+00 |
| description | Rust wrappers around Microsoft Azure REST APIs - Azure identity helper crate |
| homepage | https://github.com/azure/azure-sdk-for-rust |
| repository | https://github.com/azure/azure-sdk-for-rust |
| max_upload_size | |
| id | 520384 |
| size | 280,866 |
The Azure Identity library provides Microsoft Entra ID (formerly Azure Active Directory) authentication support across the Azure SDK.
Source code | Package (crates.io) | API reference documentation | Microsoft Entra ID documentation
Install the Azure Identity library for Rust with cargo:
cargo add azure_identity
The Azure Identity library supports authenticating through developer tools to simplify local development and debugging.
DeveloperToolsCredential and AzureCliCredential can authenticate as the user signed in to the Azure CLI. To log in to the Azure CLI, run az login as described in Azure CLI documentation.
DeveloperToolsCredential and AzureDeveloperCliCredential can authenticate as the user signed in to the Azure Developer CLI. To log in to the Azure Developer CLI, run azd auth login as described in Azure Developer CLI documentation.
A credential is a struct that can acquire access tokens for Azure resources. The Azure Identity library offers various credentials for use by Azure SDK service clients. See the Credential structures section for a list of this library's credentials.
DeveloperToolsCredentialDeveloperToolsCredential simplifies authentication while developing apps. It attempts to authenticate via a series of developer tools such as the Azure CLI, stopping when one succeeds. After receiving a token from a particular tool, it uses that tool for all subsequent token requests. See the type's reference documentation for more details.
This example demonstrates authenticating the SecretClient from the azure_security_keyvault_secrets crate using DeveloperToolsCredential.
use azure_identity::DeveloperToolsCredential;
use azure_security_keyvault_secrets::SecretClient;
let credential = DeveloperToolsCredential::new(None)?;
let client = SecretClient::new("https://TODO.vault.azure.net/", credential.clone(), None)?;
This example demonstrates how to authenticate an Entra application with an access token from a managed identity. See Configure an application to trust a managed identity for more information about this scenario. This example shows a Key Vault client, however the same approach can work with any Azure SDK client that uses a TokenCredential.
use azure_core::credentials::TokenCredential;
use azure_core::http::ClientMethodOptions;
use azure_identity::{ClientAssertion, ClientAssertionCredential, ManagedIdentityCredential};
use azure_security_keyvault_secrets::SecretClient;
use std::sync::Arc;
#[derive(Debug)]
struct AccessTokenAssertion {
credential: Arc<dyn TokenCredential>,
}
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
impl ClientAssertion for AccessTokenAssertion {
async fn secret(&self, _: Option<ClientMethodOptions<'_>>) -> azure_core::Result<String> {
Ok(self
.credential
.get_token(&[&"api://AzureADTokenExchange/.default"], None)
.await?
.token
.secret()
.to_string())
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let assertion = AccessTokenAssertion {
credential: ManagedIdentityCredential::new(None)?,
};
// this credential exchanges the managed identity's tokens for the specified Entra application's tokens
let credential = ClientAssertionCredential::new(
String::from("tenant ID"),
String::from("client ID"),
assertion,
None,
)?;
let _client = SecretClient::new("https://TODO.vault.azure.net/", credential.clone(), None)?;
Ok(())
}
| Credential | Usage |
|---|---|
AzureCliCredential |
Authenticate with Azure CLI. |
AzureDeveloperCliCredential |
Authenticate with Azure Developer CLI. |
DeveloperToolsCredential |
Simplified authentication for application development. |
| Credential | Usage |
|---|---|
ManagedIdentityCredential |
Authenticate the managed identity of an Azure resource. |
WorkloadIdentityCredential |
Supports Workload Identity on Kubernetes. |
See Service principal authentication for general information about service principals.
| Credential | Usage |
|---|---|
AzurePipelinesCredential |
Authenticate an Azure Pipelines service connection. |
ClientAssertionCredential |
Authenticate a service principal with client assertions. |
ClientCertificateCredential |
Authenticate a service principal with a certificate. |
ClientSecretCredential |
Authenticate a service principal with a secret. |
Client and management libraries listed on the Azure SDK release page that support Microsoft Entra authentication accept credentials from this library. You can learn more about using these libraries in their documentation, which is available at Docs.rs.
If you encounter bugs or have suggestions, open an issue.
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.