@@ -363,6 +363,28 @@ def form_valid(self, form):
363363 except OIDCError as error :
364364 return self .error_response (error )
365365
366+ def validate_post_logout_redirect_uri (self , application , post_logout_redirect_uri ):
367+ """
368+ Validate the OIDC RP-Initiated Logout Request post_logout_redirect_uri parameter
369+ """
370+
371+ if not post_logout_redirect_uri :
372+ return
373+
374+ if not application :
375+ raise InvalidOIDCClientError ()
376+ scheme = urlparse (post_logout_redirect_uri )[0 ]
377+ if not scheme :
378+ raise InvalidOIDCRedirectURIError ("A Scheme is required for the redirect URI." )
379+ if oauth2_settings .OIDC_RP_INITIATED_LOGOUT_STRICT_REDIRECT_URIS and (
380+ scheme == "http" and application .client_type != "confidential"
381+ ):
382+ raise InvalidOIDCRedirectURIError ("http is only allowed with confidential clients." )
383+ if scheme not in application .get_allowed_schemes ():
384+ raise InvalidOIDCRedirectURIError (f'Redirect to scheme "{ scheme } " is not permitted.' )
385+ if not application .post_logout_redirect_uri_allowed (post_logout_redirect_uri ):
386+ raise InvalidOIDCRedirectURIError ("This client does not have this redirect uri registered." )
387+
366388 def validate_logout_request (self , id_token_hint , client_id , post_logout_redirect_uri ):
367389 """
368390 Validate an OIDC RP-Initiated Logout Request.
@@ -395,21 +417,7 @@ def validate_logout_request(self, id_token_hint, client_id, post_logout_redirect
395417 elif id_token :
396418 application = id_token .application
397419
398- # Validate `post_logout_redirect_uri`
399- if post_logout_redirect_uri :
400- if not application :
401- raise InvalidOIDCClientError ()
402- scheme = urlparse (post_logout_redirect_uri )[0 ]
403- if not scheme :
404- raise InvalidOIDCRedirectURIError ("A Scheme is required for the redirect URI." )
405- if oauth2_settings .OIDC_RP_INITIATED_LOGOUT_STRICT_REDIRECT_URIS and (
406- scheme == "http" and application .client_type != "confidential"
407- ):
408- raise InvalidOIDCRedirectURIError ("http is only allowed with confidential clients." )
409- if scheme not in application .get_allowed_schemes ():
410- raise InvalidOIDCRedirectURIError (f'Redirect to scheme "{ scheme } " is not permitted.' )
411- if not application .post_logout_redirect_uri_allowed (post_logout_redirect_uri ):
412- raise InvalidOIDCRedirectURIError ("This client does not have this redirect uri registered." )
420+ self .validate_post_logout_redirect_uri (application , post_logout_redirect_uri )
413421
414422 return application , id_token .user if id_token else None
415423
0 commit comments