| Crates.io | jwt-lab |
| lib.rs | jwt-lab |
| version | 0.1.1 |
| created_at | 2025-10-07 09:38:46.981836+00 |
| updated_at | 2025-10-07 09:45:41.012135+00 |
| description | JWT crate for Rust: decode, verify, sign, mutate, JWK/JWKS, algorithm selection, time validation, and secure APIs. |
| homepage | https://github.com/nyakiomaina/jwt-lab |
| repository | https://github.com/nyakiomaina/jwt-lab |
| max_upload_size | |
| id | 1871419 |
| size | 64,434 |
JWT crate for Rust. Decode, verify, sign, mutate, select keys from JWKS by kid, validate times with leeway, and choose algorithms with feature flags.
exp and nbf claimsAdd to your Cargo.toml:
[dependencies]
jwt-lab = "0.1"
use jwt_lab::{Jwt, Key, VerifyOptions, Algorithm};
// Decode and verify a JWT
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
let jwt = Jwt::decode(token)?;
// Always validate the algorithm to prevent alg confusion attacks
jwt.verify(
&Key::hs("secret"),
VerifyOptions::default()
.expect_alg(Algorithm::HS256)
.leeway(30)
)?;
use jwt_lab::{Jwt, Jwks, VerifyOptions};
let jwks = Jwks::from_str(&std::fs::read_to_string("jwks.json")?)?;
let jwt = Jwt::decode(token)?;
jwt.verify_with_jwks(&jwks, VerifyOptions::default())?;
use jwt_lab::{Algorithm, Header, Claims, Key};
use jwt_lab::sign::sign;
use serde_json::json;
let header = Header {
alg: Algorithm::HS256,
typ: Some("JWT".into()),
kid: None,
extra: Default::default()
};
let claims = Claims(serde_json::from_value(json!({
"sub": "user123",
"iat": 1516239022,
"exp": 1516242622
}))?);
let token = sign(&header, &claims, &Key::hs("secret"))?;
⚠️ Important Security Notes:
alg: "none"hs - Enable HMAC algorithms (HS256, HS384, HS512)rs - Enable RSA algorithms (RS256, RS384, RS512)es - Enable ECDSA algorithms (ES256, ES384, ES512)eddsa - Enable EdDSA algorithmjwk - Enable JWK/JWKS supportexplain - Enable detailed error explanationsLicensed under the MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT).