forked from python-social-auth/social-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexceptions.py
116 lines (81 loc) · 3.35 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class SocialAuthBaseException(ValueError):
"""Base class for pipeline exceptions."""
pass
class WrongBackend(SocialAuthBaseException):
def __init__(self, backend_name):
self.backend_name = backend_name
def __str__(self):
return 'Incorrect authentication service "{0}"'.format(
self.backend_name
)
class MissingBackend(WrongBackend):
def __str__(self):
return 'Missing backend "{0}" entry'.format(self.backend_name)
class NotAllowedToDisconnect(SocialAuthBaseException):
"""User is not allowed to disconnect it's social account."""
pass
class AuthException(SocialAuthBaseException):
"""Auth process exception."""
def __init__(self, backend, *args, **kwargs):
self.backend = backend
super(AuthException, self).__init__(*args, **kwargs)
class AuthFailed(AuthException):
"""Auth process failed for some reason."""
def __str__(self):
msg = super(AuthFailed, self).__str__()
if msg == 'access_denied':
return 'Authentication process was canceled'
return 'Authentication failed: {0}'.format(msg)
class AuthCanceled(AuthException):
"""Auth process was canceled by user."""
def __init__(self, *args, **kwargs):
self.response = kwargs.pop('response', None)
super(AuthCanceled, self).__init__(*args, **kwargs)
def __str__(self):
msg = super(AuthCanceled, self).__str__()
if msg:
return 'Authentication process canceled: {0}'.format(msg)
return 'Authentication process canceled'
class AuthUnknownError(AuthException):
"""Unknown auth process error."""
def __str__(self):
msg = super(AuthUnknownError, self).__str__()
return 'An unknown error happened while authenticating {0}'.format(msg)
class AuthTokenError(AuthException):
"""Auth token error."""
def __str__(self):
msg = super(AuthTokenError, self).__str__()
return 'Token error: {0}'.format(msg)
class AuthMissingParameter(AuthException):
"""Missing parameter needed to start or complete the process."""
def __init__(self, backend, parameter, *args, **kwargs):
self.parameter = parameter
super(AuthMissingParameter, self).__init__(backend, *args, **kwargs)
def __str__(self):
return 'Missing needed parameter {0}'.format(self.parameter)
class AuthStateMissing(AuthException):
"""State parameter is incorrect."""
def __str__(self):
return 'Session value state missing.'
class AuthStateForbidden(AuthException):
"""State parameter is incorrect."""
def __str__(self):
return 'Wrong state parameter given.'
class AuthAlreadyAssociated(AuthException):
"""A different user has already associated the target social account"""
pass
class AuthTokenRevoked(AuthException):
"""User revoked the access_token in the provider."""
def __str__(self):
return 'User revoke access to the token'
class AuthForbidden(AuthException):
"""Authentication for this user is forbidden"""
def __str__(self):
return 'Your credentials aren\'t allowed'
class AuthUnreachableProvider(AuthException):
"""Cannot reach the provider"""
def __str__(self):
return 'The authentication provider could not be reached'
class InvalidEmail(AuthException):
def __str__(self):
return 'Email couldn\'t be validated'