Crates.io | passport_azure_ad |
lib.rs | passport_azure_ad |
version | 0.1.3 |
source | src |
created_at | 2023-06-06 14:03:19.463064 |
updated_at | 2023-12-06 10:27:31.075553 |
description | JWT bearer token validation and verification towards Microsoft Azure AD |
homepage | |
repository | https://github.com/lincemiope/rust-passport-azure-ad |
max_upload_size | |
id | 883880 |
size | 26,597 |
Port of passport-azure-ad to Rust
cargo add passport_azure_ad
use passport_azure_ad::{
bearer_strategy::BearerStrategy,
types::LogLevel,
util,
};
use std::env;
use dotenvy::dotenv;
#[tokio::test]
async fn test_msal_bearer() {
dotenv().ok();
let token = env::var("BEARER_TOKEN")
.expect("'BEARER_TOKEN' is not defined")
.to_string();
let client_id = env::var("AZURE_AD_CLIENT_ID")
.expect("'AZURE_AD_CLIENT_ID' is not defined")
.to_string();
let tenant_id = env::var("AZURE_AD_TENANT_ID")
.expect("'AZURE_AD_TENANT_ID' is not defined")
.to_string();
let bearer = BearerStrategy::build(
Some(false), // allow_multi_audiences
None, // audience
Some(client_id), // client_id
None, // clock_skew
Some(util::open_id_config_url(tenant_id.clone())), // identity_metadata
Some(false), // ignore_expiration
Some(false), // is_b2c
Some(vec![util::issuer_url(tenant_id)]), // issuer
Some(LogLevel::Trace), // log_level
None, // policy_name
Some(vec![String::from("api-access")]), // scope
Some(true), // validate_issuer
)
.unwrap();
let validated = bearer.authenticate(token).await;
assert!(validated.is_ok());
}