Update examples and readme for exp use
This commit is contained in:
parent
e725bea1d2
commit
ab0ab9b48b
|
@ -28,7 +28,8 @@ use jwt::{encode, decode, Header, Algorithm, Validation};
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Claims {
|
||||
sub: String,
|
||||
company: String
|
||||
company: String,
|
||||
exp: usize,
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -9,13 +9,15 @@ use jwt::errors::{ErrorKind};
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Claims {
|
||||
sub: String,
|
||||
company: String
|
||||
company: String,
|
||||
exp: usize,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let my_claims = Claims {
|
||||
sub: "b@b.com".to_owned(),
|
||||
company: "ACME".to_owned()
|
||||
company: "ACME".to_owned(),
|
||||
exp: 10000000000,
|
||||
};
|
||||
let key = "secret";
|
||||
|
||||
|
|
|
@ -9,13 +9,15 @@ use jwt::errors::{ErrorKind};
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Claims {
|
||||
sub: String,
|
||||
company: String
|
||||
company: String,
|
||||
exp: usize,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let my_claims = Claims {
|
||||
sub: "b@b.com".to_owned(),
|
||||
company: "ACME".to_owned()
|
||||
company: "ACME".to_owned(),
|
||||
exp: 10000000000,
|
||||
};
|
||||
let key = "secret";
|
||||
let token = match encode(&Header::default(), &my_claims, key.as_ref()) {
|
||||
|
@ -27,13 +29,12 @@ fn main() {
|
|||
sub: Some("b@b.com".to_string()),
|
||||
..Validation::default()
|
||||
};
|
||||
|
||||
let token_data = match decode::<Claims>(&token, key.as_ref(), &validation) {
|
||||
Ok(c) => c,
|
||||
Err(err) => match *err.kind() {
|
||||
ErrorKind::InvalidToken => panic!(), // Example on how to handle a specific error
|
||||
ErrorKind::InvalidIssuer => panic!(), // Example on how to handle a specific error
|
||||
_ => panic!()
|
||||
ErrorKind::InvalidToken => panic!("Token is invalid"), // Example on how to handle a specific error
|
||||
ErrorKind::InvalidIssuer => panic!("Issuer is invalid"), // Example on how to handle a specific error
|
||||
_ => panic!("Some other errors")
|
||||
}
|
||||
};
|
||||
println!("{:?}", token_data.claims);
|
||||
|
|
Loading…
Reference in New Issue