pub struct Claims<T> {
pub expiration_date: Option<DateTime<Utc>>,
pub not_before: Option<DateTime<Utc>>,
pub issued_at: Option<DateTime<Utc>>,
pub custom: T,
}Expand description
Claims encoded in a token.
Claims are comprised of a “standard” part (exp, nbf and iat claims as per JWT spec),
and custom fields. iss, sub and aud claims are not in the standard part
due to a variety of data types they can be reasonably represented by.
Fields§
§expiration_date: Option<DateTime<Utc>>Expiration date of the token.
not_before: Option<DateTime<Utc>>Minimum date at which token is valid.
issued_at: Option<DateTime<Utc>>Date of token issuance.
custom: TCustom claims.
Implementations§
Source§impl<T> Claims<T>
impl<T> Claims<T>
Sourcepub fn set_duration(self, duration: Duration) -> Self
pub fn set_duration(self, duration: Duration) -> Self
Sets expiration_date claim so that the token has the specified duration.
Sourcepub fn set_duration_and_issuance(self, duration: Duration) -> Self
pub fn set_duration_and_issuance(self, duration: Duration) -> Self
Atomically sets issued_at and expiration_date claims: first to the current time,
and the second to match the specified duration of the token.
Sourcepub fn set_not_before(self, moment: DateTime<Utc>) -> Self
pub fn set_not_before(self, moment: DateTime<Utc>) -> Self
Sets the nbf claim.
Sourcepub fn validate_expiration(
&self,
options: TimeOptions,
) -> Result<&Self, ValidationError>
pub fn validate_expiration( &self, options: TimeOptions, ) -> Result<&Self, ValidationError>
Validates the expiration claim.
This method will return an error if the claims do not feature an expiration date,
or if it is in the past (subject to the provided options).
Sourcepub fn validate_maturity(
&self,
options: TimeOptions,
) -> Result<&Self, ValidationError>
pub fn validate_maturity( &self, options: TimeOptions, ) -> Result<&Self, ValidationError>
Validates the maturity date (nbf claim).
This method will return an error if the claims do not feature a maturity date,
or if it is in the future (subject to the provided options).