#azure-sdk #microsoft-azure #azure-api #azure #cloud #identity-management #sdk

azure_identity

Rust wrappers around Microsoft Azure REST APIs - Azure identity helper crate

20 breaking releases

0.21.0 Oct 15, 2024
0.20.0 Apr 24, 2024
0.19.0 Jan 5, 2024
0.18.1 Dec 11, 2023
0.1.1 Jan 25, 2022

#99 in Network programming

Download history 18418/week @ 2024-07-25 16744/week @ 2024-08-01 20360/week @ 2024-08-08 18685/week @ 2024-08-15 19570/week @ 2024-08-22 19089/week @ 2024-08-29 20194/week @ 2024-09-05 17956/week @ 2024-09-12 22394/week @ 2024-09-19 30731/week @ 2024-09-26 30257/week @ 2024-10-03 28599/week @ 2024-10-10 27020/week @ 2024-10-17 29967/week @ 2024-10-24 24461/week @ 2024-10-31 26328/week @ 2024-11-07

113,989 downloads per month
Used in 27 crates (20 directly)

MIT license

355KB
8K SLoC

azure_identity

Microsoft is developing the official Azure SDK for Rust crates and has no plans to update this unofficial crate. In the future we may release an official version that may have a different package name. If releasing an official version of this crate is important to you let us know.

Source for this crate can now be found in https://github.com/Azure/azure-sdk-for-rust/tree/legacy. To monitor for an official, supported version of this crate, see https://aka.ms/azsdk/releases.

Azure Identity crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to https://github.com/azure/azure-sdk-for-rust.

This crate provides several implementations of the azure_core::auth::TokenCredential trait. It is recommended to start with azure_identity::create_credential()?, which will create an instance of DefaultAzureCredential by default. If you want to use a specific credential type, the AZURE_CREDENTIAL_KIND environment variable may be set to a value from azure_credential_kinds, such as azurecli or virtualmachine.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
   let subscription_id =
       std::env::var("AZURE_SUBSCRIPTION_ID").expect("AZURE_SUBSCRIPTION_ID required");

   let credential = azure_identity::create_credential()?;

   // Let's enumerate the Azure storage accounts in the subscription using the REST API directly.
   // This is just an example. It is easier to use the Azure SDK for Rust crates.
   let url = url::Url::parse(&format!("https://management.azure.com/subscriptions/{subscription_id}/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01"))?;

   let access_token = credential
       .get_token(&["https://management.azure.com/.default"])
       .await?;

   let response = reqwest::Client::new()
       .get(url)
       .header(
           "Authorization",
           format!("Bearer {}", access_token.token.secret()),
       )
       .send()
       .await?
       .text()
       .await?;

   println!("{response}");
   Ok(())
}

The supported authentication flows are:

License: MIT

Dependencies

~10–26MB
~366K SLoC