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>

source

pub fn invalid_before(self, unix_timestamp: UnixTimeStamp) -> Self

Set the token as not being valid until unix_timestamp

source

pub fn with_issuer(self, issuer: impl ToString) -> Self

Set the issuer

source

pub fn with_subject(self, subject: impl ToString) -> Self

Set the subject

source

pub fn with_audiences(self, audiences: HashSet<impl ToString>) -> Self

Register one or more audiences (optional recipient identifiers), as a set

source

pub fn with_audience(self, audience: impl ToString) -> Self

Set a unique audience (an optional recipient identifier), as a string

source

pub fn with_jwt_id(self, jwt_id: impl ToString) -> Self

Set the JWT identifier

source

pub fn with_nonce(self, nonce: impl ToString) -> Self

Set the nonce

source

pub fn create_nonce(&mut self) -> String

Create a nonce, attach it and return it

Trait Implementations§

source§

impl<CustomClaims: Clone> Clone for JWTClaims<CustomClaims>

source§

fn clone(&self) -> JWTClaims<CustomClaims>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<CustomClaims: Debug> Debug for JWTClaims<CustomClaims>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<CustomClaims> Serialize for JWTClaims<CustomClaims>where CustomClaims: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. 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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,