Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/jwt/exceptions.py: 95%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

41 statements  

1class PyJWTError(Exception): 

2 """ 

3 Base class for all exceptions 

4 """ 

5 

6 pass 

7 

8 

9class InvalidTokenError(PyJWTError): 

10 """Base exception when ``decode()`` fails on a token""" 

11 

12 pass 

13 

14 

15class DecodeError(InvalidTokenError): 

16 """Raised when a token cannot be decoded because it failed validation""" 

17 

18 pass 

19 

20 

21class 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 

28class ExpiredSignatureError(InvalidTokenError): 

29 """Raised when a token's ``exp`` claim indicates that it has expired""" 

30 

31 pass 

32 

33 

34class 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 

41class InvalidIssuerError(InvalidTokenError): 

42 """Raised when a token's ``iss`` claim does not match the expected issuer""" 

43 

44 pass 

45 

46 

47class InvalidIssuedAtError(InvalidTokenError): 

48 """Raised when a token's ``iat`` claim is non-numeric""" 

49 

50 pass 

51 

52 

53class ImmatureSignatureError(InvalidTokenError): 

54 """Raised when a token's ``nbf`` or ``iat`` claims represent a time in the future""" 

55 

56 pass 

57 

58 

59class InvalidKeyError(PyJWTError): 

60 """Raised when the specified key is not in the proper format""" 

61 

62 pass 

63 

64 

65class InvalidAlgorithmError(InvalidTokenError): 

66 """Raised when the specified algorithm is not recognized by PyJWT""" 

67 

68 pass 

69 

70 

71class 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 

82class PyJWKError(PyJWTError): 

83 pass 

84 

85 

86class MissingCryptographyError(PyJWKError): 

87 """Raised if the algorithm requires ``cryptography`` to be installed and it is not available.""" 

88 

89 pass 

90 

91 

92class PyJWKSetError(PyJWTError): 

93 pass 

94 

95 

96class PyJWKClientError(PyJWTError): 

97 pass 

98 

99 

100class PyJWKClientConnectionError(PyJWKClientError): 

101 pass 

102 

103 

104class 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 

110class InvalidJTIError(InvalidTokenError): 

111 """Raised when a token's ``jti`` claim is not a string""" 

112 

113 pass