#[non_exhaustive]pub struct JwksCache { /* private fields */ }Expand description
Thread-safe JWKS key cache with automatic refresh.
Includes protections against denial-of-service via invalid JWTs:
- Refresh cooldown: At most one refresh per 10 seconds, regardless of
cache misses. This prevents attackers from flooding the upstream JWKS
endpoint by sending JWTs with fabricated
kidvalues. - Concurrent deduplication: Only one refresh in flight at a time; concurrent waiters share the same fetch result.
Implementations§
Source§impl JwksCache
impl JwksCache
Sourcepub fn new(config: &OAuthConfig) -> Result<Self, Box<dyn Error + Send + Sync>>
pub fn new(config: &OAuthConfig) -> Result<Self, Box<dyn Error + Send + Sync>>
Build a new cache from OAuth configuration.
§Errors
Returns an error if the CA bundle cannot be read or the HTTP client cannot be built.
Sourcepub async fn validate_token(&self, token: &str) -> Option<AuthIdentity>
pub async fn validate_token(&self, token: &str) -> Option<AuthIdentity>
Validate a JWT Bearer token. Returns Some(AuthIdentity) on success.
Sourcepub async fn validate_token_with_reason(
&self,
token: &str,
) -> Result<AuthIdentity, JwtValidationFailure>
pub async fn validate_token_with_reason( &self, token: &str, ) -> Result<AuthIdentity, JwtValidationFailure>
Validate a JWT Bearer token with failure classification.
§Errors
Returns JwtValidationFailure::Expired when the JWT is expired,
or JwtValidationFailure::Invalid for all other validation failures.
Auto Trait Implementations§
impl !Freeze for JwksCache
impl !RefUnwindSafe for JwksCache
impl Send for JwksCache
impl Sync for JwksCache
impl Unpin for JwksCache
impl UnsafeUnpin for JwksCache
impl !UnwindSafe for JwksCache
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
Mutably borrows from an owned value. Read more