diff --git a/social_core/pipeline/__init__.py b/social_core/pipeline/__init__.py index 5ff422be..2d996932 100644 --- a/social_core/pipeline/__init__.py +++ b/social_core/pipeline/__init__.py @@ -4,6 +4,8 @@ # already part of the auth response from the provider, but sometimes this # could hit a provider API. "social_core.pipeline.social_auth.social_details", + # Populate first+last name from full name and vice-versa, if needed + 'social_core.pipeline.social_auth.social_names', # Get the social uid from whichever service we're authing thru. The uid is # the unique identifier of the given user in the provider. "social_core.pipeline.social_auth.social_uid", diff --git a/social_core/pipeline/social_auth.py b/social_core/pipeline/social_auth.py index 1c5940e7..8159edd7 100644 --- a/social_core/pipeline/social_auth.py +++ b/social_core/pipeline/social_auth.py @@ -5,6 +5,21 @@ def social_details(backend, details, response, *args, **kwargs): return {"details": dict(backend.get_user_details(response), **details)} +def social_names(backend, details, response, *args, **kwargs): + # If first+last are both missing, populate from full + if details.get('fullname') and backend.setting('FIRSTLAST_FROM_FULL', True): + if not (details.get('first_name') or details.get('last_name')): + first, _space, last = details['fullname'].rpartition(' ') + details['first_name'] = first.strip() + details['last_name'] = last.strip() + print(f"end social_names {details=}") + + # If first+last are both present, populate full if that's missing + if not details.get('fullname') and backend.setting('FULL_FROM_FIRSTLAST', True): + if details.get('first_name') and details.get('last_name'): + details['fullname'] = details['first_name'] + " " + details['last_name'] + + def social_uid(backend, details, response, *args, **kwargs): return {"uid": str(backend.get_user_id(details, response))}