@@ -367,17 +367,66 @@ def validate_logout_request(self, id_token_hint, client_id, post_logout_redirect
367367        return  application , id_token .user  if  id_token  else  None 
368368
369369    def  must_prompt (self , token_user ):
370-         """Indicate whether the logout has to be confirmed by the user. This happens if the 
371-         specifications force a confirmation, or it is enabled by `OIDC_RP_INITIATED_LOGOUT_ALWAYS_PROMPT`. 
370+         """ 
371+         per: https://openid.net/specs/openid-connect-rpinitiated-1_0.html 
372+ 
373+         > At the Logout Endpoint, the OP SHOULD ask the End-User whether to log 
374+         > out of the OP as well. Furthermore, the OP MUST ask the End-User this 
375+         > question if an id_token_hint was not provided or if the supplied ID 
376+         > Token does not belong to the current OP session with the RP and/or 
377+         > currently logged in End-User. 
372378
373-         A logout without user interaction (i.e. no prompt) is only allowed 
374-         if an ID Token is provided that matches the current user. 
375379        """ 
376-         return  (
377-             oauth2_settings .OIDC_RP_INITIATED_LOGOUT_ALWAYS_PROMPT 
378-             or  token_user  is  None 
379-             or  token_user  !=  self .request .user 
380-         )
380+ 
381+         if  not  self .request .user .is_authenticated :
382+             """ 
383+             > the OP MUST ask ask the End-User whether to log out of the OP as 
384+ 
385+             If the user does not have an active session with the OP, they cannot 
386+             end their OP session, so there is nothing to prompt for. This occurs 
387+             in cases where the user has logged out of the OP via another channel 
388+             such as the OP's own logout page, session timeout or another RP's 
389+             logout page. 
390+             """ 
391+             return  False 
392+ 
393+         if  oauth2_settings .OIDC_RP_INITIATED_LOGOUT_ALWAYS_PROMPT :
394+             """ 
395+             > At the Logout Endpoint, the OP SHOULD ask the End-User whether to 
396+             > log out of the OP as well 
397+ 
398+             The admin has configured the OP to always prompt the userfor logout 
399+             per the SHOULD recommendation. 
400+             """ 
401+             return  True 
402+ 
403+         if  token_user  is  None :
404+             """ 
405+             > the OP MUST ask ask the End-User whether to log out of the OP as 
406+             > well if the supplied ID Token does not belong to the current OP 
407+             > session with the RP. 
408+ 
409+             token_user will only be populated if an ID token was found for the 
410+             RP (Application) that is requesting the logout. If token_user is not 
411+             then we must prompt the user. 
412+             """ 
413+             return  True 
414+ 
415+         if  token_user  !=  self .request .user :
416+             """ 
417+             > the OP MUST ask ask the End-User whether to log out of the OP as 
418+             > well if the supplied ID Token does not belong to the logged in 
419+             > End-User. 
420+ 
421+             is_authenticated indicates that there is a logged in user and was 
422+             tested in the first condition. 
423+             token_user != self.request.user indicates that the token does not 
424+             belong to the logged in user, Therefore we need to prompt the user. 
425+             """ 
426+             return  True 
427+ 
428+         """ We didn't find a reason to prompt the user """ 
429+         return  False 
381430
382431    def  do_logout (self , application = None , post_logout_redirect_uri = None , state = None , token_user = None ):
383432        user  =  token_user  or  self .request .user 
0 commit comments