| Crates.io | frank_jwt |
| lib.rs | frank_jwt |
| version | 3.1.4 |
| created_at | 2015-07-27 10:07:27.588792+00 |
| updated_at | 2025-07-12 13:38:47.457766+00 |
| description | Implementation of JSON JWT |
| homepage | https://github.com/GildedHonour/frank_jwt |
| repository | https://github.com/GildedHonour/frank_jwt |
| max_upload_size | |
| id | 2695 |
| size | 62,440 |
Implementation of JSON Web Tokens in Rust.
Put this into your Cargo.toml:
[dependencies]
frank_jwt = "<current version of frank_jwt>"
And this in your crate root:
extern crate frank_jwt;
#[macro_use] extern crate serde_json;
use frank_jwt::{Algorithm, encode, decode};
//HS256
let mut payload = json!({
"key1": "val1",
"key2": "val2"
});
let mut header = json!({});
let secret = "secret123";
let jwt = encode(&header, secret.to_string(), &payload, Algorithm::HS256);
//RS256
use std::env;
let mut payload = json!({
"key1": "val1",
"key2": "val2"
});
let mut header = json!({});
let mut keypath = env::current_dir().unwrap();
keypath.push("some_folder");
keypath.push("my_rsa_2048_key.pem");
let jwt = encode(&header, &keypath.to_path_buf(), &payload, Algorithm::RS256);
let (header, payload) = decode(&jwt, &keypath.to_path_buf(), Algorithm::RS256, &ValidationOptions::default());
The ValidationOptions structure allows for control over which checks should be preformed when decoding a JWT. Calling new on this will provide a default set of values. There is also a dangerous function that will return validation options that doesn't perform any checking.
The default values are:
It's worth noting that if the expiry check is requested and an exp claim is not within the JWT the check will fail validation.
Apache 2.0
cargo test
TODO