1class JWTExtendedException(Exception):
2 """
3 Base except which all flask_jwt_extended errors extend
4 """
5
6 pass
7
8
9class JWTDecodeError(JWTExtendedException):
10 """
11 An error decoding a JWT
12 """
13
14 pass
15
16
17class InvalidHeaderError(JWTExtendedException):
18 """
19 An error getting header information from a request
20 """
21
22 pass
23
24
25class InvalidQueryParamError(JWTExtendedException):
26 """
27 An error when a query string param is not in the correct format
28 """
29
30 pass
31
32
33class NoAuthorizationError(JWTExtendedException):
34 """
35 An error raised when no authorization token was found in a protected endpoint
36 """
37
38 pass
39
40
41class CSRFError(JWTExtendedException):
42 """
43 An error with CSRF protection
44 """
45
46 pass
47
48
49class WrongTokenError(JWTExtendedException):
50 """
51 Error raised when attempting to use a refresh token to access an endpoint
52 or vice versa
53 """
54
55 pass
56
57
58class RevokedTokenError(JWTExtendedException):
59 """
60 Error raised when a revoked token attempt to access a protected endpoint
61 """
62
63 def __init__(self, jwt_header: dict, jwt_data: dict) -> None:
64 super().__init__("Token has been revoked")
65 self.jwt_header = jwt_header
66 self.jwt_data = jwt_data
67
68
69class FreshTokenRequired(JWTExtendedException):
70 """
71 Error raised when a valid, non-fresh JWT attempt to access an endpoint
72 protected by fresh_jwt_required
73 """
74
75 def __init__(self, message, jwt_header: dict, jwt_data: dict) -> None:
76 super().__init__(message)
77 self.jwt_header = jwt_header
78 self.jwt_data = jwt_data
79
80
81class UserLookupError(JWTExtendedException):
82 """
83 Error raised when a user_lookup callback function returns None, indicating
84 that it cannot or will not load a user for the given identity.
85 """
86
87 def __init__(self, message, jwt_header: dict, jwt_data: dict) -> None:
88 super().__init__(message)
89 self.jwt_header = jwt_header
90 self.jwt_data = jwt_data
91
92
93class UserClaimsVerificationError(JWTExtendedException):
94 """
95 Error raised when the claims_verification_callback function returns False,
96 indicating that the expected user claims are invalid
97 """
98
99 def __init__(self, message, jwt_header: dict, jwt_data: dict) -> None:
100 super().__init__(message)
101 self.jwt_header = jwt_header
102 self.jwt_data = jwt_data