pub struct Claims {
inner: Map<String, Value>,
}Expand description
Represents a set of claims made by a JWT.
Fields§
§inner: Map<String, Value>Implementations§
Source§impl Claims
impl Claims
pub fn new() -> Self
Sourcepub fn check<'s, V: Deserialize<'s>>(
self,
name: &'static str,
expectation: impl FnOnce(&'static str, Option<V>) -> Result<(), Error>,
) -> Result<Self, Error>
pub fn check<'s, V: Deserialize<'s>>( self, name: &'static str, expectation: impl FnOnce(&'static str, Option<V>) -> Result<(), Error>, ) -> Result<Self, Error>
Checks that the claim with name meets the given expectation, and removes it from the
set. The Deserializer is given ownership of the claim’s contents, so for V you
probably want to use an owned type like String instead of &str.
Sourcepub fn check_present_and<'s, V: Deserialize<'s>>(
self,
name: &'static str,
expectation: impl FnOnce(&'static str, V) -> Result<(), Error>,
) -> Result<Self, Error>
pub fn check_present_and<'s, V: Deserialize<'s>>( self, name: &'static str, expectation: impl FnOnce(&'static str, V) -> Result<(), Error>, ) -> Result<Self, Error>
Check that the claim with name exists and meets the given expectation,
removing the claim from the set afterwards. Variation on Claims::check.
Sourcepub fn check_no(self, name: &'static str) -> Result<Self, Error>
pub fn check_no(self, name: &'static str) -> Result<Self, Error>
Checks that there is no claim with name.
Sourcepub fn extract<V: DeserializeOwned>(
&mut self,
name: &'static str,
) -> Result<Option<V>, Error>
pub fn extract<V: DeserializeOwned>( &mut self, name: &'static str, ) -> Result<Option<V>, Error>
Returns the contents of claim with name, if it exists, enabling manual checking.
Sourcepub fn ignore(self, name: &'static str) -> Self
pub fn ignore(self, name: &'static str) -> Self
Removes named claim from this set, if present, effectively ignoring it.
Sourcepub fn check_iss(
self,
expectation: impl FnOnce(&'static str, Option<String>) -> Result<(), Error>,
) -> Result<Self, Error>
pub fn check_iss( self, expectation: impl FnOnce(&'static str, Option<String>) -> Result<(), Error>, ) -> Result<Self, Error>
Self::check for iss claim.
Sourcepub fn check_sub(
self,
expectation: impl FnOnce(&'static str, Option<String>) -> Result<(), Error>,
) -> Result<Self, Error>
pub fn check_sub( self, expectation: impl FnOnce(&'static str, Option<String>) -> Result<(), Error>, ) -> Result<Self, Error>
Self::check for sub claim.
Sourcepub fn default_check_timestamps(self) -> Result<Self, Error>
pub fn default_check_timestamps(self) -> Result<Self, Error>
Checks timestamps iat, exp and nbf. When present they should be a valid
NumericDate, and the current moment should be between nbf and exp.
Sourcepub fn default_check_common_claims(self) -> Result<Self, Error>
pub fn default_check_common_claims(self) -> Result<Self, Error>
Checks and removes iat, exp, and nbf, and makes sure
sub and iss have already been checked (i.e. are no longer present).
Sourcepub fn visit_custom<C: DeserializeOwned, R>(
self,
visitor: impl FnOnce(C) -> R,
) -> Result<R, Error>
pub fn visit_custom<C: DeserializeOwned, R>( self, visitor: impl FnOnce(C) -> R, ) -> Result<R, Error>
Deserializes remaining, custom, claims into a type C and calls the given visitor function on it.
Will call Claims::default_check_common_claims first, checking iat, etc..
We can, in general, not return C directly, because C might borrow from the
Deserializer.
For the caller’s convenience, we pass along anything that’s returned by the visitor.
Consumes self to prevent deserializing to C twice.
Sourcepub fn into_custom<C: DeserializeOwned>(self) -> Result<C, Error>
pub fn into_custom<C: DeserializeOwned>(self) -> Result<C, Error>
Like Self::visit_custom, but returns C (which is not possible when C borrows from its
Deserializer.)
Sourcepub fn from_custom<C: Serialize>(claims: C) -> Result<Self, Error>
pub fn from_custom<C: Serialize>(claims: C) -> Result<Self, Error>
Creates new Claims from an object that serializes to a json map.
Sourcepub fn claim<V: Serialize>(
self,
name: &'static str,
value: V,
) -> Result<Self, Error>
pub fn claim<V: Serialize>( self, name: &'static str, value: V, ) -> Result<Self, Error>
Adds the named claim with the given value. Returns an error when a claim with the same name was already present.
Sourcepub fn exp_after(self, duration: Duration) -> Result<Self, Error>
pub fn exp_after(self, duration: Duration) -> Result<Self, Error>
Sets exp claim such that the jwt is valid for the given duration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Claims
impl RefUnwindSafe for Claims
impl Send for Claims
impl Sync for Claims
impl Unpin for Claims
impl UnsafeUnpin for Claims
impl UnwindSafe for Claims
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more