jwt_boiler

Crates.iojwt_boiler
lib.rsjwt_boiler
version0.1.1
sourcesrc
created_at2022-11-02 12:45:01.519063
updated_at2023-01-25 16:51:19.803523
descriptionBoilerplate for jwt signing and decrypting.
homepage
repositoryhttps://github.com/enokson/jwt-boiler
max_upload_size
id703455
size6,108
Joshua Enokson (enokson)

documentation

README

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));
Commit count: 6

cargo fmt