From db50523cffb7445532503fe16d406beca17bb3fb Mon Sep 17 00:00:00 2001 From: Nikolaus Lieb <4014270+nikoder@users.noreply.github.com> Date: Wed, 15 May 2024 18:01:35 +0800 Subject: [PATCH 1/2] Fix social-app-django/issues/355 Handle the case where the user has not registered a `family-name` and ORCID returns `None`. --- CHANGELOG.md | 5 +++++ social_core/backends/orcid.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1783c865..6b570d97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Changed +- Handle case where user has not registered a `family-name` with ORCID + ## [4.5.4](https://github.com/python-social-auth/social-core/releases/tag/4.5.4) - 2024-04-25 ### Added diff --git a/social_core/backends/orcid.py b/social_core/backends/orcid.py index a2be9eaa..1f815f3b 100644 --- a/social_core/backends/orcid.py +++ b/social_core/backends/orcid.py @@ -76,7 +76,8 @@ def get_user_details(self, response): if name: first_name = name.get("given-names", {}).get("value", "") - last_name = name.get("family-name", {}).get("value", "") + if name.get("family-name", None) is not None: + last_name = name.get("family-name").get("value", "") emails = person.get("emails") if emails: From e1f00ae0f9dac5e5b811f2d492b71b2dae5a1df1 Mon Sep 17 00:00:00 2001 From: Nikolaus Lieb <4014270+nikoder@users.noreply.github.com> Date: Thu, 16 May 2024 14:23:56 +0800 Subject: [PATCH 2/2] Nicer implementation of ORCID login fix for missing family name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michal Čihař --- social_core/backends/orcid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/social_core/backends/orcid.py b/social_core/backends/orcid.py index 1f815f3b..8717fc00 100644 --- a/social_core/backends/orcid.py +++ b/social_core/backends/orcid.py @@ -76,8 +76,8 @@ def get_user_details(self, response): if name: first_name = name.get("given-names", {}).get("value", "") - if name.get("family-name", None) is not None: - last_name = name.get("family-name").get("value", "") + if (family_name := name.get("family-name", None)) is not None: + last_name = family_name.get("value", "") emails = person.get("emails") if emails: