1
from ..exceptions import AuthAlreadyAssociated, AuthException, AuthForbidden
4
def social_details(backend, details, response, *args, **kwargs):
5
return {'details': dict(backend.get_user_details(response), **details)}
8
def social_uid(backend, details, response, *args, **kwargs):
9
return {'uid': backend.get_user_id(details, response)}
12
def auth_allowed(backend, details, response, *args, **kwargs):
13
if not backend.auth_allowed(response, details):
14
raise AuthForbidden(backend)
17
def social_user(backend, uid, user=None, *args, **kwargs):
18
provider = backend.name
19
social = backend.strategy.storage.user.get_social_auth(provider, uid)
21
if user and social.user != user:
22
msg = 'This {0} account is already in use.'.format(provider)
23
raise AuthAlreadyAssociated(backend, msg)
26
return {'social': social,
28
'is_new': user is None,
29
'new_association': social is None}
32
def associate_user(backend, uid, user=None, social=None, *args, **kwargs):
33
if user and not social:
35
social = backend.strategy.storage.user.create_social_auth(
36
user, uid, backend.name
38
except Exception as err:
39
if not backend.strategy.storage.is_integrity_error(err):
41
# Protect for possible race condition, those bastard with FTL
42
# clicking capabilities, check issue #131:
43
# https://github.com/omab/django-social-auth/issues/131
44
return social_user(backend, uid, user, *args, **kwargs)
46
return {'social': social,
48
'new_association': True}
51
def associate_by_email(backend, details, user=None, *args, **kwargs):
53
Associate current auth with a user with the same email address in the DB.
55
This pipeline entry is not 100% secure unless you know that the providers
56
enabled enforce email verification on their side, otherwise a user can
57
attempt to take over another user account by using the same (not validated)
58
email address on some provider. This pipeline entry is disabled by
64
email = details.get('email')
66
# Try to associate accounts registered with the same email address,
67
# only if it's a single object. AuthException is raised if multiple
68
# objects are returned.
69
users = list(backend.strategy.storage.user.get_users_by_email(email))
75
'The given email address is associated with another account'
78
return {'user': users[0],
82
def load_extra_data(backend, details, response, uid, user, *args, **kwargs):
83
social = kwargs.get('social') or \
84
backend.strategy.storage.user.get_social_auth(backend.name, uid)
86
extra_data = backend.extra_data(user, uid, response, details,
88
social.set_extra_data(extra_data)