pub struct JwksClient { /* private fields */ }Expand description
JWKS client with automatic caching.
Fetches public keys from a JWKS endpoint and caches them for efficient token validation. Keys are automatically refreshed when the cache expires.
§Example
ⓘ
let client = JwksClient::new(
"https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com".to_string(),
3600, // 1 hour cache TTL
);
// Get key by ID from token header
let key = client.get_key("abc123").await?;Implementations§
Source§impl JwksClient
impl JwksClient
Sourcepub fn new(url: String, cache_ttl_secs: u64) -> Self
pub fn new(url: String, cache_ttl_secs: u64) -> Self
Create a new JWKS client.
§Arguments
url- The JWKS endpoint URLcache_ttl_secs- How long to cache keys (in seconds)
Sourcepub async fn get_key(&self, kid: &str) -> Result<DecodingKey, JwksError>
pub async fn get_key(&self, kid: &str) -> Result<DecodingKey, JwksError>
Get a decoding key by key ID.
This will return a cached key if available and not expired, otherwise it will fetch fresh keys from the JWKS endpoint.
Sourcepub async fn get_any_key(&self) -> Result<DecodingKey, JwksError>
pub async fn get_any_key(&self) -> Result<DecodingKey, JwksError>
Get any available key (for tokens without kid header).
Some providers don’t include a key ID in tokens. This method returns the first available key from the JWKS.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JwksClient
impl !RefUnwindSafe for JwksClient
impl Send for JwksClient
impl Sync for JwksClient
impl Unpin for JwksClient
impl !UnwindSafe for JwksClient
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> 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 more