Skip to content

Commit

Permalink
Update examples for Client Credentials Flow (#1325)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgdev-guy authored Sep 5, 2023
1 parent 84b192d commit d1f93c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions sdk/identity/examples/client_credentials_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
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 subscription_id =
env::var("SUBSCRIPTION_ID").expect("Missing SUBSCRIPTION_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,
&["https://management.azure.com/"],
&[&scope],
&tenant_id,
)
.await?;
println!("Non interactive authorization == {token:?}");

let subscription_id =
env::var("SUBSCRIPTION_ID").expect("Missing SUBSCRIPTION_ID environment variable.");

// Let's enumerate the Azure SQL Databases instances
// in the subscription. Note: this way of calling the REST API
// will be different (and easier) using other Azure Rust SDK
Expand Down
6 changes: 3 additions & 3 deletions sdk/identity/src/client_credentials_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
//! 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 subscription_id =
//! env::var("SUBSCRIPTION_ID").expect("Missing SUBSCRIPTION_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,
//! &["https://management.azure.com/"],
//! &[&scope],
//! &tenant_id,
//! )
//! .await?;
Expand Down

0 comments on commit d1f93c9

Please sign in to comment.