exceptions.py 2.3 KB

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