From f8a27e789724e3870cc7d16ad7950acd872ebdb7 Mon Sep 17 00:00:00 2001 From: Cristiano Singulani Date: Wed, 15 May 2024 19:16:39 -0300 Subject: [PATCH 1/4] Fixed bug in gh login --- backend/core/shibboleth.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/backend/core/shibboleth.py b/backend/core/shibboleth.py index a48421f..a5d6d6e 100644 --- a/backend/core/shibboleth.py +++ b/backend/core/shibboleth.py @@ -1,7 +1,6 @@ import logging from django.contrib.auth.models import Group - from shibboleth.middleware import ShibbolethRemoteUserMiddleware @@ -20,18 +19,16 @@ def make_profile(self, user, shib_meta): log.debug(user) # Guardar o email do usuario - user.email = shib_meta.get('email', None) - log.debug("Updated user email") + # user.email = shib_meta.get('email', None) + # log.debug("Updated user email") - if not shib_meta.get('first_name', None): + if not shib_meta.get("first_name", None): user.profile.display_name = user.username user.profile.save() log.debug("Added user profile display name") # Adiciona um display name para o usuario - if ( - user.profile.display_name is None - ): + if user.profile.display_name is None: user.profile.display_name = user.username user.profile.save() log.debug("Added user profile display name") From c1455d044b5a5947d8eb770945fd8f0a25490b5f Mon Sep 17 00:00:00 2001 From: Cristiano Singulani Date: Thu, 16 May 2024 12:30:12 +0000 Subject: [PATCH 2/4] Improvements to authentication via github --- backend/core/shibboleth.py | 9 +++++---- backend/pzserver/settings.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/core/shibboleth.py b/backend/core/shibboleth.py index a5d6d6e..9a0336b 100644 --- a/backend/core/shibboleth.py +++ b/backend/core/shibboleth.py @@ -22,7 +22,7 @@ def make_profile(self, user, shib_meta): # user.email = shib_meta.get('email', None) # log.debug("Updated user email") - if not shib_meta.get("first_name", None): + if not shib_meta.get("display_name", None): user.profile.display_name = user.username user.profile.save() log.debug("Added user profile display name") @@ -37,9 +37,10 @@ def make_profile(self, user, shib_meta): # Adicionar o usuario ao grupo Shibboleth try: - group, created = Group.objects.get_or_create(name="Shibboleth") - group.user_set.add(user) - log.debug("Added user to Shibboleth group") + if not user.groups.filter(name="Shibboleth").exists(): + group, created = Group.objects.get_or_create(name="Shibboleth") + group.user_set.add(user) + log.debug("Added user to Shibboleth group") except Exception as e: log.error("Failed on add user to group shibboleth. Error: %s" % e) diff --git a/backend/pzserver/settings.py b/backend/pzserver/settings.py index 8ceec74..7ab96ee 100644 --- a/backend/pzserver/settings.py +++ b/backend/pzserver/settings.py @@ -206,9 +206,9 @@ if os.getenv("AUTH_SHIB_URL", None) is not None: # https://github.com/Brown-University-Library/django-shibboleth-remoteuser SHIBBOLETH_ATTRIBUTE_MAP = { - "eppn": (True, "username"), - "cn": (False, "first_name"), - "sn": (False, "last_name"), + "eppn": (True, "id"), + "cn": (False, "display_name"), + "sn": (False, "username"), "Shib-inetOrgPerson-mail": (False, "email"), } SHIBBOLETH_GROUP_ATTRIBUTES = "Shibboleth" From 526e9464ce8b4ec9d0de9ef2f9890b71d42821d0 Mon Sep 17 00:00:00 2001 From: Cristiano Singulani Date: Thu, 16 May 2024 12:48:45 +0000 Subject: [PATCH 3/4] Improvements to authentication via github --- backend/core/shibboleth.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/core/shibboleth.py b/backend/core/shibboleth.py index 9a0336b..7e936c1 100644 --- a/backend/core/shibboleth.py +++ b/backend/core/shibboleth.py @@ -19,19 +19,19 @@ def make_profile(self, user, shib_meta): log.debug(user) # Guardar o email do usuario - # user.email = shib_meta.get('email', None) - # log.debug("Updated user email") + if shib_meta.get('email', None): + user.email = shib_meta.get('email') + log.debug("Updated user email") - if not shib_meta.get("display_name", None): - user.profile.display_name = user.username - user.profile.save() + if user.profile.display_name != shib_meta.get("display_name", None): + user.profile.display_name = shib_meta.get("display_name", user.username) log.debug("Added user profile display name") + user.profile.save() # Adiciona um display name para o usuario if user.profile.display_name is None: user.profile.display_name = user.username user.profile.save() - log.debug("Added user profile display name") user.save() @@ -44,8 +44,6 @@ def make_profile(self, user, shib_meta): except Exception as e: log.error("Failed on add user to group shibboleth. Error: %s" % e) - log.debug("--------------------------") - return def setup_session(self, request): From dac0b6d0b7ac63c88a6aa8f042fd27874649c5d3 Mon Sep 17 00:00:00 2001 From: Cristiano Singulani Date: Thu, 16 May 2024 14:09:06 +0000 Subject: [PATCH 4/4] Improvements to authentication via github --- backend/core/shibboleth.py | 5 +++++ backend/pzserver/settings.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/core/shibboleth.py b/backend/core/shibboleth.py index 7e936c1..3aaba5a 100644 --- a/backend/core/shibboleth.py +++ b/backend/core/shibboleth.py @@ -23,6 +23,11 @@ def make_profile(self, user, shib_meta): user.email = shib_meta.get('email') log.debug("Updated user email") + if not user.last_name and shib_meta.get("first_name", None): + fullname = shib_meta.get("first_name") + user.first_name = fullname.split()[0] + user.last_name = fullname.split()[-1] + if user.profile.display_name != shib_meta.get("display_name", None): user.profile.display_name = shib_meta.get("display_name", user.username) log.debug("Added user profile display name") diff --git a/backend/pzserver/settings.py b/backend/pzserver/settings.py index 7ab96ee..2e4ae38 100644 --- a/backend/pzserver/settings.py +++ b/backend/pzserver/settings.py @@ -206,9 +206,9 @@ if os.getenv("AUTH_SHIB_URL", None) is not None: # https://github.com/Brown-University-Library/django-shibboleth-remoteuser SHIBBOLETH_ATTRIBUTE_MAP = { - "eppn": (True, "id"), - "cn": (False, "display_name"), - "sn": (False, "username"), + "eppn": (True, "username"), + "cn": (False, "first_name"), + "sn": (False, "display_name"), "Shib-inetOrgPerson-mail": (False, "email"), } SHIBBOLETH_GROUP_ATTRIBUTES = "Shibboleth"