use jwt_simple::claims::JWTClaims; use jwt_simple::prelude::Duration; pub struct AccessToken { pub issuer: String, pub subject_identifier: String, pub issued_at: u64, pub exp_time: u64, pub rand_val: String, pub nonce: Option, } #[derive(serde::Serialize, serde::Deserialize)] pub struct CustomAccessTokenClaims { rand_val: String, } impl AccessToken { pub fn to_jwt_claims(self) -> JWTClaims { JWTClaims { issued_at: Some(Duration::from_secs(self.issued_at)), expires_at: Some(Duration::from_secs(self.exp_time)), invalid_before: None, issuer: Some(self.issuer), subject: Some(self.subject_identifier), audiences: None, jwt_id: None, nonce: self.nonce, custom: CustomAccessTokenClaims { rand_val: self.rand_val }, } } }