Struct jwt_simple::claims::JWTClaims
source · [−]pub struct JWTClaims<CustomClaims> {
pub issued_at: Option<UnixTimeStamp>,
pub expires_at: Option<UnixTimeStamp>,
pub invalid_before: Option<UnixTimeStamp>,
pub issuer: Option<String>,
pub subject: Option<String>,
pub audiences: Option<Audiences>,
pub jwt_id: Option<String>,
pub nonce: Option<String>,
pub custom: CustomClaims,
}
Expand description
A set of JWT claims.
The CustomClaims
parameter can be set to NoCustomClaims
if only standard claims are used,
or to a user-defined type that must be serde
-serializable if custom claims are required.
Fields
issued_at: Option<UnixTimeStamp>
Time the claims were created at
expires_at: Option<UnixTimeStamp>
Time the claims expire at
invalid_before: Option<UnixTimeStamp>
Time the claims will be invalid until
issuer: Option<String>
Issuer - This can be set to anything application-specific
subject: Option<String>
Subject - This can be set to anything application-specific
audiences: Option<Audiences>
Audience
jwt_id: Option<String>
JWT identifier
That property was originally designed to avoid replay attacks, but keeping all previously sent JWT token IDs is unrealistic.
Replay attacks are better addressed by keeping only the timestamp of the last valid token for a user, and rejecting anything older in future tokens.
nonce: Option<String>
Nonce
custom: CustomClaims
Custom (application-defined) claims
Implementations
sourceimpl<CustomClaims> JWTClaims<CustomClaims>
impl<CustomClaims> JWTClaims<CustomClaims>
sourcepub fn invalid_before(self, unix_timestamp: UnixTimeStamp) -> Self
pub fn invalid_before(self, unix_timestamp: UnixTimeStamp) -> Self
Set the token as not being valid until unix_timestamp
sourcepub fn with_issuer(self, issuer: impl ToString) -> Self
pub fn with_issuer(self, issuer: impl ToString) -> Self
Set the issuer
sourcepub fn with_subject(self, subject: impl ToString) -> Self
pub fn with_subject(self, subject: impl ToString) -> Self
Set the subject
sourcepub fn with_audiences(self, audiences: HashSet<impl ToString>) -> Self
pub fn with_audiences(self, audiences: HashSet<impl ToString>) -> Self
Register one or more audiences (optional recipient identifiers), as a set
sourcepub fn with_audience(self, audience: impl ToString) -> Self
pub fn with_audience(self, audience: impl ToString) -> Self
Set a unique audience (an optional recipient identifier), as a string
sourcepub fn with_jwt_id(self, jwt_id: impl ToString) -> Self
pub fn with_jwt_id(self, jwt_id: impl ToString) -> Self
Set the JWT identifier
sourcepub fn with_nonce(self, nonce: impl ToString) -> Self
pub fn with_nonce(self, nonce: impl ToString) -> Self
Set the nonce
sourcepub fn create_nonce(&mut self) -> String
pub fn create_nonce(&mut self) -> String
Create a nonce, attach it and return it
Trait Implementations
sourceimpl<'de, CustomClaims> Deserialize<'de> for JWTClaims<CustomClaims> where
CustomClaims: Deserialize<'de>,
impl<'de, CustomClaims> Deserialize<'de> for JWTClaims<CustomClaims> where
CustomClaims: Deserialize<'de>,
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<CustomClaims> RefUnwindSafe for JWTClaims<CustomClaims> where
CustomClaims: RefUnwindSafe,
impl<CustomClaims> Send for JWTClaims<CustomClaims> where
CustomClaims: Send,
impl<CustomClaims> Sync for JWTClaims<CustomClaims> where
CustomClaims: Sync,
impl<CustomClaims> Unpin for JWTClaims<CustomClaims> where
CustomClaims: Unpin,
impl<CustomClaims> UnwindSafe for JWTClaims<CustomClaims> where
CustomClaims: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more