@@ -439,9 +439,10 @@ def post_login_hook(self, request: HttpRequest, user: settings.AUTH_USER_MODEL,
439
439
def build_relay_state (self ) -> str :
440
440
""" The relay state is a URL used to redirect the user to the view where they came from.
441
441
"""
442
+ login_redirect_url = get_custom_setting ('LOGIN_REDIRECT_URL' , '/' )
442
443
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 )
445
446
relay_state = self .customize_relay_state (relay_state )
446
447
if not relay_state :
447
448
logger .warning ('The RelayState parameter exists but is empty' )
@@ -505,7 +506,7 @@ def get(self, request, *args, **kwargs):
505
506
'Error Handled - SLO not supported by IDP: {}' .format (exp ))
506
507
auth .logout (request )
507
508
state .sync ()
508
- return HttpResponseRedirect ( getattr ( settings , 'LOGOUT_REDIRECT_URL' , '/' ) )
509
+ return self . handle_unsupported_slo_exception ( request , exp )
509
510
510
511
auth .logout (request )
511
512
state .sync ()
@@ -541,6 +542,15 @@ def get(self, request, *args, **kwargs):
541
542
'Could not logout because there only the HTTP_REDIRECT is supported' )
542
543
return HttpResponseServerError ('Logout Binding not supported' )
543
544
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
+
544
554
545
555
@method_decorator (csrf_exempt , name = 'dispatch' )
546
556
class LogoutView (SPConfigMixin , View ):
0 commit comments