frank_jwt 2.6.0

Implementation of JSON JWT
Documentation

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;

use frank_jwt::{Header, Payload, Algorithm, encode, decode};

Example

//HS256
let mut payload = Payload::new();
payload.insert("key1".to_string(), "val1".to_string());
payload.insert("key2".to_string(), "val2".to_string());
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".to_string(), "val1".to_string());
payload.insert("key2".to_string(), "val2".to_string());
let header = Header::new(Algorithm::RS256);

let mut path = env::current_dir().unwrap();
path.push("some_folder");
path.push("my_rsa_2048_key.pem");
let key_path = path.to_str().unwrap().to_string();

let jwt = encode(header, key_path, payload.clone());

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