chore: reorg

This commit is contained in:
2020-10-17 11:51:44 +08:00
parent 9b6fb8b292
commit d88ab2580a
9 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
use serde::{ Serialize, Deserialize };
use jsonwebtoken::{ encode, decode, Header, Validation, EncodingKey, DecodingKey };
#[derive(Debug, Serialize, Deserialize)]
struct Claims {
sub: String,
company: String,
exp: usize,
}
// https://mp.weixin.qq.com/s/KkcLH42b5vepmPZiwS6g5Q
fn main() -> Result<(), Box<dyn std::error::Error>> {
let my_claims = Claims {
sub: "Test Sub".into(),
company: "Test Company".into(),
exp: 1597546123497,
};
let token = encode(&Header::default(), &my_claims, &EncodingKey::from_secret("secret".as_ref()))?;
// let token = encode(&Header::default(), &my_claims, &EncodingKey::from_secret("secret".as_ref()))?;
// let token = encode(&Header::new(Algorithm::RS256), &my_claims, &EncodingKey::from_rsa_pem(include_bytes!("privkey.pem"))?)?;
println!("Token: {}", token);
let decoded_token = decode::<Claims>(&token, &DecodingKey::from_secret("secret".as_ref()), &Validation::default())?;
println!("Decoded token: {:#?}", decoded_token);
Ok(())
}