JWKS-Client is a library written in Rust to decode and validate JWT tokens using a JSON Web Key Store.
** IMPORTANT **
JWKS-Client was designed to work with a project that uses Rocket. Unfortunatly, the version of Rocket in crates.io is not compatible with the version of Ring required for JWKS-Client.
To use JWKS-Client with Rocket, use the following dependency in Cargo.toml:
= { = "https://github.com/SergioBenitez/Rocket" }
Furthermore, be aware that JWKS-Client is still being developed. Some (hopefully minor) breaking changes may happen. Sorry about that!
Features
- Download key set from HTTP address
- Decode JWT tokens into header, payload and signature
- Verify token signature, expiry and not-before
- Can transfer header and payload in user-defined struct. See the example below
- Consise results (see error::Type for example)
- Designed for a production system (not an academic project)
- Build with Rust stable
I created this library specifically to decode GCP/Firebase JWT but should be useable with little to no modification. Contact me to propose support for different JWKS key store. Feedback, suggestions, complaints and critisism is appreaciate.
Basic Usage
The following demonstrates how to load a set of keys from an HTTP address and verify a JWT token using those keys:
use KeyStore;
unwrap;
=======
let jkws_url = "https://...";
let key_set = new_from.unwrap;
>>>>>>> fade3478dc6e28ac80b39ddccb3bbe315b87e8ab
// ...
let my_token = "..."; // JWT
match key_store.verify
JWKS-Client offers descriptive error results:
use KeyStore;
use ;
let key_store = new_from.unwrap;
verify
JWKS-Client can decode a JWT payload (claims) into a struct:
use Deserialize;
use ;
=======
let key_set = new;
>>>>>>> fade3478dc6e28ac80b39ddccb3bbe315b87e8ab
let mut key_set = new_from;
let jwt = key_set.decode.unwrap;
let claims = jwt.payload..unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
History
- 0.1.2: (Sorry for the breaking changes)
- Rename module
jwkstokeyset - Renamed struct
JwkstoKeyStore - Expanded documentation a bit
- Fixed some demos
- Rename module
- 0.1.1: Original version
TODO:
- More documentation :P
- Extract expiration time of keys from HTTP request
- Automatically refresh keys in background
(Made with ❤️ with Rust)