azure_identity 0.2.0

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

Azure SDK for Rust - Azure Identity Crate

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 mechanisms for several ways to authenticate against Azure

For example, to authenticate using the client credential flow, you can do the following:

use azure_identity::client_credentials_flow;
use oauth2::{ClientId, ClientSecret};
use url::Url;

use std::env;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client_id =
        ClientId::new(env::var("CLIENT_ID").expect("Missing CLIENT_ID environment variable."));
    let client_secret = ClientSecret::new(
        env::var("CLIENT_SECRET").expect("Missing CLIENT_SECRET environment variable."),
    );
    let tenant_id = env::var("TENANT_ID").expect("Missing TENANT_ID environment variable.");
    let subscription_id =
        env::var("SUBSCRIPTION_ID").expect("Missing SUBSCRIPTION_ID environment variable.");

    let client = reqwest::Client::new();
    // This will give you the final token to use in authorization.
    let token = client_credentials_flow::perform(
        client,
        &client_id,
        &client_secret,
        &["https://management.azure.com/"],
        &tenant_id,
    )
    .await?;
    Ok(())
}

The supported authentication flows are:

This crate also includes utilities for handling refresh tokens and accessing token credentials from many different sources.

Usage

To set this crate as a dependency, add this to your Cargo.toml

[dependencies]
azure_identity = "0.1"