pub struct JwtValidator { /* private fields */ }Expand description
The set of claim checks applied after a JWT’s signature verifies.
All checks are opt-in except signature and exp: if you set no issuer,
the iss claim is not checked; likewise for audience. For anything beyond
a demo, set both.
Implementations§
Source§impl JwtValidator
impl JwtValidator
Sourcepub fn new() -> JwtValidator
pub fn new() -> JwtValidator
Creates a validator that checks signature and exp only.
Sourcepub fn with_issuer(self, issuer: impl Into<String>) -> JwtValidator
pub fn with_issuer(self, issuer: impl Into<String>) -> JwtValidator
Requires the token’s iss to equal one of the accepted issuers.
Sourcepub fn with_audience(self, audience: impl Into<String>) -> JwtValidator
pub fn with_audience(self, audience: impl Into<String>) -> JwtValidator
Requires the token’s aud to contain one of the accepted audiences.
Sourcepub const fn with_leeway(self, leeway: Duration) -> JwtValidator
pub const fn with_leeway(self, leeway: Duration) -> JwtValidator
Sets the clock-skew leeway for exp/nbf (default 60 s).
Sourcepub const fn allow_missing_exp(self) -> JwtValidator
pub const fn allow_missing_exp(self) -> JwtValidator
Allows tokens without an exp claim (default: exp is required).
Sourcepub fn with_hs256_secret(self, secret: impl Into<Vec<u8>>) -> JwtValidator
pub fn with_hs256_secret(self, secret: impl Into<Vec<u8>>) -> JwtValidator
Sets a shared secret for verifying HS256 tokens.
HS256 is only ever checked against this secret — never against a JWKS public key — which is what makes the RS256→HS256 confusion attack impossible.
Trait Implementations§
Source§impl Clone for JwtValidator
impl Clone for JwtValidator
Source§fn clone(&self) -> JwtValidator
fn clone(&self) -> JwtValidator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JwtValidator
impl Debug for JwtValidator
Source§impl Default for JwtValidator
impl Default for JwtValidator
Source§fn default() -> JwtValidator
fn default() -> JwtValidator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for JwtValidator
impl RefUnwindSafe for JwtValidator
impl Send for JwtValidator
impl Sync for JwtValidator
impl Unpin for JwtValidator
impl UnsafeUnpin for JwtValidator
impl UnwindSafe for JwtValidator
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request