13 stable releases

3.1.1 May 23, 2019
3.1.0 Dec 7, 2018
3.0.2 Sep 28, 2018
3.0.0 Jan 10, 2018
2.1.0 Jul 30, 2015

#2 in #encryption

Download history 356/week @ 2019-04-23 272/week @ 2019-04-30 379/week @ 2019-05-07 499/week @ 2019-05-14 335/week @ 2019-05-21 668/week @ 2019-05-28 384/week @ 2019-06-04 634/week @ 2019-06-11 411/week @ 2019-06-18 357/week @ 2019-06-25 427/week @ 2019-07-02 551/week @ 2019-07-09 321/week @ 2019-07-16 207/week @ 2019-07-23 299/week @ 2019-07-30

1,754 downloads per month
Used in 3 crates

Apache-2.0

34KB
677 lines

Frank JWT Build Status crates.io

Implementation of JSON Web Tokens in Rust.

Algorithms and features supported

  • HS256
  • HS384
  • HS512
  • RS256
  • RS384
  • RS512
  • ES256
  • ES384
  • ES512
  • Sign
  • Verify
  • iss (issuer) check
  • sub (subject) check
  • aud (audience) check
  • exp (expiration time) check
  • nbf (not before time) check
  • iat (issued at) check
  • jti (JWT id) check

Usage

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};

Example

//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);

License

Apache 2.0

Tests

cargo test

I'm available for hire

I'm a freelance developer and looking forward to new challenges.

me@gildedhonour.com | gildedhonour.com

Contributors

todo

Dependencies

~2MB
~43K SLoC