Revoke Auth
Revoke Auth is a high-performance JWT authentication library for Axum web applications, built with pure Rust. It provides seamless JWT token validation with JWKS (JSON Web Key Set) support and custom claims extraction.
Features
- JWT Token Validation: Secure JWT token validation with RS256 algorithm support
- JWKS Integration: Automatic public key fetching and caching from JWKS endpoints
- High Performance: Built on tokio async runtime with efficient key caching
- Custom Claims: Support for custom JWT claims through trait implementation
- Axum Integration: Native Axum extractor for seamless authentication middleware
- Zero Copy: Minimal allocations and efficient memory usage
Installation
Add this to your Cargo.toml:
[]
= "0.5.0"
= "0.8"
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
Quick Start
1. Define Your Claims
First, implement the JwtClaims trait for your custom claims structure:
use JwtClaims;
use ;
2. Setup Application State
Configure your application with JWKS store and authentication config:
use ;
use ;
async
3. Protected Route Handlers
Use the Auth<T> extractor in your route handlers:
use ;
use ;
// Protected route that requires authentication
async
4. Client Usage
Send requests with JWT tokens in the Authorization header:
Configuration
AuthConfig Options
| Field | Type | Description | Required |
|---|---|---|---|
issuer |
String |
JWT issuer URL | Yes |
audience |
Option<String> |
Expected audience claim | No |
Error Handling
The library returns HTTP status codes for different error conditions:
401 Unauthorized: Invalid or missing JWT token401 Unauthorized: Token validation failed (expired, wrong issuer, etc.)401 Unauthorized: JWKS key not found for token
API Reference
JwtClaims
A trait that must be implemented by your custom claims structure:
Auth
An Axum extractor for extracting authenticated claims from requests.
JwksStore
Manages JWKS key fetching and caching:
AuthConfig
Configuration for JWT validation:
Security Best Practices
- Use HTTPS for JWKS URLs and API endpoints
- Validate issuer and audience claims
- Implement proper key rotation
- Use reasonable token expiration times
- Apply proper CORS and security headers
Compatibility
- Axum: 0.8+
- Tokio: 1.0+
- Rust: 1.70+ (2024 edition)
License
This project is licensed under either Apache License 2.0 or MIT license at your option.