mod manager;
mod revocation;
pub use manager::TokenManager;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum TokenType {
Access,
Refresh,
}
#[derive(Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TokenClaims {
pub iss: String,
pub sub: String,
pub aud: String,
pub exp: u64,
pub nbf: u64,
pub iat: u64,
pub jti: String,
pub token_type: TokenType,
#[serde(flatten)]
pub custom: serde_json::Value,
}
impl core::fmt::Debug for TokenClaims {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("TokenClaims")
.field("iss", &self.iss)
.field("sub", &self.sub)
.field("aud", &self.aud)
.field("exp", &self.exp)
.field("nbf", &self.nbf)
.field("iat", &self.iat)
.field("jti", &"***")
.field("token_type", &self.token_type)
.field("custom", &"***")
.finish()
}
}
impl TokenClaims {
#[allow(clippy::too_many_arguments)]
pub fn new(
iss: impl Into<String>,
sub: impl Into<String>,
aud: impl Into<String>,
exp: u64,
nbf: u64,
iat: u64,
jti: impl Into<String>,
token_type: TokenType,
custom: serde_json::Value,
) -> Self {
Self {
iss: iss.into(),
sub: sub.into(),
aud: aud.into(),
exp,
nbf,
iat,
jti: jti.into(),
token_type,
custom,
}
}
}
#[cfg(test)]
#[path = "__tests__/claims_test.rs"]
mod claims_test;
#[cfg(test)]
#[path = "__tests__/manager_test.rs"]
mod manager_test;