Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GitHub authentication #260

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading