paseto_auth/
claims.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone)]
4pub struct Claims {
5    pub sub: String,        // User ID
6    pub exp: i64,           // Unix timestamp (saniye)
7    pub iat: i64,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub scope: Option<String>, // Optional
10}
11
12impl Claims {
13    pub fn new(sub: String, ttl_seconds: u64) -> Self {
14        let now = chrono::Utc::now().timestamp();
15        Self {
16            sub,
17            iat: now,
18            exp: now + ttl_seconds as i64,
19            scope: None,
20        }
21    }
22
23    pub fn with_scope(mut self, scope: String) -> Self {
24        self.scope = Some(scope);
25        self
26    }
27
28    pub fn is_valid(&self) -> bool {
29        let now = chrono::Utc::now().timestamp();
30        self.exp > now && self.iat <= now
31    }
32}