Skip to content

Commit be2f7b3

Browse files
authored
fix: Use alternative logout url for oauth2 (#1182)
Currently it is sending the request to the oauth2-proxy but is not redirecting blueapi to the Identity provider so using alternative method suggested by oauth2-proxy ``` [2025/08/27 10:20:01] p46-blueapi.diamond.ac.uk GET blueapi "/logout" HTTP/1.1 "Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0" 308 0 0.008 10.32.0.21:57828 - 6cc428867cd7ff0b3ddc0faabc4cddcf - b1370833-c4a3-49c2-9a1e-1a69e3854b59 [2025/08/27 10:20:01] p46-blueapi.diamond.ac.uk GET - "/oauth2/sign_out" HTTP/1.1 "Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0" 302 24 0.000 ```
1 parent 089ef05 commit be2f7b3

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/blueapi/service/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import urllib.parse
23
from collections.abc import Awaitable, Callable
34
from contextlib import asynccontextmanager
45
from enum import Enum
@@ -541,10 +542,11 @@ def logout(runner: Annotated[WorkerDispatcher, Depends(_runner)]) -> Response:
541542
config = runner.run(interface.get_oidc_config)
542543
if config is None or not config.logout_redirect_endpoint:
543544
raise HTTPException(status_code=status.HTTP_205_RESET_CONTENT)
545+
546+
encoded_url = urllib.parse.quote_plus(config.end_session_endpoint)
544547
return RedirectResponse(
545548
status_code=status.HTTP_308_PERMANENT_REDIRECT,
546-
url=config.logout_redirect_endpoint,
547-
headers={"X-Auth-Request-Redirect": config.end_session_endpoint},
549+
url=config.logout_redirect_endpoint.rstrip("/") + "?rd=" + encoded_url,
548550
)
549551

550552

tests/unit_tests/service/test_rest_api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,15 @@ def test_logout(
734734
oidc_config: OIDCConfig,
735735
client_with_auth: TestClient,
736736
):
737-
oidc_config.logout_redirect_endpoint = "/oauth2/logout"
737+
oidc_config.logout_redirect_endpoint = "/oauth2/sign_out/"
738738
mock_runner.run.return_value = oidc_config
739739
client_with_auth.follow_redirects = False
740740
response = client_with_auth.get("/logout")
741741
assert response.status_code == status.HTTP_308_PERMANENT_REDIRECT
742742
assert (
743-
response.headers.get("X-Auth-Request-Redirect")
744-
== oidc_config.end_session_endpoint
743+
response.headers.get("location")
744+
== "/oauth2/sign_out?rd=https%3A%2F%2Fexample.com%2Fend_session"
745745
)
746-
assert response.headers.get("location") == oidc_config.logout_redirect_endpoint
747746

748747

749748
@pytest.mark.parametrize("has_oidc_config", [True, False])

0 commit comments

Comments
 (0)