Skip to content

Commit a246326

Browse files
committed
If debug enable, print reason for the SAMLResponse invalidation
1 parent bd2a662 commit a246326

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
@@ -33,6 +33,7 @@ def index(request):
3333
req = prepare_django_request(request)
3434
auth = init_saml_auth(req)
3535
errors = []
36+
error_reason = None
3637
not_auth_warn = False
3738
success_slo = False
3839
attributes = False
@@ -56,12 +57,16 @@ def index(request):
5657
auth.process_response()
5758
errors = auth.get_errors()
5859
not_auth_warn = not auth.is_authenticated()
60+
5961
if not errors:
6062
request.session['samlUserdata'] = auth.get_attributes()
6163
request.session['samlNameId'] = auth.get_nameid()
6264
request.session['samlSessionIndex'] = auth.get_session_index()
6365
if 'RelayState' in req['post_data'] and OneLogin_Saml2_Utils.get_self_url(req) != req['post_data']['RelayState']:
6466
return HttpResponseRedirect(auth.redirect_to(req['post_data']['RelayState']))
67+
else:
68+
if auth.get_settings().is_debug_active():
69+
error_reason = auth.get_last_error_reason()
6570
elif 'sls' in req['get_data']:
6671
dscb = lambda: request.session.flush()
6772
url = auth.process_slo(delete_session_cb=dscb)
@@ -77,7 +82,7 @@ def index(request):
7782
if len(request.session['samlUserdata']) > 0:
7883
attributes = request.session['samlUserdata'].items()
7984

80-
return render(request, 'index.html', {'errors': errors, 'not_auth_warn': not_auth_warn, 'success_slo': success_slo,
85+
return render(request, 'index.html', {'errors': errors, 'error_reason': error_reason, 'not_auth_warn': not_auth_warn, 'success_slo': success_slo,
8186
'attributes': attributes, 'paint_logout': paint_logout})
8287

8388

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)