clerk-rs
clerk-rs copied to clipboard
Add JwksProvider to allow for caching of the JWKS
This PR adds a JwksProvider
trait which is used by ClerkAuthorizer
to retrieve JWKs for validating requests.
It provides SimpleJwksProvider
which reqeusts the JWKS from Clerk on every request, and MemoryCacheJwksProvider
that caches the JWKS in memory. The expiration time of MemoryCacheJwksProvider
is optional and configurable. The behavior when an key that isn't in the cache is requested is also configurable: don't refresh the JWKS, always refresh the JWKS, and refresh the JWKS if the cache is older than a certain duration.
This PR also splits validate_jwt
into validate_jwt
which takes a JwksProvider
and validate_jwt_with_key
which takes a JwksKey
. The Axum and Actix middlewares are also updated to take a JwksProvider
instead of a ClerkConfiguration
.
Closes #45.