exceptions.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. from django.utils.translation import gettext_lazy as _
  2. class OAuth2Error(Exception):
  3. pass
  4. class OAuth2ProviderError(OAuth2Error):
  5. pass
  6. class OAuth2AccessDeniedError(OAuth2ProviderError):
  7. message = _("The OAuth2 process was canceled by the provider.")
  8. class OAuth2StateError(OAuth2Error):
  9. recoverable = True
  10. class OAuth2StateNotSetError(OAuth2StateError):
  11. message = _("The OAuth2 session is missing state.")
  12. class OAuth2StateNotProvidedError(OAuth2StateError):
  13. message = _("The OAuth2 state was not sent by the provider.")
  14. class OAuth2StateMismatchError(OAuth2StateError):
  15. message = _(
  16. "The OAuth2 state sent by the provider did not match one in the session."
  17. )
  18. class OAuth2CodeError(OAuth2Error):
  19. recoverable = True
  20. class OAuth2CodeNotProvidedError(OAuth2CodeError):
  21. message = _("The OAuth2 authorization code was not sent by the provider.")
  22. class OAuth2ProviderError(OAuth2Error):
  23. recoverable = True
  24. class OAuth2AccessTokenRequestError(OAuth2ProviderError):
  25. message = _("Failed to connect to the OAuth2 provider to retrieve an access token.")
  26. class OAuth2AccessTokenResponseError(OAuth2ProviderError):
  27. message = _("The OAuth2 provider responded with error for an access token request.")
  28. class OAuth2AccessTokenJSONError(OAuth2ProviderError):
  29. message = _(
  30. "The OAuth2 provider did not respond with a valid JSON "
  31. "for an access token request."
  32. )
  33. class OAuth2AccessTokenNotProvidedError(OAuth2ProviderError):
  34. message = _("JSON sent by the OAuth2 provider did not contain an access token.")
  35. class OAuth2UserDataRequestError(OAuth2ProviderError):
  36. message = _("Failed to connect to the OAuth2 provider to retrieve user profile.")
  37. class OAuth2UserDataResponseError(OAuth2ProviderError):
  38. message = _("The OAuth2 provider responded with error for user profile request.")
  39. class OAuth2UserDataJSONError(OAuth2ProviderError):
  40. message = _(
  41. "The OAuth2 provider did not respond with a valid JSON "
  42. "for user profile request."
  43. )
  44. class OAuth2UserIdNotProvidedError(OAuth2Error):
  45. message = _("JSON sent by the OAuth2 provider did not contain a user id.")
  46. class OAuth2UserAccountDeactivatedError(OAuth2Error):
  47. recoverable = False
  48. message = _(
  49. "User account associated with the profile from the OAuth2 provider was "
  50. "deactivated by the site administrator."
  51. )
  52. class OAuth2UserDataValidationError(OAuth2ProviderError):
  53. recoverable = False
  54. error_list: list[str]
  55. message = _("User profile retrieved from the OAuth2 provider did not validate.")
  56. def __init__(self, error_list: list[str]):
  57. self.error_list = error_list