passport_azure_ad

Crates.iopassport_azure_ad
lib.rspassport_azure_ad
version0.1.3
sourcesrc
created_at2023-06-06 14:03:19.463064
updated_at2023-12-06 10:27:31.075553
descriptionJWT bearer token validation and verification towards Microsoft Azure AD
homepage
repositoryhttps://github.com/lincemiope/rust-passport-azure-ad
max_upload_size
id883880
size26,597
Fabio Cammilli (lincemiope)

documentation

README

rust-passport-azure-ad

Port of passport-azure-ad to Rust

Installation

cargo add passport_azure_ad

Usage

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());
}

License

MIT

Commit count: 6

cargo fmt