Skip to content

Commit c7e5cda

Browse files
committed
If debug enable, print reason for the SAMLResponse invalidation
1 parent 4bafe94 commit c7e5cda

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

demo-django/demo/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def index(request):
3434
req = prepare_django_request(request)
3535
auth = init_saml_auth(req)
3636
errors = []
37+
error_reason = None
3738
not_auth_warn = False
3839
success_slo = False
3940
attributes = False
@@ -70,6 +71,7 @@ def index(request):
7071
auth.process_response(request_id=request_id)
7172
errors = auth.get_errors()
7273
not_auth_warn = not auth.is_authenticated()
74+
7375
if not errors:
7476
if 'AuthNRequestID' in request.session:
7577
del request.session['AuthNRequestID']
@@ -78,6 +80,9 @@ def index(request):
7880
request.session['samlSessionIndex'] = auth.get_session_index()
7981
if 'RelayState' in req['post_data'] and OneLogin_Saml2_Utils.get_self_url(req) != req['post_data']['RelayState']:
8082
return HttpResponseRedirect(auth.redirect_to(req['post_data']['RelayState']))
83+
else:
84+
if auth.get_settings().is_debug_active():
85+
error_reason = auth.get_last_error_reason()
8186
elif 'sls' in req['get_data']:
8287
request_id = None
8388
if 'LogoutRequestID' in request.session:
@@ -96,7 +101,7 @@ def index(request):
96101
if len(request.session['samlUserdata']) > 0:
97102
attributes = request.session['samlUserdata'].items()
98103

99-
return render(request, 'index.html', {'errors': errors, 'not_auth_warn': not_auth_warn, 'success_slo': success_slo,
104+
return render(request, 'index.html', {'errors': errors, 'error_reason': error_reason, not_auth_warn: not_auth_warn, 'success_slo': success_slo,
100105
'attributes': attributes, 'paint_logout': paint_logout})
101106

102107

demo-django/templates/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<li>{{err}}</li>
1111
{% endfor %}
1212
</ul>
13+
{% if error_reason %}
14+
<p><b>Reason:</b> {{error_reason}}</p>
15+
{% endif %}
1316
</div>
1417
{% endif %}
1518

0 commit comments

Comments
 (0)