diff --git a/src/open_inwoner/accounts/tests/test_oidc_views.py b/src/open_inwoner/accounts/tests/test_oidc_views.py index 3453c6a4d..f3268ab6b 100644 --- a/src/open_inwoner/accounts/tests/test_oidc_views.py +++ b/src/open_inwoner/accounts/tests/test_oidc_views.py @@ -1,5 +1,6 @@ from hashlib import md5 from typing import Literal +from unittest import skip from unittest.mock import patch from django.contrib.auth import get_user_model @@ -623,6 +624,7 @@ def test_new_user_is_created_when_new_bsn( id=1, enabled=True, oidc_op_logout_endpoint="http://localhost:8080/logout" ), ) + @skip("Testing this in a live environment first") def test_logout(self, mock_get_solo): # set up a user with a non existing email address user = DigidUserFactory.create( @@ -1155,6 +1157,7 @@ def test_new_user_is_created_when_new_kvk( oidc_op_logout_endpoint="http://localhost:8080/logout", ), ) + @skip("Testing this in a live environment first") def test_logout(self, mock_get_solo): # set up a user with a non existing email address user = eHerkenningUserFactory.create( diff --git a/src/open_inwoner/accounts/views/auth_oidc.py b/src/open_inwoner/accounts/views/auth_oidc.py index 25f078e7e..d3402cb09 100644 --- a/src/open_inwoner/accounts/views/auth_oidc.py +++ b/src/open_inwoner/accounts/views/auth_oidc.py @@ -1,4 +1,5 @@ import logging +from urllib.parse import urlencode from django.conf import settings from django.contrib import auth, messages @@ -97,16 +98,38 @@ def get_success_url(self): def get(self, request): assert self.config_class is not None + config = self.config_class.get_solo() - if id_token := request.session.get("oidc_id_token"): - config = self.config_class.get_solo() - do_op_logout(config, id_token) + if not (logout_endpoint := config.oidc_op_logout_endpoint): + logger.warning("No OIDC logout endpoint defined") + id_token = request.session.get("oidc_id_token") if "oidc_login_next" in request.session: del request.session["oidc_login_next"] + # Always destroy our session, having obtained the OIDC artifacts from the session auth.logout(request) + # Try to initiate a frontchannel redirect + if id_token: + if not logout_endpoint: + # Fallback: no frontchannel flow possible + # TODO: we can actually still redirect here, but it might be a + # bad UX, because no id token hint. + do_op_logout(config, id_token) + else: + params = { + "id_token_hint": id_token, + # The value MUST have been previously registered with the + # OP, either using the post_logout_redirect_uris + # Registration parameter or via another mechanism. + "post_logout_redirect_uri": self.request.build_absolute_uri( + self.get_success_url() + ), + } + logout_url = f"{logout_endpoint}?{urlencode(params)}" + return HttpResponseRedirect(logout_url) + return HttpResponseRedirect(self.get_success_url())