From d987dc0475ed02c2380ce1e3b45d8a73dea715fa Mon Sep 17 00:00:00 2001 From: Jozef Knaperek Date: Wed, 16 Aug 2017 09:33:00 +0200 Subject: [PATCH] Show error message for echo_attributes when not logged in via SAML This fixes issue #72 --- djangosaml2/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/djangosaml2/views.py b/djangosaml2/views.py index cd88fb19..76e7a34d 100644 --- a/djangosaml2/views.py +++ b/djangosaml2/views.py @@ -323,8 +323,12 @@ def echo_attributes(request, client = Saml2Client(conf, state_cache=state, identity_cache=IdentityCache(request.session)) subject_id = _get_subject_id(request.session) - identity = client.users.get_identity(subject_id, - check_not_on_or_after=False) + 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, template, {'attributes': identity[0]})