jwk-box
A simple, async JWK (JSON Web Key) client for Rust that fetches public keys from a JWKS endpoint to validate JWT tokens with automatic key refresh.
Features
- Automatic key refresh
- Reactive key refresh
- JWT validation
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
use JwkClient;
use ;
async
Configuration
You can customize the refresh behavior:
use Duration;
let mut client = new;
// Set how long before keys are marked stale (default: 1 hour)
client.set_auto_refresh_interval;
// Set rate limit for reactive retries after validation failure (default: 5 minutes)
client.set_retry_rate_limit;
How it Works
- Proactive key refresh: Keys are automatically refreshed before token validation if they haven't been refreshed within the
auto_refresh_interval(default: 1 hour) - Reactive key refresh/retry: If token validation fails, the client will refresh keys and retry once, but only if the last retry was longer ago than
retry_rate_limit - Key Validation: Keys with an
nbf(not before) claim are only used after that time has passed - JWT Validation: Uses jwt-simple for token parsing and verification
API Documentation
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.