Expand description
JSON Web Token encoding, decoding, and validation with HMAC algorithms.
This crate provides functions to create, verify, and inspect JWTs using HMAC-based signing algorithms (HS256, HS384, HS512). It supports typed custom claims, registered claim validation (expiration, not-before, issuer, audience), and configurable clock skew tolerance.
§Quick Start
use philiprehberger_jwt::{encode, decode, Algorithm, Claims, RegisteredClaims, Validation};
let claims = Claims {
registered: RegisteredClaims::default(),
custom: serde_json::json!({"user": "alice"}),
};
let token = encode(&claims, b"secret", Algorithm::HS256).unwrap();
let decoded: Claims<serde_json::Value> = decode(&token, b"secret", &Validation::default()).unwrap();Structs§
- Claims
- JWT claims combining registered claims with custom typed data.
- Header
- JWT header containing algorithm and type information.
- Registered
Claims - Standard registered JWT claims as defined in RFC 7519.
- Validation
- Configuration for JWT claim validation.
Enums§
- Algorithm
- HMAC signing algorithm used for JWT signatures.
- JwtError
- Errors that can occur during JWT operations.
Functions§
- decode
- Decodes and validates a JWT, returning the typed claims.
- decode_
without_ validation - Decodes claims from a JWT without verifying the signature.
- encode
- Encodes claims into a signed JWT string.
- encode_
simple - Encodes claims using HS256 with
iatautomatically set to the current time. - inspect
- Decodes the JWT header without verifying the signature.