pub struct RemoteJwksDecoder { /* private fields */ }Expand description
JWT decoder that fetches and caches keys from a remote JWKS endpoint.
Automatically fetches JWKS from the specified URL, caches keys by their kid (key ID),
and periodically refreshes them. Includes retry logic for robustness.
§Example
ⓘ
use axum_jwt_auth::RemoteJwksDecoder;
use jsonwebtoken::{Algorithm, Validation};
let decoder = RemoteJwksDecoder::builder()
.jwks_url("https://example.com/.well-known/jwks.json".to_string())
.validation(Validation::new(Algorithm::RS256))
.build()
.unwrap();
// Spawn background refresh task
let decoder_clone = decoder.clone();
tokio::spawn(async move {
decoder_clone.refresh_keys_periodically().await;
});Implementations§
Source§impl RemoteJwksDecoder
impl RemoteJwksDecoder
Sourcepub fn new(jwks_url: String) -> Result<Self, Error>
pub fn new(jwks_url: String) -> Result<Self, Error>
Creates a new RemoteJwksDecoder with the given JWKS URL and default settings.
§Errors
Returns Error::Configuration if the builder fails to construct the decoder.
Sourcepub fn builder() -> RemoteJwksDecoderBuilder
pub fn builder() -> RemoteJwksDecoderBuilder
Creates a new builder for configuring a remote JWKS decoder.
Sourcepub async fn refresh_keys_periodically(&self)
pub async fn refresh_keys_periodically(&self)
Runs an infinite loop that periodically refreshes the JWKS cache.
This method never returns and should be spawned in a background task using tokio::spawn.
Refresh failures are logged, and the decoder continues using stale keys until the next
successful refresh.
§Example
ⓘ
let decoder = RemoteJwksDecoder::builder()
.jwks_url("https://example.com/.well-known/jwks.json".to_string())
.build()
.unwrap();
let decoder_clone = decoder.clone();
tokio::spawn(async move {
decoder_clone.refresh_keys_periodically().await;
});Trait Implementations§
Source§impl Clone for RemoteJwksDecoder
impl Clone for RemoteJwksDecoder
Source§fn clone(&self) -> RemoteJwksDecoder
fn clone(&self) -> RemoteJwksDecoder
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 moreSource§impl<T> JwtDecoder<T> for RemoteJwksDecoderwhere
T: for<'de> DeserializeOwned,
impl<T> JwtDecoder<T> for RemoteJwksDecoderwhere
T: for<'de> DeserializeOwned,
Source§fn decode<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<TokenData<T>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn decode<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<TokenData<T>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Decodes and validates a JWT token string, returning the parsed claims. Read more
Auto Trait Implementations§
impl Freeze for RemoteJwksDecoder
impl !RefUnwindSafe for RemoteJwksDecoder
impl Send for RemoteJwksDecoder
impl Sync for RemoteJwksDecoder
impl Unpin for RemoteJwksDecoder
impl !UnwindSafe for RemoteJwksDecoder
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