Claims

Struct Claims 

Source
pub struct Claims {
    pub iss: String,
    pub sub: String,
    pub aud: String,
    pub exp: Option<u64>,
    pub nbf: u64,
    pub iat: u64,
}
Expand description

Represents registered JSON Web Token Claims. https://tools.ietf.org/html/rfc7519#section-4.1

Fields§

§iss: String

Issuer. Identifies the principal that issued the JWT. The processing of this claim is generally application specific.

§sub: String

Subject. Identifies the principal that is the subject of the JWT. The claims in a JWT are normally statements about the subject. The subject value MUST either be scoped to be locally unique in the context of the issuer or be globally unique. The processing of this claim is generally application specific.

§aud: String

Audience. Identifies the recipients that the JWT is intended for. Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the “aud” claim when this claim is present, then the JWT MUST be rejected. The interpretation of audience values is generally application specific.

§exp: Option<u64>

Expiration Time. Identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing of the “exp” claim requires that the current date/time MUST be before the expiration date/time listed in the “exp” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew.

§nbf: u64

Not Before. Identifies the time before which the JWT MUST NOT be accepted for processing. The processing of the “nbf” claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the “nbf” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew.

§iat: u64

Issued At. Identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT.

Implementations§

Source§

impl Claims

Source

pub fn new( iss: impl Into<String>, sub: impl Into<String>, aud: impl Into<String>, ) -> Result<Self, Error>

Creates a new set of claims.

Source

pub fn expires_after(self, exp: u64) -> Result<Self, Error>

Specify that this token will expire by providing an expiry timestamp.

Source

pub fn expires_after_duration(self, dur: Duration) -> Result<Self, Error>

Specify that this token will expire by providing a duration offset from issued time.

Source

pub fn valid_after(self, nbf: u64) -> Result<Self, Error>

Specify that this token is valid after the given timestamp.

Source

pub fn valid_after_duration(self, dur: Duration) -> Result<Self, Error>

Specify when this token becomes valid by providing a duration offset from issued time.

Source

pub fn issuer(&self) -> &str

Returns the issuer of the JWT.

Source

pub fn subject(&self) -> &str

Returns the subject of the JWT.

Source

pub fn audience(&self) -> &str

Returns the audience of the JWT.

Source

pub fn expiry(&self) -> Option<u64>

Returns the expiration time of the JWT, if it has been specified.

Source

pub fn not_before(&self) -> u64

Returns the “nbf” field of the JWT.

Source

pub fn issued_at(&self) -> u64

Returns the issue timestamp of the JWT.

Trait Implementations§

Source§

impl Debug for Claims

Source§

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

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

impl<'de> Deserialize<'de> for Claims

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 Serialize for Claims

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 Freeze for Claims

§

impl RefUnwindSafe for Claims

§

impl Send for Claims

§

impl Sync for Claims

§

impl Unpin for Claims

§

impl UnwindSafe for Claims

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

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