Implementation of JSON Web Tokens in Rust.
Put this into your Cargo.toml
:
toml
[dependencies]
frank_jwt = "<current version of frank_jwt>"
And this in your crate root:
```rust extern crate frank_jwt;
use frank_jwt::{Header, Payload, Algorithm, encode, decode}; ```
```rust //HS256 let mut payload = Payload::new(); payload.insert("key1".tostring(), "val1".tostring()); payload.insert("key2".tostring(), "val2".tostring()); let header = Header::new(Algorithm::HS256); let secret = "secret123";
let jwt = encode(header, secret.to_string(), payload.clone());
//RS256 use std::env;
let mut payload = Payload::new(); payload.insert("key1".tostring(), "val1".tostring()); payload.insert("key2".tostring(), "val2".tostring()); let header = Header::new(Algorithm::RS256);
let mut path = env::currentdir().unwrap(); path.push("somefolder"); path.push("myrsa2048key.pem"); let keypath = path.tostr().unwrap().tostring();
let jwt = encode(header, key_path, payload.clone()); ```
Apache 2.0
shell
cargo test
I'm a freelance developer and looking forward to new challenges.
me@gildedhonour.com | gildedhonour.com