pub struct KeyResolver { /* private fields */ }Expand description
This struct provides methods to resolve JWT decoding keys from various sources.
The KeyResolver is responsible for fetching and caching JSON Web Keys (JWK)
from OpenID Connect providers. It supports:
- OpenID Connect Discovery via the standard
.well-known/openid-configurationendpoint - Direct retrieval from the
.well-known/jwks.jsonendpoint as a fallback - Caching of retrieved keys to minimize network requests
Example usage:
let resolver = KeyResolver::new()
.with_jwks_ttl(Duration::from_secs(1800)); // 30 minute cache TTL
let jwt = Jwt::builder()
.issuer("https://your-oidc-provider.com")
.key_resolver(resolver)
.build()?;Implementations§
Source§impl KeyResolver
impl KeyResolver
pub fn with_jwks(jwks: JwkSet) -> Self
Sourcepub fn with_jwks_ttl(self, ttl: Duration) -> Self
pub fn with_jwks_ttl(self, ttl: Duration) -> Self
Set the default TTL for cached JWKS
Sourcepub async fn resolve_key(
&self,
issuer: &str,
token_header: &Header,
) -> Result<DecodingKey, AuthError>
pub async fn resolve_key( &self, issuer: &str, token_header: &Header, ) -> Result<DecodingKey, AuthError>
Resolve a decoding key from various sources
This function will attempt to resolve the key in the following order:
- If a decoding key is already provided, return it
- If a kid (Key ID) is specified in the token header, fetch the key from the JWKS endpoint
- If no kid is specified, use the first suitable key from the JWKS endpoint
§Arguments
issuer- The token issuer URLtoken_header- The JWT header containing the algorithm and key ID (if available)
Sourcepub fn get_cached_key(
&self,
issuer: &str,
token_header: &Header,
) -> Result<DecodingKey, AuthError>
pub fn get_cached_key( &self, issuer: &str, token_header: &Header, ) -> Result<DecodingKey, AuthError>
Check the cache for a JWKS entry
Trait Implementations§
Source§impl Debug for KeyResolver
impl Debug for KeyResolver
Auto Trait Implementations§
impl !Freeze for KeyResolver
impl !RefUnwindSafe for KeyResolver
impl !UnwindSafe for KeyResolver
impl Send for KeyResolver
impl Sync for KeyResolver
impl Unpin for KeyResolver
impl UnsafeUnpin for KeyResolver
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> 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