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