jsonwebtoken/examples/claims.rs

25 lines
551 B
Rust
Raw Normal View History

2015-11-02 18:27:28 -05:00
extern crate jsonwebtoken as jwt;
2015-11-02 15:34:11 -05:00
extern crate rustc_serialize;
use jwt::{
Algorithm,
encode,
decode
};
#[derive(Debug, RustcEncodable, RustcDecodable)]
struct Claims {
sub: String,
company: String
}
fn main() {
let my_claims = Claims {
sub: "b@b.com".to_owned(),
company: "ACME".to_owned()
};
2015-11-02 16:04:58 -05:00
let key = "secret";
let token = encode::<Claims>(my_claims, key.to_owned(), Algorithm::HS256).unwrap();
let claims = decode::<Claims>(token.to_owned(), key.to_owned(), Algorithm::HS256).unwrap();
2015-11-02 15:34:11 -05:00
}