1__all__ = [
2 "OAuthError",
3 "OAuthStateMismatchError",
4 "OAuthStateMissingError",
5 "OAuthUserAlreadyExistsError",
6]
7
8
9class OAuthError(Exception):
10 """Base class for OAuth errors"""
11
12 message = "An error occurred during the OAuth process."
13 template_name = ""
14
15 def __init__(self, message: str = "", *, provider_key: str = "") -> None:
16 self.provider_key = provider_key
17 if message:
18 self.message = message
19 super().__init__(self.message)
20
21
22class OAuthStateMissingError(OAuthError):
23 message = "The OAuth state is missing. Your session may have expired or cookies may be blocked. Please try again."
24 template_name = "oauth/state_missing.html"
25
26
27class OAuthStateMismatchError(OAuthError):
28 message = "The state parameter did not match. Please try again."
29 template_name = "oauth/state_mismatch.html"
30
31
32class OAuthUserAlreadyExistsError(OAuthError):
33 message = "A user already exists with this email address. Please log in first and then connect this OAuth provider to the existing account."
34 template_name = "oauth/user_already_exists.html"
35
36 def __init__(
37 self, *, provider_key: str = "", user_model_fields: dict | None = None
38 ) -> None:
39 self.user_model_fields = user_model_fields or {}
40 super().__init__(provider_key=provider_key)