Skip to main content

pidge_client/auth/
config.rs

1//! Compile-time constants and runtime overrides for the pidge OAuth app.
2
3/// The pidge app's `client_id` in Microsoft Entra.
4///
5/// Empty string means "not yet provisioned". Set by `scripts/register-pidge-app.sh`
6/// after registering the app in Entra. Until then, set the `PIDGE_CLIENT_ID` env var
7/// for development.
8pub const APP_CLIENT_ID: &str = "e49f90dc-c265-4392-b62f-b26704f9088f";
9
10/// Microsoft Graph delegated scopes pidge requests at sign-in.
11/// Locked in at app registration time — changing them later requires updating
12/// the Entra app permissions AND triggering incremental consent on existing accounts.
13pub const SCOPES: &[&str] = &[
14    "offline_access",
15    "User.Read",
16    "Mail.ReadWrite",
17    "Mail.Send",
18    "Calendars.ReadWrite",
19];
20
21/// Microsoft identity platform endpoints (common = multi-tenant + personal MSA).
22pub const AUTHORITY: &str = "https://login.microsoftonline.com/common";
23pub const DEVICE_CODE_URL: &str = "https://login.microsoftonline.com/common/oauth2/v2.0/devicecode";
24pub const TOKEN_URL: &str = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
25
26/// Microsoft Graph base URL.
27pub const GRAPH_BASE: &str = "https://graph.microsoft.com/v1.0";
28
29/// Resolved client_id: env var wins, otherwise the compile-time constant (if non-empty).
30pub fn client_id() -> Option<String> {
31    if let Ok(v) = std::env::var("PIDGE_CLIENT_ID") {
32        if !v.is_empty() {
33            return Some(v);
34        }
35    }
36    if APP_CLIENT_ID.is_empty() {
37        None
38    } else {
39        Some(APP_CLIENT_ID.to_string())
40    }
41}
42
43/// The space-separated scope string sent to Microsoft.
44pub fn scope_string() -> String {
45    SCOPES.join(" ")
46}