#azure-sdk #azure #sdk #cloud #iot #azure-rest #rest

azure_identity_gindix

围绕Microsoft Azure REST API的Rust封装 - Azure身份助手包

2个不稳定版本

0.21.0 2024年5月3日
0.20.0 2024年5月3日

#1799 in 网络编程

每月38次下载

MIT许可证

360KB
8K SLoC

azure_identity

Azure Identity包用于非官方的Rust Microsoft Azure SDK。此包是集合中的一员:有关更多信息,请参阅https://github.com/azure/azure-sdk-for-rust

此包提供了多个azure_core::auth::TokenCredential特质的实现。建议从azure_identity::create_credential()?开始,这将默认创建一个DefaultAzureCredential实例。如果您想使用特定的凭证类型,可以将AZURE_CREDENTIAL_KIND环境变量设置为azure_credential_kinds中的值,例如azureclivirtualmachine

#[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(())
}

支持的认证流程有

许可证:MIT

依赖项

~9–24MB
~373K SLoC