Skip to main content

openauth_core/db/
models.rs

1use serde::{Deserialize, Serialize};
2use time::OffsetDateTime;
3
4/// Core user record.
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct User {
7    pub id: String,
8    pub name: String,
9    pub email: String,
10    pub email_verified: bool,
11    pub image: Option<String>,
12    #[serde(default)]
13    pub username: Option<String>,
14    #[serde(default, alias = "displayUsername")]
15    pub display_username: Option<String>,
16    #[serde(with = "time::serde::rfc3339")]
17    pub created_at: OffsetDateTime,
18    #[serde(with = "time::serde::rfc3339")]
19    pub updated_at: OffsetDateTime,
20}
21
22/// Linked credential, OAuth, or social provider account.
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24pub struct Account {
25    pub id: String,
26    pub provider_id: String,
27    pub account_id: String,
28    pub user_id: String,
29    pub access_token: Option<String>,
30    pub refresh_token: Option<String>,
31    pub id_token: Option<String>,
32    #[serde(with = "time::serde::rfc3339::option")]
33    pub access_token_expires_at: Option<OffsetDateTime>,
34    #[serde(with = "time::serde::rfc3339::option")]
35    pub refresh_token_expires_at: Option<OffsetDateTime>,
36    pub scope: Option<String>,
37    pub password: Option<String>,
38    #[serde(with = "time::serde::rfc3339")]
39    pub created_at: OffsetDateTime,
40    #[serde(with = "time::serde::rfc3339")]
41    pub updated_at: OffsetDateTime,
42}
43
44/// Persisted user session.
45#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46pub struct Session {
47    pub id: String,
48    pub user_id: String,
49    #[serde(with = "time::serde::rfc3339")]
50    pub expires_at: OffsetDateTime,
51    pub token: String,
52    pub ip_address: Option<String>,
53    pub user_agent: Option<String>,
54    #[serde(with = "time::serde::rfc3339")]
55    pub created_at: OffsetDateTime,
56    #[serde(with = "time::serde::rfc3339")]
57    pub updated_at: OffsetDateTime,
58}
59
60/// Verification token or value used by flows such as email verification.
61#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
62pub struct Verification {
63    pub id: String,
64    pub identifier: String,
65    pub value: String,
66    #[serde(with = "time::serde::rfc3339")]
67    pub expires_at: OffsetDateTime,
68    #[serde(with = "time::serde::rfc3339")]
69    pub created_at: OffsetDateTime,
70    #[serde(with = "time::serde::rfc3339")]
71    pub updated_at: OffsetDateTime,
72}
73
74/// Database-backed rate limit bucket.
75#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
76pub struct RateLimit {
77    pub key: String,
78    pub count: u64,
79    pub last_request: i64,
80}