pub struct JwtValidator { /* private fields */ }Expand description
Validates JWTs against a JwtConfig and KeyRegistry.
Implementations§
Source§impl JwtValidator
impl JwtValidator
Sourcepub fn new(config: JwtConfig) -> Self
pub fn new(config: JwtConfig) -> Self
Build a new validator with an empty key registry. Call Self::add_key
for each trusted issuer.
Sourcepub fn add_key(&self, kid: impl Into<String>, alg: Algorithm, key: KeyMaterial)
pub fn add_key(&self, kid: impl Into<String>, alg: Algorithm, key: KeyMaterial)
Register a key for verification.
Sourcepub fn validate(&self, token: &str) -> Result<ValidatedJwt>
pub fn validate(&self, token: &str) -> Result<ValidatedJwt>
Validate a JWT. The kid and alg from the header are used to find
a matching key.
Note: cryptographic verification is implemented for EdDSA (HMAC-like
signature) in this release; RS256/ES256 support requires adding the
jsonwebtoken crate as a feature in v2.1.
Sourcepub async fn refresh_jwks(&self) -> Result<()>
pub async fn refresh_jwks(&self) -> Result<()>
Fetch JWKS from jwks_uri and populate the key registry. Idempotent.
Supports Ed25519 keys (kty=OK, crv=Ed25519, x=base64url-32-bytes). Other key types are skipped with a tracing warning.
Sourcepub fn spawn_jwks_refresher(self: Arc<Self>, interval: Duration)
pub fn spawn_jwks_refresher(self: Arc<Self>, interval: Duration)
Background task that periodically refreshes JWKS.
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for JwtValidator
impl !RefUnwindSafe for JwtValidator
impl Send for JwtValidator
impl Sync for JwtValidator
impl Unpin 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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more