Expand description
Type-safe JWT encode/decode for Rust with configurable validation, secret rotation, key rotation, and revocation support.
§Quick Start
use tokenkit::service::{JwtConfig, JwtService, JwtAlgorithm};
use tokenkit::claims::StandardClaims;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Claims {
sub: Option<String>,
exp: Option<u64>,
iss: Option<String>,
}
let config = JwtConfig {
algorithm: JwtAlgorithm::HS256,
secret: "my-secret-key".to_string(),
issuer: Some("my-app".to_string()),
..Default::default()
};
let service = JwtService::new(config);
let claims = Claims {
sub: Some("user-123".to_string()),
exp: Some(chrono::Utc::now().timestamp() as u64 + 3600),
iss: Some("my-app".to_string()),
};
let token = service.encode(&claims).unwrap();
let decoded: Claims = service.decode(&token).unwrap();
assert_eq!(decoded.sub.as_deref(), Some("user-123"));Modules§
- claims
- JWT claims types.
- error
- Error types.
- extractors
- Extractors for HTTP authorization headers and cookies.
- jwks
jwks - JWKS fetching and caching with automatic rotation on
kidmiss. JWKS fetching and caching with automatic rotation onkidmiss. - revocation
revocation - Token revocation: pluggable
TokenRevocationStoretrait with in-memory and Redis-backed implementations. - service
- JWT service for encoding, decoding, and validation.