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: TheDecodingKeyused to verify the JWT’s signature.
§Returns
Ok(Claims): If the token is successfully decoded and verified, returns the extractedClaims.Err((StatusCode, Json<Error>)): If the token is invalid, expired, or cannot be decoded, returns anUNAUTHORIZEDstatus code along with a JSON error message.