Skip to content

Commit

Permalink
Fixed GitHub authentication (#260)
Browse files Browse the repository at this point in the history
* Fixed bug in gh login

* Improvements to authentication via github

* Improvements to authentication via github

* Improvements to authentication via github
  • Loading branch information
crisingulani committed May 16, 2024
1 parent dffe3a5 commit d636235
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions backend/core/shibboleth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

from django.contrib.auth.models import Group

from shibboleth.middleware import ShibbolethRemoteUserMiddleware


Expand All @@ -20,34 +19,36 @@ 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('first_name', None):
user.profile.display_name = user.username
user.profile.save()
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")
user.profile.save()

# 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")

user.save()

# 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)

log.debug("--------------------------")

return

def setup_session(self, request):
Expand Down
2 changes: 1 addition & 1 deletion backend/pzserver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
SHIBBOLETH_ATTRIBUTE_MAP = {
"eppn": (True, "username"),
"cn": (False, "first_name"),
"sn": (False, "last_name"),
"sn": (False, "display_name"),
"Shib-inetOrgPerson-mail": (False, "email"),
}
SHIBBOLETH_GROUP_ATTRIBUTES = "Shibboleth"
Expand Down

0 comments on commit d636235

Please sign in to comment.