Skip to main content

alibi_api/plugins/oauth/providers/
zoom.rs

1//! Dedicated published Better Auth 1.7.6 Zoom factory.
2use super::remaining_profile::{ProfileKind, PublishedProfile};
3use super::{OAuthAuthorizationPolicy, OAuthProvider, OAuthTokenEndpointAuth, OAuthUserInfo};
4use serde_json::Value;
5
6#[derive(Clone)]
7pub struct ZoomOptions {
8    pub client_id: String,
9    pub client_secret: Option<String>,
10    pub client_key: Option<String>,
11    pub authorization_endpoint: Option<String>,
12    pub redirect_uri: Option<String>,
13    /// Trusted application transport override; it does not change profile semantics.
14    pub user_info_endpoint: Option<String>,
15    pub map_profile_to_user: Option<fn(Value) -> Result<OAuthUserInfo, String>>,
16    pub pkce: bool,
17}
18impl ZoomOptions {
19    #[must_use]
20    pub fn new(client_id: impl Into<String>, client_secret: Option<String>) -> Self {
21        Self {
22            client_id: client_id.into(),
23            client_secret,
24            client_key: None,
25            authorization_endpoint: None,
26            redirect_uri: None,
27            user_info_endpoint: None,
28            map_profile_to_user: None,
29            pkce: true,
30        }
31    }
32}
33impl std::fmt::Debug for ZoomOptions {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        f.debug_struct("ZoomOptions")
36            .field("client_id", &self.client_id)
37            .field("authorization_endpoint", &self.authorization_endpoint)
38            .finish_non_exhaustive()
39    }
40}
41impl OAuthProvider {
42    #[must_use]
43    pub fn zoom(client_id: &str, client_secret: Option<&str>) -> Self {
44        Self::zoom_with_options(ZoomOptions::new(
45            client_id,
46            client_secret.map(str::to_owned),
47        ))
48    }
49    #[must_use]
50    pub fn zoom_with_options(options: ZoomOptions) -> Self {
51        let mut policy = OAuthAuthorizationPolicy {
52            preserve_raw_profile_scalars: true,
53            source_profile_exceptions: true,
54            honor_factory_options: false,
55            require_client_id: true,
56            login_hint: false,
57            pkce: true,
58            configured_scopes: Vec::new(),
59            disable_default_scopes: false,
60            authorization_code_client_key: options.client_key,
61            redirect_uri: options.redirect_uri,
62            token_endpoint_auth: Some(
63                if options
64                    .client_secret
65                    .as_ref()
66                    .is_some_and(|v| !v.is_empty())
67                {
68                    OAuthTokenEndpointAuth::ClientSecretPost
69                } else {
70                    OAuthTokenEndpointAuth::None
71                },
72            ),
73            allow_missing_access_token: true,
74            preserve_raw_email_errors: true,
75            ..OAuthAuthorizationPolicy::default()
76        };
77        let mut provider = Self {
78            client_id: options.client_id,
79            client_secret: options.client_secret.unwrap_or_default(),
80            additional_client_ids: Vec::new(),
81            hosted_domain: None,
82            require_email_verification: false,
83            auth_url: "https://zoom.us/oauth/authorize".into(),
84            token_url: "https://zoom.us/oauth/token".into(),
85            user_info_url: Some("https://api.zoom.us/v2/users/me".into()),
86            scopes: vec![],
87            authorization: None,
88            authorization_params: Vec::new(),
89            account_subject: Some(subject),
90            map_user_info: None,
91            get_user_info: None,
92            refresh_access_token: None,
93            verify_id_token: None,
94            id_token: None,
95            disable_id_token_sign_in: false,
96            disable_implicit_sign_up: false,
97            disable_sign_up: false,
98            override_user_info_on_sign_in: false,
99        };
100        provider.auth_url = options
101            .authorization_endpoint
102            .filter(|v| !v.is_empty())
103            .unwrap_or(provider.auth_url);
104        provider.user_info_url = options.user_info_endpoint.or(provider.user_info_url);
105        policy.pkce = options.pkce;
106        policy.authorization_code_pkce = Some(true);
107        policy.omit_scopes = true;
108        provider.authorization = Some(policy);
109        provider.get_user_info = Some(std::sync::Arc::new(PublishedProfile {
110            kind: ProfileKind::Zoom,
111            endpoint: provider.user_info_url.clone(),
112            email_endpoint: None,
113            client_id: provider.client_id.clone(),
114            mapper: options.map_profile_to_user,
115            application_mapper: None,
116        }));
117        provider
118    }
119}
120fn subject(profile: &Value) -> Result<String, String> {
121    super::remaining_profile::subject(ProfileKind::Zoom, profile)
122}