Skip to main content

rustbasic_passport/
entity.rs

1use serde::{Deserialize, Serialize};
2
3pub type UserId = String;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Client {
7    pub id: String,
8    pub owner_type: Option<String>,
9    pub owner_id: Option<String>,
10    pub name: String,
11    pub secret: Option<String>,
12    pub provider: Option<String>,
13    pub redirect_uris: Vec<String>,
14    pub grant_types: Vec<String>,
15    pub revoked: bool,
16}
17
18impl Client {
19    pub fn has_grant_type(&self, grant_type: &str) -> bool {
20        self.grant_types.iter().any(|g| g == grant_type)
21    }
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct AccessToken {
26    pub id: String,
27    pub user_id: Option<UserId>,
28    pub client_id: String,
29    pub name: Option<String>,
30    pub scopes: Vec<String>,
31    pub revoked: bool,
32    pub expires_at: i64,
33    pub created_at: i64,
34    pub updated_at: i64,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct AuthCode {
39    pub id: String,
40    pub user_id: Option<UserId>,
41    pub client_id: String,
42    pub scopes: Vec<String>,
43    pub revoked: bool,
44    pub expires_at: i64,
45    pub redirect_uri: String,
46    pub code_challenge: Option<String>,
47    pub code_challenge_method: Option<String>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct RefreshToken {
52    pub id: String,
53    pub client_id: String,
54    pub access_token_id: String,
55    pub revoked: bool,
56    pub expires_at: i64,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct DeviceCode {
61    pub id: String,
62    pub user_id: Option<UserId>,
63    pub client_id: String,
64    pub user_code: String,
65    pub scopes: Vec<String>,
66    pub revoked: bool,
67    pub user_approved_at: Option<i64>,
68    pub last_polled_at: Option<i64>,
69    pub expires_at: i64,
70}
71
72#[derive(Debug, Clone)]
73pub struct PersonalAccessTokenResult {
74    pub access_token: String,
75    pub token: AccessToken,
76}