Struct Validation

Source
pub struct Validation {
    pub leeway: u64,
    pub validate_exp: bool,
    pub validate_nbf: bool,
    pub aud: Option<Vec<String>>,
    pub iss: Option<Vec<String>>,
    pub validate_signature: bool,
    pub algs: Vec<Algorithm>,
}
Expand description

Defines the jwt validation parameters (with defaults simplifying configuration).

Fields§

§leeway: u64

Add some leeway (in seconds) to the exp and nbf validation to account for clock skew.

Defaults to 60.

§validate_exp: bool

Whether to validate the exp field.

Defaults to true.

§validate_nbf: bool

Whether to validate the nbf field.

Defaults to false.

§aud: Option<Vec<String>>

If it contains a value, the validation will check that the aud claim value is in the values provided.

Defaults to None.

§iss: Option<Vec<String>>

If it contains a value, the validation will check that the iss claim value is in the values provided.

Defaults to None.

§validate_signature: bool

Whether to validate the JWT signature. Very insecure to turn that off!

Defaults to true.

§algs: Vec<Algorithm>

Accepted algorithms

If empty anly the algorithms matching key will be authorized

Implementations§

Source§

impl Validation

Source

pub fn new() -> Self

new Validation with default values

Source

pub fn iss<T: ToString>(self, items: &[T]) -> Self

check that the iss claim is a member of the values provided

Source

pub fn aud<T: ToString>(self, items: &[T]) -> Self

check that the aud claim is a member of the items provided

Source

pub fn exp(self, val: bool) -> Self

enables or disables exp validation

Source

pub fn nbf(self, val: bool) -> Self

enables or disables nbf validation

Source

pub fn leeway(self, value: u64) -> Self

Add some leeway (in seconds) to the exp and nbf validation to account for clock skew.

Source

pub fn disable_validation(self) -> Self

Whether to validate the JWT cryptographic signature Very insecure to turn that off, only do it if you know what you’re doing.

Source

pub fn algs(self, algs: Vec<Algorithm>) -> Self

Authorized algorithms.

If no algs are supplied default algs for the key will be used (example for a EC key, algs = [ES256, ES384]).

Trait Implementations§

Source§

impl Default for Validation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,