pub struct SecureJwtValidator { /* private fields */ }Implementations§
Source§impl SecureJwtValidator
impl SecureJwtValidator
pub fn new(config: SecureJwtConfig) -> Result<Self>
Sourcepub fn set_on_revoke<F>(&self, callback: F)
pub fn set_on_revoke<F>(&self, callback: F)
Register an optional callback that is invoked with the JTI every time
[revoke_token] is called.
This allows callers to persist revocations to durable storage (database, KV store, etc.) without changing the existing validation or revocation API.
§Example
validator.set_on_revoke(|jti| {
// Persist to your storage backend
storage.insert_revoked_jti(jti);
});Sourcepub fn get_decoding_key(&self) -> DecodingKey
pub fn get_decoding_key(&self) -> DecodingKey
Get HMAC decoding key for backward-compatible call sites.
Prefer validate which handles key selection automatically.
Sourcepub fn get_encoding_key(&self) -> EncodingKey
pub fn get_encoding_key(&self) -> EncodingKey
Get HMAC encoding key for signing JWTs.
Sourcepub fn validate(&self, token: &str) -> Result<SecureJwtClaims>
pub fn validate(&self, token: &str) -> Result<SecureJwtClaims>
Validate a JWT, automatically selecting the key based on the token header algorithm.
This is the preferred entry point. It:
- Decodes the JWT header to determine the claimed algorithm.
- Rejects the token immediately if the algorithm is not in
allowed_algorithms. - Selects the correct decoding key for the algorithm family.
- Validates the signature and all standard claims (exp, nbf, iss, aud).
- Performs additional checks: revocation, max lifetime, JTI presence, token type.
Sourcepub fn validate_token(
&self,
token: &str,
decoding_key: &DecodingKey,
) -> Result<SecureJwtClaims>
pub fn validate_token( &self, token: &str, decoding_key: &DecodingKey, ) -> Result<SecureJwtClaims>
Legacy validation entry point that accepts a caller-supplied decoding key.
Prefer [validate] which handles algorithm checking and key selection internally.
This method still enforces the full allow-list and all claim checks.
Sourcepub fn is_token_revoked(&self, jti: &str) -> Result<bool>
pub fn is_token_revoked(&self, jti: &str) -> Result<bool>
Check whether jti appears in the in-memory revocation list.
This only consults the local cache. For a complete revocation check that
also queries durable storage, combine this with the storage-backed lookup
in the API layer (src/api/auth.rs).
Sourcepub fn revoke_token(&self, jti: &str) -> Result<()>
pub fn revoke_token(&self, jti: &str) -> Result<()>
Revoke a token by its JTI.
The JTI is inserted into the in-memory revocation map. If an
on_revoke callback has been registered, it is
invoked with the JTI after the in-memory insertion, allowing durable
persistence without changing this method’s signature.
Note: Without a registered on_revoke callback, revocations are
volatile and will be lost on process restart.
Sourcepub fn cleanup_revoked_tokens(&self, expired_cutoff: SystemTime) -> Result<()>
pub fn cleanup_revoked_tokens(&self, expired_cutoff: SystemTime) -> Result<()>
Remove revoked token entries that are older than expired_cutoff.
This prevents unbounded memory growth in long-running deployments. Callers should
pass a cutoff equal to now − max_token_lifetime so that every entry that could
still be used by a live token is preserved, while entries that can only correspond
to already-expired tokens are discarded.
An additional size cap (10,000 entries) is enforced after time-based eviction: if the map still exceeds the cap the oldest 25 % of entries are removed.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SecureJwtValidator
impl RefUnwindSafe for SecureJwtValidator
impl Send for SecureJwtValidator
impl Sync for SecureJwtValidator
impl Unpin for SecureJwtValidator
impl UnsafeUnpin for SecureJwtValidator
impl UnwindSafe for SecureJwtValidator
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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