#jwt #jwk #api-token

jsonwebtoken-jwks-cache

Resilient and blazingly fast async JWK Set cache

2 unstable releases

Uses new Rust 2024

0.2.0 Jan 22, 2026
0.1.0 Oct 20, 2025

#1218 in Web programming

Download history 125/week @ 2025-11-14 153/week @ 2025-11-21 172/week @ 2025-11-28 88/week @ 2025-12-05 102/week @ 2025-12-12 66/week @ 2025-12-19 12/week @ 2025-12-26 737/week @ 2026-01-02 1147/week @ 2026-01-09 1346/week @ 2026-01-16 1434/week @ 2026-01-23 1204/week @ 2026-01-30 1567/week @ 2026-02-06 677/week @ 2026-02-13 788/week @ 2026-02-20 884/week @ 2026-02-27

4,122 downloads per month
Used in rs-firebase-admin-sdk

MIT license

27KB
571 lines

jsonwebtoken-jwks-cache

Resilient and blazingly fast async JWK Set cache

Example

let cache = CachedJWKS::new(
    // strictly follow caching semantics provided by the JWKS URL host
    "https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com"
        .parse()
        .unwrap(),
    // if requested 1hr before token cache gets expired, refresh the cache in the background
    Duration::from_secs(60 * 60),
    // simple timeout strategy
    TimeoutSpec {
        // if encountered network/http error or single try timeout, how many times more to retry
        retries: 3,
        // single try timeout period
        retry_after: Duration::from_seconds(10),
        // how long to wait between retries
        backoff: Duration::from_seconds(1),
        // total timeout deadline
        deadline: Duration::from_seconds(30),
    },
)
.unwrap();

let jwks = cache.get().await.unwrap();

// perform JWT validation here using `jsonwebtoken` crate

Dependencies

~16–26MB
~495K SLoC