Skip to main content

rustauth_plugins/generic_oauth/providers/
microsoft_entra_id.rs

1//! Microsoft Entra ID generic OAuth provider helper.
2
3use crate::generic_oauth::GenericOAuthConfig;
4use std::sync::Arc;
5
6pub const PROVIDER_ID: &str = "microsoft-entra-id";
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct MicrosoftEntraIdOptions {
10    pub base: super::BaseOAuthProviderOptions,
11    pub tenant_id: String,
12}
13
14pub fn microsoft_entra_id(options: MicrosoftEntraIdOptions) -> GenericOAuthConfig {
15    let tenant_id = options.tenant_id;
16    let mut config = GenericOAuthConfig::new(
17        PROVIDER_ID,
18        "",
19        None::<String>,
20        format!("https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize"),
21        format!("https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"),
22    );
23    config.user_info_url = Some("https://graph.microsoft.com/oidc/userinfo".to_owned());
24    super::apply_base_options(
25        &mut config,
26        options.base,
27        vec![
28            "openid".to_owned(),
29            "profile".to_owned(),
30            "email".to_owned(),
31        ],
32    );
33    config.get_user_info = Some(Arc::new(|tokens| {
34        Box::pin(super::user_info::microsoft_entra_id(tokens))
35    }));
36    config
37}