Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples for Client Credentials Flow #1325

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 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,24 @@ 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
Loading