Verifying a signature is not verifying a token
pythonA valid signature only proves somebody with the key minted it. Without the audience and expiry checks, a token for another service and a token from last year both sail through.
import jwt claims = jwt.decode( token, key=PUBLIC_KEY, # Never read the algorithm from the token's own header: that is how # an attacker re-signs it with "alg": "none" or with HMAC. algorithms=["RS256"], audience="cyberscallywags.org", issuer="https://auth.cyberscallywags.org", options={"require": ["exp", "iat", "aud", "iss"]}, ) # jwt.ExpiredSignatureError / InvalidAudienceError are raised, not returned - # there is no path where an invalid token becomes an empty dict you forget to check.