Decoding our token
We can encode our token with the code below:
// glue/src/token.rs
pub fn decode(token: &str) -> Result<Self, NanoServiceError> {
let key_str = Self::get_key()?;
let key = DecodingKey::from_secret(key_str.as_ref());
let mut validation = Validation::new(Algorithm::HS256);
validation.required_spec_claims.remove("exp");
match decode::<Self>(token, &key, &validation) {
Ok(token_data) => return Ok(token_data.claims),
Err(error) => return Err(
NanoServiceError::new(
error.to_string(),
NanoServiceErrorStatus::Unauthorized
)
)
};
}
Here we can see that we get the key from the environment variable again. We then create a decoding key, with the HS256 algorithm. From this, we can deduce that the default encoding in the previous section was the HS256 algorithm. We then remove the "exp" from the claims. This means that we are...