Use new settings of social-auth

cf #754
This commit is contained in:
Yohan Boniface 2020-03-22 18:00:47 +01:00
parent cc4ce9ea8c
commit 7f0454fce0
2 changed files with 2 additions and 35 deletions

View file

@ -220,6 +220,7 @@ COMPRESS_OFFLINE = True
SOCIAL_AUTH_DEFAULT_USERNAME = lambda u: slugify(u)
SOCIAL_AUTH_ASSOCIATE_BY_EMAIL = True
SOCIAL_AUTH_NO_DEFAULT_PROTECTED_USER_FIELDS = True
LOGIN_URL = "login"
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/login/popup/end/"
SOCIAL_AUTH_PIPELINE = (
@ -232,5 +233,5 @@ SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'umap.utils.oauth_user_details'
'social_core.pipeline.user.user_details'
)

View file

@ -109,37 +109,3 @@ def gzip_file(from_path, to_path):
with open(from_path, 'rb') as f_in:
with gzip.open(to_path, 'wb') as f_out:
f_out.writelines(f_in)
def oauth_user_details(strategy, details, user=None, *args, **kwargs):
"""
This method is a pipeline stage only to be used with social_auth
Note this is a workaround that can break if social_auth is updated
Update user details using data from provider.
"""
if not user:
return
changed = False # flag to track changes
# uMap fix: remove 'username' from protected fields
protected = ('id', 'pk', 'email') + \
tuple(strategy.setting('PROTECTED_USER_FIELDS', []))
# Update user model attributes with the new data sent by the current
# provider. Update on some attributes is disabled by default, for
# example username and id fields. It's also possible to disable update
# on fields defined in SOCIAL_AUTH_PROTECTED_USER_FIELDS.
for name, value in details.items():
if value is None or not hasattr(user, name) or name in protected:
continue
# Check https://github.com/omab/python-social-auth/issues/671
current_value = getattr(user, name, None)
# uMap fix: update field when value has changed
if current_value == value:
continue
changed = True
setattr(user, name, value)
if changed:
strategy.storage.user.changed(user)