Crates.io | jwt_boiler |
lib.rs | jwt_boiler |
version | 0.1.1 |
source | src |
created_at | 2022-11-02 12:45:01.519063 |
updated_at | 2023-01-25 16:51:19.803523 |
description | Boilerplate for jwt signing and decrypting. |
homepage | |
repository | https://github.com/enokson/jwt-boiler |
max_upload_size | |
id | 703455 |
size | 6,108 |
Boilerplate code for JWT token signing and decrypting.
[dependencies]
boiler-jwt = "0.1.0"
use boiler_jwt::{to_token, from_token, to_value, from_value};
let app_secret = "my-secret";
let user_id = 1;
// create a jwt with a BTreeMap<String, Value> containing an "id" field
let jwt = to_token(app_secret, [
("id".into(), to_value(user_id).unwrap())
].into()).unwrap();
// convert back to a BTreeMap<String, Value>
let mut claims = from_token(app_secret, &jwt).unwrap();
assert_eq!(1, from_value::<i32>(claims.remove("id").unwrap()).unwrap());
use boiler_jwt::{to_hash, verify};
let pass = "foo";
let hash = to_hash(pass);
assert!(verify(pass, &hash));
assert!(!verify("bar", &hash));