use fully_pub::fully_pub; use jsonwebtoken::get_current_timestamp; use serde::{Deserialize, Serialize}; use time::Duration; use super::authorization::AuthorizationScope; #[derive(Debug, Serialize, Deserialize, Clone)] #[fully_pub] struct UserTokenClaims { /// subject: user id sub: String, /// token expiration exp: u64, /// token issuer iss: String // TODO: add roles } impl UserTokenClaims { pub fn new(user_id: &str, max_age: Duration) -> Self { UserTokenClaims { sub: user_id.into(), exp: get_current_timestamp() + max_age.whole_seconds() as u64, iss: "Minauthator".into() } } } #[derive(Debug, Serialize, Deserialize, Clone)] #[fully_pub] struct AppUserTokenClaims { /// combined subject client_id: String, user_id: String, scopes: Vec, /// token expiration exp: u64, /// token issuer iss: String } impl AppUserTokenClaims { pub fn new(client_id: &str, user_id: &str, scopes: Vec) -> Self { AppUserTokenClaims { client_id: client_id.into(), user_id: user_id.into(), scopes, exp: get_current_timestamp() + 86_000, iss: "Minauth".into() } } }