2022-04-15 18:08:31 +00:00
|
|
|
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<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Serialize, serde::Deserialize)]
|
|
|
|
pub struct CustomAccessTokenClaims {
|
|
|
|
rand_val: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AccessToken {
|
|
|
|
pub fn to_jwt_claims(self) -> JWTClaims<CustomAccessTokenClaims> {
|
|
|
|
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 {
|
2022-11-11 11:26:02 +00:00
|
|
|
rand_val: self.rand_val,
|
2022-04-15 18:08:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 11:26:02 +00:00
|
|
|
}
|