Expand description
Authorize using the OAuth 2.0 client credentials flow
For example:
use azure_identity::client_credentials_flow;
use azure_core::Url;
use std::env;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client_id =
env::var("CLIENT_ID").expect("Missing CLIENT_ID environment variable.");
let client_secret =
env::var("CLIENT_SECRET").expect("Missing CLIENT_SECRET environment variable.");
let tenant_id = env::var("TENANT_ID").expect("Missing TENANT_ID environment variable.");
let scope =
env::var("SCOPE").expect("Missing SCOPE environment variable.");
let http_client = azure_core::new_http_client();
// This will give you the final token to use in authorization.
let token = client_credentials_flow::perform(
http_client.clone(),
&client_id,
&client_secret,
&[&scope],
&tenant_id,
)
.await?;
Ok(())
}
You can learn more about this authorization flow here.
Functions§
- Perform the client credentials flow