Skip to main content

modo/auth/oauth/
profile.rs

1use serde::{Deserialize, Serialize};
2
3/// Normalized user profile returned after a successful OAuth exchange.
4///
5/// Fields common to all providers are promoted to top-level fields. The raw JSON response from the
6/// provider is preserved in [`raw`](UserProfile::raw) for any provider-specific data your
7/// application needs.
8#[non_exhaustive]
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct UserProfile {
11    /// Lowercase provider identifier (`"google"`, `"github"`, …).
12    pub provider: String,
13    /// The user's unique ID within the provider's system.
14    pub provider_user_id: String,
15    /// Primary email address.
16    pub email: String,
17    /// Whether the provider has verified this email address.
18    pub email_verified: bool,
19    /// Display name, if the provider returned one.
20    pub name: Option<String>,
21    /// URL of the user's avatar image, if available.
22    pub avatar_url: Option<String>,
23    /// Raw JSON response from the provider's user-info endpoint.
24    pub raw: serde_json::Value,
25}
26
27impl UserProfile {
28    /// Create a new user profile with required fields.
29    pub fn new(
30        provider: impl Into<String>,
31        provider_user_id: impl Into<String>,
32        email: impl Into<String>,
33    ) -> Self {
34        Self {
35            provider: provider.into(),
36            provider_user_id: provider_user_id.into(),
37            email: email.into(),
38            email_verified: false,
39            name: None,
40            avatar_url: None,
41            raw: serde_json::Value::Null,
42        }
43    }
44}