jwt-rust
A rust implementation of JSON Web Tokens.
Examples
Sign
use Claims;
use ;
let mut claims = new;
claims.iss = Some;
let mut token = with_payload;
// custom the header like:
// token.header.cty = Some("application/example".to_owned());
let key = new;
let token = token.sign.unwrap;
assert_eq!;
Verify
use ;
use ;
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzZWEiLCJleHAiOjEwNTc3MDkxMDU2LCJuYmYiOjE1NzcwOTEwNTYsImlhdCI6MTU3NzA5MTA1Nn0.4HwFlFB3LMhVc2xpsGBGSO3ut1KmnFdF8JrsL589ytw";
let key = new;
let verified: = verify_with_key.unwrap;
// use key resolver like:
// let verified: Token<Claims> = Token::verify_with_key_resolver(token, |header, payload| {
// // return a Key here
// }).unwrap();
println!;
// validate claims
let config = ValidationConfig ;
verified.validate_claims.unwrap;
Custom Claims
use ;
extern crate serde_derive;
let claims = CustomClaims ;
let mut token = with_payload;
let key = new;
let token = token.sign.unwrap;
let token: = decode.unwrap; // here decode without verification for demonstration
println!;
Algorithms
Sign and verify use crate ring.
- HS256 - HMAC using SHA-256
- HS384 - HMAC using SHA-384
- HS512 - HMAC using SHA-512
- RS256 - RSASSA-PKCS1-v1_5 using SHA-256
- RS384 - RSASSA-PKCS1-v1_5 using SHA-384
- RS512 - RSASSA-PKCS1-v1_5 using SHA-512
- ES256 - ECDSA using P-256 and SHA-256
- ES384 - ECDSA using P-384 and SHA-384
- ES512 - ECDSA using P-521 and SHA-512
- PS256 - RSASSA-PSS using SHA-256 and MGF1 with SHA-256
- PS384 - RSASSA-PSS using SHA-384 and MGF1 with SHA-384
- PS512 - RSASSA-PSS using SHA-512 and MGF1 with SHA-512
More
RFC 7519 JSON Web Token (JWT)
RFC 7515 JSON Web Signature (JWS)
RFC 7518 JSON Web Algorithms (JWA)