tokenkit
Type-safe JWT encode/decode for Rust with configurable validation, secret rotation, key rotation, and revocation support.
Why?
The jsonwebtoken crate provides low-level JWT primitives but requires manual claim management, validation setup, and doesn't support revocation out of the box. tokenkit builds on top of it with a high-level API, standard claims, and optional revocation support.
Features
- Type-safe claims —
StandardClaimsstruct with serde derives - Configurable algorithms — HS256/384/512, RS256/384/512
- Built-in validation — issuer, audience, expiration checks
- Token revocation — pluggable
TokenRevocationStoretrait with in-memory implementation - JWT helpers —
extract_bearer_token(),build_auth_cookie() - Secret & key rotation — swap
JwtConfigwithout downtime #![forbid(unsafe_code)]— no unsafe code anywhere
Quick Start
use ;
use StandardClaims;
let config = JwtConfig ;
let service = new;
// Encode
let claims = StandardClaims ;
let token = service.encode_standard.unwrap;
// Decode
let decoded = service.decode_standard.unwrap;
assert_eq!;
Revocation
use InMemoryRevocationStore;
use ;
let store = Boxnew;
let service = new.with_revocation;
// Revoke a token by its jti claim
// store.revoke("token-jti").await.unwrap();
Comparison with Raw jsonwebtoken
| Feature | tokenkit |
jsonwebtoken |
|---|---|---|
| Standard claims struct | ✅ | ❌ (manual) |
| Issuer/audience validation | ✅ | Manual setup |
| Token revocation | ✅ | ❌ |
| Bearer token extraction | ✅ | ❌ |
| Cookie builder | ✅ | ❌ |
| Secret rotation support | ✅ | Manual |
forbid(unsafe_code) |
✅ | ❌ |
License
MIT OR Apache-2.0