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§
source§impl<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§
source§impl<'de, CustomClaims> Deserialize<'de> for JWTClaims<CustomClaims>where
CustomClaims: Deserialize<'de>,
impl<'de, CustomClaims> Deserialize<'de> for JWTClaims<CustomClaims>where
CustomClaims: Deserialize<'de>,
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>,
Auto Trait Implementations§
impl<CustomClaims> Freeze for JWTClaims<CustomClaims>where
CustomClaims: Freeze,
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)