Skip to content

Commit

Permalink
Be able to call logout on the OIDC provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 10, 2024
1 parent 138f2eb commit 15155ab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/integrator/authentication_oidc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Other options

``client_secret``: The secret of the client.

``logout``: If ``true``, the logout is called on the OIDC provider, default is ``false``.

``trusted_audiences``: The list of trusted audiences, if the audience provided by the id-token is not in
this list, the ``ID token`` will be rejected.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ mapping:
type: seq
sequence:
- type: str
logout:
type: bool
default: false
provide_roles:
type: bool
default: false
Expand Down
12 changes: 12 additions & 0 deletions geoportal/c2cgeoportal_geoportal/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import pyotp
import pyramid.request
import pyramid.response
import requests
from pyramid.httpexceptions import (
HTTPBadRequest,
HTTPForbidden,
Expand Down Expand Up @@ -298,6 +299,17 @@ def logout(self) -> pyramid.response.Response:
client.revoke_token(user_info["access_token"])
if user_info.get("refresh_token") is not None:
client.revoke_token(user_info["refresh_token"])
if self.authentication_settings.get("openid_connect", {}).get("logout", False):
response = requests.get( # pylint: disable=missing-timeout
client.initiate_logout(), auth=client.client_auth
)
if not response.ok:
_LOG.error(
"Error during logout from OpenID Connect, code %s %s:\n%s",
response.status_code,
response.reason,
response.text,
)

headers = forget(self.request)

Expand Down
4 changes: 2 additions & 2 deletions geoportal/tests/functional/test_mapserverproxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023, Camptocamp SA
# Copyright (c) 2013-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_get_feature_info(self):
self.assertTrue(response.cache_control.public)
assert response.cache_control.max_age == 10
self.assertEqual(
str(response.cache_control), "max-age=10, must-revalidate, no-cache, no-store, public"
str(response.cache_control), "max-age=10, must-revalidate, no-cache, no-store, private"
)

def test_get_map_unprotected_layer_anonymous(self):
Expand Down

0 comments on commit 15155ab

Please sign in to comment.