Skip to content

Commit

Permalink
logout url and echo_attributes fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Feb 15, 2021
2 parents 5cfbd7f + 5144854 commit 511ef42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/djangosaml2_spid/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from django.urls import include, path
from django.conf import settings
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import reverse
from django.views.generic.base import RedirectView


from djangosaml2.views import *
from djangosaml2 import views
from djangosaml2_spid.views import (metadata_spid,
spid_login,
spid_logout)

from . import views
spid_logout,
EchoAttributesView)

SAML2_URL_PREFIX = 'spid'

Expand All @@ -20,11 +20,11 @@
path(f'{SAML2_URL_PREFIX}/metadata/', metadata_spid, name='spid_metadata'),
path(f'{SAML2_URL_PREFIX}/logout/', spid_logout, name='spid_logout'),

path(f'{SAML2_URL_PREFIX}/acs/', AssertionConsumerServiceView.as_view(), name='saml2_acs'),
path(f'{SAML2_URL_PREFIX}/ls/', LogoutView.as_view(), name='saml2_ls'),
path(f'{SAML2_URL_PREFIX}/ls/post/', LogoutView.as_view(), name='saml2_ls_post'),
path(f'{SAML2_URL_PREFIX}/acs/', views.AssertionConsumerServiceView.as_view(), name='saml2_acs'),
path(f'{SAML2_URL_PREFIX}/ls/', views.LogoutView.as_view(), name='saml2_ls'),
path(f'{SAML2_URL_PREFIX}/ls/post/', views.LogoutView.as_view(), name='saml2_ls_post'),
path(f'{SAML2_URL_PREFIX}/echo_attributes', EchoAttributesView.as_view(), name='saml2_echo_attributes'),
path('logout/', LogoutView.as_view(), {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
path('logout/', auth_views.LogoutView.as_view(), {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),

path('', RedirectView.as_view(url='/spid/login/', permanent=False), name='index')

Expand Down
21 changes: 20 additions & 1 deletion src/djangosaml2_spid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.conf import settings
from django.contrib import auth
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.dispatch import receiver
Expand All @@ -24,7 +25,9 @@
get_idp_sso_supported_bindings, get_location,
validate_referral_url
)
from djangosaml2.views import finish_logout, _get_subject_id
from djangosaml2.views import (finish_logout,
_get_subject_id,
SPConfigMixin, View)
from saml2 import BINDING_HTTP_REDIRECT, BINDING_HTTP_POST
from saml2.authn_context import requested_authn_context
from saml2.metadata import entity_descriptor, sign_entity_descriptor
Expand Down Expand Up @@ -473,3 +476,19 @@ def metadata_spid(request, config_loader_path=None, valid_for=None):
xmldoc = spid_sp_metadata(conf)
return HttpResponse(content=str(xmldoc).encode('utf-8'),
content_type="text/xml; charset=utf8")


class EchoAttributesView(LoginRequiredMixin, SPConfigMixin, View):
"""Example view that echo the SAML attributes of an user
"""

def get(self, request, *args, **kwargs):
state, client = self.get_state_client(request)

subject_id = _get_subject_id(request.saml_session)
try:
identity = client.users.get_identity(subject_id, check_not_on_or_after=False)
except AttributeError:
return HttpResponse("No active SAML identity found. Are you sure you have logged in via SAML?")

return render(request, 'spid_echo_attributes.html', {'attributes': identity[0]})

0 comments on commit 511ef42

Please sign in to comment.