[−][src]Function salvo_extra::auth::jwt::decode
pub fn decode<T>(
token: &str,
key: &[u8],
validation: &Validation
) -> Result<TokenData<T>, Error> where
T: DeserializeOwned,
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));