1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
class PyJWTError(Exception):
"""
Base class for all exceptions
"""
pass
class InvalidTokenError(PyJWTError):
"""Base exception when ``decode()`` fails on a token"""
pass
class DecodeError(InvalidTokenError):
"""Raised when a token cannot be decoded because it failed validation"""
pass
class InvalidSignatureError(DecodeError):
"""Raised when a token's signature doesn't match the one provided as part of
the token."""
pass
class ExpiredSignatureError(InvalidTokenError):
"""Raised when a token's ``exp`` claim indicates that it has expired"""
pass
class InvalidAudienceError(InvalidTokenError):
"""Raised when a token's ``aud`` claim does not match one of the expected
audience values"""
pass
class InvalidIssuerError(InvalidTokenError):
"""Raised when a token's ``iss`` claim does not match the expected issuer"""
pass
class InvalidIssuedAtError(InvalidTokenError):
"""Raised when a token's ``iat`` claim is non-numeric"""
pass
class ImmatureSignatureError(InvalidTokenError):
"""Raised when a token's ``nbf`` or ``iat`` claims represent a time in the future"""
pass
class InvalidKeyError(PyJWTError):
"""Raised when the specified key is not in the proper format"""
pass
class InvalidAlgorithmError(InvalidTokenError):
"""Raised when the specified algorithm is not recognized by PyJWT"""
pass
class MissingRequiredClaimError(InvalidTokenError):
"""Raised when a claim that is required to be present is not contained
in the claimset"""
def __init__(self, claim: str) -> None:
self.claim = claim
def __str__(self) -> str:
return f'Token is missing the "{self.claim}" claim'
class PyJWKError(PyJWTError):
pass
class MissingCryptographyError(PyJWKError):
"""Raised if the algorithm requires ``cryptography`` to be installed and it is not available."""
pass
class PyJWKSetError(PyJWTError):
pass
class PyJWKClientError(PyJWTError):
pass
class PyJWKClientConnectionError(PyJWKClientError):
pass
class InvalidSubjectError(InvalidTokenError):
"""Raised when a token's ``sub`` claim is not a string or doesn't match the expected ``subject``"""
pass
class InvalidJTIError(InvalidTokenError):
"""Raised when a token's ``jti`` claim is not a string"""
pass
|