2 releases
0.1.1 | Jan 25, 2023 |
---|---|
0.1.0 | Nov 2, 2022 |
#1856 in Cryptography
5KB
64 lines
boiler-jwt
Boilerplate code for JWT token signing and decrypting.
Add to Cargo.toml
[dependencies]
boiler-jwt = "0.1.0"
JWT Signing and Verifying Example
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());
Password Hashing and Verifying Example
use boiler_jwt::{to_hash, verify};
let pass = "foo";
let hash = to_hash(pass);
assert!(verify(pass, &hash));
assert!(!verify("bar", &hash));
Dependencies
~1.6–2.5MB
~53K SLoC