oauth_account.rs 51 lignes · 1687 octets
use chrono::{DateTime, Utc};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// SeaORM model for the `oauth_accounts` table.
///
/// Links a Rustwarden user account to an external OAuth/OIDC identity.
#[derive(Clone, Debug, Serialize, Deserialize, DeriveEntityModel)]
#[sea_orm(table_name = "oauth_accounts")]
pub struct Model {
    /// Primary key.
    #[sea_orm(primary_key)]
    pub id: Uuid,
    /// FK → users.id — the local user this OAuth identity belongs to.
    pub user_id: Uuid,
    /// Provider name (e.g. `"google"`, `"github"`).
    pub provider: String,
    /// Unique user ID as returned by the OAuth provider.
    pub provider_user_id: String,
    /// Email address reported by the provider (may be absent for some providers).
    pub email: Option<String>,
    /// Display name reported by the provider.
    pub display_name: Option<String>,
    /// URL of the user's avatar image reported by the provider.
    pub avatar_url: Option<String>,
    /// Timestamp when this OAuth link was created.
    pub created_at: DateTime<Utc>,
    /// Timestamp of the last update to this OAuth link.
    pub updated_at: DateTime<Utc>,
}

/// SeaORM relations for the OAuthAccount entity.
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    /// The local user account this OAuth identity is linked to.
    #[sea_orm(
        belongs_to = "super::user::Entity",
        from = "Column::UserId",
        to = "super::user::Column::Id"
    )]
    User,
}

impl Related<super::user::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::User.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}