Skip to content

Commit 7950d20

Browse files
authored
Allow for custom error handling in LogoutInitView (#256)
1 parent 5c52521 commit 7950d20

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

djangosaml2/views.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def get(self, request, *args, **kwargs):
497497
'Error Handled - SLO not supported by IDP: {}'.format(exp))
498498
auth.logout(request)
499499
state.sync()
500-
return HttpResponseRedirect(getattr(settings, 'LOGOUT_REDIRECT_URL', '/'))
500+
return self.handle_unsupported_slo_exception(request, exp)
501501

502502
auth.logout(request)
503503
state.sync()
@@ -533,6 +533,15 @@ def get(self, request, *args, **kwargs):
533533
'Could not logout because there only the HTTP_REDIRECT is supported')
534534
return HttpResponseServerError('Logout Binding not supported')
535535

536+
def handle_unsupported_slo_exception(self, request, exception, *args, **kwargs):
537+
""" Subclasses may override this method to implement custom logic for
538+
handling logout errors. Redirects to LOGOUT_REDIRECT_URL by default.
539+
540+
For example, a site may want to perform additional logic and redirect
541+
users somewhere other than the LOGOUT_REDIRECT_URL.
542+
"""
543+
return HttpResponseRedirect(getattr(settings, 'LOGOUT_REDIRECT_URL', '/'))
544+
536545

537546
@method_decorator(csrf_exempt, name='dispatch')
538547
class LogoutView(SPConfigMixin, View):

0 commit comments

Comments
 (0)