pub fn decode<T: DeserializeOwned>(
    token: &str,
    key: &DecodingKey<'_>,
    validation: &Validation
) -> Result<TokenData<T>>
Expand description

Decode and validate a JWT

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

use serde::{Deserialize, Serialize};
use jsonwebtoken::{decode, DecodingKey, 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_message = decode::<Claims>(&token, &DecodingKey::from_secret("secret".as_ref()), &Validation::new(Algorithm::HS256));