turul-jwt-validator
Generic JWT validator with JWKS caching and kid-miss refresh. No
protocol-specific dependencies — use it from any async Rust project that
needs to verify bearer tokens against a JWKS endpoint.
Features
- Signature verification via [
jsonwebtoken] with theaws_lc_rsbackend.- Default allowlist:
RS256,ES256. Both exercised by the integration suite. - Opt-in via
.with_algorithms(...):RS384,RS512,ES384. Code paths exist and the JWKS parser accepts them, but integration coverage is RS256 + ES256 only. Adopters that enable the extras should extend the test matrix in their own project.
- Default allowlist:
- JWKS fetched over HTTPS with an in-memory cache, a configurable
refresh interval, and automatic refetch on
kidcache miss. - Audience and issuer claim enforcement.
- Expiration (
exp) validation. - Extra-claims extraction via
serde_json::Value. - Cross-check: the token's
algheader must match the JWKS-advertisedalgfor the matchingkid. This blocks algorithm-confusion attacks where a caller submits an HS256 token using a public key as the HMAC secret.
Usage
use Duration;
use JwtValidator;
async
A runnable version lives at
examples/validate-token.rs and reads
the JWKS URL, audience, and token from environment variables:
TURUL_JWKS=https://auth.example.com/.well-known/jwks.json \
TURUL_AUDIENCE=my-audience \
TURUL_TOKEN='eyJhbGc...' \
AWS Lambda builds — Zig version pin
This crate enables jsonwebtoken's aws_lc_rs backend, which links
aws-lc-sys (C code built via cc-rs). cargo lambda build delegates
to cargo-zigbuild, whose ar shim currently requires Zig 0.15.x —
Zig 0.16 broke it, and every cc-rs-built crate (aws-lc-sys, ring,
…) fails to archive. This is a Zig-version issue, not a platform issue:
macOS and Linux are both affected if Zig 0.16+ is first on PATH.
Until cargo-zigbuild ships Zig 0.16 support, put Zig 0.15 ahead of any
newer Zig on your build host's PATH:
# macOS (Homebrew):
# Linux: install Zig 0.15.x from a distro package, an upstream
# tarball, or asdf, and ensure it resolves first on PATH.
If Zig 0.15.x is the only Zig on your host, no action needed. Remove
the pin once cargo-zigbuild announces 0.16 compatibility.
Compatibility
- MSRV: Rust 1.85 (
rust-versioninCargo.toml). - Edition: 2024.
- Semver policy: this is a
0.xcrate. Minor bumps (0.1.x→0.2.0) may introduce breaking changes; patch bumps are additive or bug-fix only.
See also
turul-a2a-auth— A2A bearer/JWT middleware built on this validator.turul-a2a— A2A (Agent-to-Agent) Protocol framework, first adopter of this crate.
License
Dual-licensed under MIT OR Apache 2.0 at your option.