@@ -439,9 +439,10 @@ def post_login_hook(self, request: HttpRequest, user: settings.AUTH_USER_MODEL,
439439 def build_relay_state (self ) -> str :
440440 """ The relay state is a URL used to redirect the user to the view where they came from.
441441 """
442+ login_redirect_url = get_custom_setting ('LOGIN_REDIRECT_URL' , '/' )
442443 default_relay_state = get_custom_setting (
443- 'ACS_DEFAULT_REDIRECT_URL' , settings . LOGIN_REDIRECT_URL )
444- relay_state = self .request .POST .get ('RelayState' , '/' )
444+ 'ACS_DEFAULT_REDIRECT_URL' , login_redirect_url )
445+ relay_state = self .request .POST .get ('RelayState' , default_relay_state )
445446 relay_state = self .customize_relay_state (relay_state )
446447 if not relay_state :
447448 logger .warning ('The RelayState parameter exists but is empty' )
@@ -505,7 +506,7 @@ def get(self, request, *args, **kwargs):
505506 'Error Handled - SLO not supported by IDP: {}' .format (exp ))
506507 auth .logout (request )
507508 state .sync ()
508- return HttpResponseRedirect ( getattr ( settings , 'LOGOUT_REDIRECT_URL' , '/' ) )
509+ return self . handle_unsupported_slo_exception ( request , exp )
509510
510511 auth .logout (request )
511512 state .sync ()
@@ -541,6 +542,15 @@ def get(self, request, *args, **kwargs):
541542 'Could not logout because there only the HTTP_REDIRECT is supported' )
542543 return HttpResponseServerError ('Logout Binding not supported' )
543544
545+ def handle_unsupported_slo_exception (self , request , exception , * args , ** kwargs ):
546+ """ Subclasses may override this method to implement custom logic for
547+ handling logout errors. Redirects to LOGOUT_REDIRECT_URL by default.
548+
549+ For example, a site may want to perform additional logic and redirect
550+ users somewhere other than the LOGOUT_REDIRECT_URL.
551+ """
552+ return HttpResponseRedirect (getattr (settings , 'LOGOUT_REDIRECT_URL' , '/' ))
553+
544554
545555@method_decorator (csrf_exempt , name = 'dispatch' )
546556class LogoutView (SPConfigMixin , View ):
0 commit comments