decode_token

Function decode_token 

Source
pub fn decode_token(
    token: String,
    key: &DecodingKey,
) -> Result<Claims, (StatusCode, Json<Error>)>
Expand description

Decodes and validates a JSON Web Token (JWT).

This function attempts to decode a JWT string, validate its signature and claims using the provided decoding key. It specifically ignores expiration (validate_exp) and “not before” (validate_nbf) claims during validation. Returns the extracted Claims on success.

§Arguments

  • token: The JWT string to decode.
  • key: The DecodingKey used to verify the JWT’s signature.

§Returns

  • Ok(Claims): If the token is successfully decoded and verified, returns the extracted Claims.
  • Err((StatusCode, Json<Error>)): If the token is invalid, expired, or cannot be decoded, returns an UNAUTHORIZED status code along with a JSON error message.