Skip to content

Commit eb97098

Browse files
committed
Update docs and status code changes
1 parent 0f250ae commit eb97098

5 files changed

Lines changed: 28 additions & 17 deletions

File tree

docs/how-to/authenticate.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Authenticate to BlueAPI
1+
> [!NOTE]
2+
> If you are using `oauth2-proxy` to secure the Swagger UI documentation page, you can log out by visiting the `/logout` URL. For this to work correctly, ensure that the blueapi server is configured with
3+
> `oidc.logout_redirect_endpoint` set to `/oauth2/sign_out`, which is required for `oauth2-proxy`.
4+
5+
# Authenticate to BlueAPI-Cli
26

37
## Introduction
48
BlueAPI provides a secure and efficient way to interact with its services. This guide walks you through the steps to log in and log out using BlueAPI with OpenID Connect (OIDC) authentication.
@@ -63,9 +67,3 @@ To log out and securely remove the cached access token, follow these steps:
6367
```
6468
Logged out
6569
```
66-
67-
68-
> [!NOTE]
69-
> The login and logout instructions above apply to the CLI. If you are using `oauth2-proxy` to secure the Swagger
70-
> UI documentation page, you can log out by visiting the `/logout` URL. For other OIDC providers, update the
71-
> `oidc.logout_redirect_endpoint` configuration to the appropriate logout endpoint.

docs/reference/openapi.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ components:
9393
title: Client Id
9494
type: string
9595
logout_redirect_endpoint:
96-
default: /oauth2/sign_out
96+
anyOf:
97+
- type: string
98+
- type: 'null'
9799
description: The oidc endpoint required to logout
98100
title: Logout Redirect Endpoint
99-
type: string
100101
well_known_url:
101102
description: URL to fetch OIDC config from the provider
102103
title: Well Known Url

src/blueapi/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class OIDCConfig(BlueapiBaseModel):
162162
)
163163
client_id: str = Field(description="Client ID")
164164
client_audience: str = Field(description="Client Audience(s)", default="blueapi")
165-
logout_redirect_endpoint: str = Field(
166-
description="The oidc endpoint required to logout", default="/oauth2/sign_out"
165+
logout_redirect_endpoint: str | None = Field(
166+
description="The oidc endpoint required to logout", default=None
167167
)
168168

169169
@cached_property

src/blueapi/service/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ def health_probe() -> HealthProbeResponse:
536536

537537

538538
@secure_router.get("/logout", include_in_schema=False)
539-
def logout(runner: Annotated[WorkerDispatcher, Depends(_runner)]) -> RedirectResponse:
539+
def logout(runner: Annotated[WorkerDispatcher, Depends(_runner)]) -> Response:
540540
"""Redirect to logout url"""
541541
config = runner.run(interface.get_oidc_config)
542-
if config is None:
543-
raise HTTPException(status_code=status.HTTP_204_NO_CONTENT)
542+
if config is None or config.logout_redirect_endpoint is None:
543+
raise HTTPException(status_code=status.HTTP_205_RESET_CONTENT)
544544
return RedirectResponse(
545545
status_code=status.HTTP_308_PERMANENT_REDIRECT,
546546
url=config.logout_redirect_endpoint,

tests/unit_tests/service/test_rest_api.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ def test_logout(
752752
oidc_config: OIDCConfig,
753753
client_authenticated: TestClient,
754754
):
755+
oidc_config.logout_redirect_endpoint = "/oauth2/logout"
755756
mock_runner.run.return_value = oidc_config
756757
client_authenticated.follow_redirects = False
757758
response = client_authenticated.get("/logout")
@@ -760,11 +761,22 @@ def test_logout(
760761
response.headers.get("X-Auth-Request-Redirect")
761762
== oidc_config.end_session_endpoint
762763
)
764+
assert response.headers.get("location") == oidc_config.logout_redirect_endpoint
763765

764766

767+
@pytest.mark.parametrize("has_oidc_config", [True, False])
765768
def test_logout_when_oidc_config_invalid(
766-
mock_runner: Mock, mock_authn_server, client_authenticated: TestClient
769+
has_oidc_config: bool,
770+
mock_runner: Mock,
771+
oidc_config: OIDCConfig,
772+
mock_authn_server,
773+
client_authenticated: TestClient,
767774
):
768-
mock_runner.run.return_value = None
775+
if has_oidc_config:
776+
oidc_config.logout_redirect_endpoint = None
777+
mock_runner.run.return_value = oidc_config
778+
else:
779+
mock_runner.run.return_value = None
780+
769781
response = client_authenticated.get("/logout")
770-
assert response.status_code == status.HTTP_204_NO_CONTENT
782+
assert response.status_code == status.HTTP_205_RESET_CONTENT

0 commit comments

Comments
 (0)