pub struct Claims {
pub iss: Option<String>,
pub sub: Option<String>,
pub aud: Option<String>,
pub exp: Option<u64>,
pub nbf: Option<u64>,
pub iat: Option<u64>,
pub jti: Option<String>,
}Expand description
JWT claim payload used by the system auth flow.
Contains the seven registered JWT claims (iss, sub, aud, exp, nbf,
iat, jti). All fields are optional — None values are omitted from the
serialized token.
Custom auth flows that need extra payload fields should define their own
struct and pass it directly to [JwtEncoder::encode<T>] /
[JwtDecoder::decode<T>].
§Example
use modo::auth::session::jwt::Claims;
let claims = Claims::new()
.with_sub("user_123")
.with_aud("my-app")
.with_iat_now()
.with_exp_in(std::time::Duration::from_secs(3600));Fields§
§iss: Option<String>Issuer (iss).
sub: Option<String>Subject (sub) — typically the user identifier.
aud: Option<String>Audience (aud).
exp: Option<u64>Expiration time (exp) as a Unix timestamp in seconds.
nbf: Option<u64>Not-before time (nbf) as a Unix timestamp in seconds.
iat: Option<u64>Issued-at time (iat) as a Unix timestamp in seconds.
jti: Option<String>JWT ID (jti) — unique identifier for the token.
Implementations§
Source§impl Claims
impl Claims
Sourcepub fn with_exp(self, exp: u64) -> Self
pub fn with_exp(self, exp: u64) -> Self
Sets the expiration time (exp) as an absolute Unix timestamp in seconds.
Sourcepub fn with_exp_in(self, duration: Duration) -> Self
pub fn with_exp_in(self, duration: Duration) -> Self
Sets the expiration time (exp) relative to the current time.
Sourcepub fn with_nbf(self, nbf: u64) -> Self
pub fn with_nbf(self, nbf: u64) -> Self
Sets the not-before time (nbf) as an absolute Unix timestamp in seconds.
Sourcepub fn with_iat_now(self) -> Self
pub fn with_iat_now(self) -> Self
Sets the issued-at time (iat) to the current time.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Returns true if the token has an exp claim that is in the past.
Returns false when exp is absent.
Sourcepub fn is_not_yet_valid(&self) -> bool
pub fn is_not_yet_valid(&self) -> bool
Returns true if the token has an nbf claim that is in the future.
Returns false when nbf is absent.
Sourcepub fn subject(&self) -> Option<&str>
pub fn subject(&self) -> Option<&str>
Returns the subject claim (sub) as a string slice, if present.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Claims
impl<'de> Deserialize<'de> for Claims
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<S: Send + Sync> FromRequestParts<S> for Claims
Extracts Claims from request extensions.
impl<S: Send + Sync> FromRequestParts<S> for Claims
Extracts Claims from request extensions.
JwtLayer must be applied to the route — the
middleware decodes the token and inserts Claims into extensions before the
handler is called. Returns 401 Unauthorized when claims are not present
in extensions.