@@ -407,6 +407,7 @@ def echo_attributes(request,
407407 """Example view that echo the SAML attributes of an user"""
408408 saml_session = get_saml_request_session (request )
409409 state = StateCache (saml_session )
410+ state .sync ()
410411 conf = get_config (config_loader_path , request )
411412
412413 client = Saml2Client (conf , state_cache = state ,
@@ -428,12 +429,15 @@ def logout(request, config_loader_path=None):
428429 This view initiates the SAML2 Logout request
429430 using the pysaml2 library to create the LogoutRequest.
430431 """
432+ _do_local_logout (request )
433+
431434 saml_session = get_saml_request_session (request )
432435 state = StateCache (saml_session )
433- conf = get_config (config_loader_path , request )
434436
437+ conf = get_config (config_loader_path , request )
435438 client = Saml2Client (conf , state_cache = state ,
436439 identity_cache = IdentityCache (saml_session ))
440+
437441 subject_id = _get_subject_id (saml_session )
438442 if subject_id is None :
439443 logger .warning (
@@ -450,8 +454,6 @@ def logout(request, config_loader_path=None):
450454 state .sync ()
451455 return HttpResponseRedirect (settings .LOGOUT_REDIRECT_URL )
452456
453- # user locally logged out for prudence, indipendently by IdP behaviour
454- _do_local_logout (request )
455457 state .sync ()
456458
457459 if not result :
@@ -499,7 +501,7 @@ def _do_local_logout(request):
499501
500502
501503def do_logout_service (request , data , binding , config_loader_path = None , next_page = None ,
502- logout_error_template = 'djangosaml2/logout_error.html' ):
504+ logout_error_template = 'djangosaml2/logout_error.html' ):
503505 """SAML Logout Response endpoint
504506
505507 The IdP will send the logout response to this view,
@@ -517,10 +519,11 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
517519 client = Saml2Client (conf , state_cache = state ,
518520 identity_cache = IdentityCache (saml_session ))
519521
522+ state .sync ()
523+
520524 if 'SAMLResponse' in data : # we started the logout
521525 logger .debug ('Receiving a logout response from the IdP' )
522526 response = client .parse_logout_request_response (data ['SAMLResponse' ], binding )
523- state .sync ()
524527 return finish_logout (request , response , next_page = next_page )
525528
526529 elif 'SAMLRequest' in data : # logout started by the IdP
@@ -539,7 +542,6 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
539542 subject_id ,
540543 binding ,
541544 relay_state = data .get ('RelayState' , '' ))
542- state .sync ()
543545
544546 # logout
545547 _do_local_logout (request )
0 commit comments