Function asap_deps_jsonwebtoken::decode[][src]

pub fn decode<T: DeserializeOwned>(
    token: &str,
    key: &[u8],
    validation: &Validation
) -> Result<TokenData<T>>

Decode a token into a struct containing 2 fields: claims and header.

If the token or its signature is invalid or the claims fail validation, it will return an error.

This example is not tested
#[macro_use]
extern crate serde_derive;
use jsonwebtoken::{decode, Validation, Algorithm};

#[derive(Debug, Serialize, Deserialize)]
struct Claims {
   sub: String,
   company: String
}

let token = "a.jwt.token".to_string();
// Claims is a struct that implements Deserialize
let token_data = decode::<Claims>(&token, "secret", &Validation::new(Algorithm::HS256));