Skip to content

Commit

Permalink
Logout from keycloack
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Nov 6, 2024
1 parent bd13f04 commit f77f77b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ckanext/keycloak/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@

from ckanext.keycloak.views import get_blueprint
from ckanext.keycloak import helpers as h
import ckan.lib.helpers as helpers1

from os import environ
from urllib.parse import quote

from ckan.common import (
_, config, g, request, current_user, login_user, logout_user, session,
repr_untrusted
)


class KeycloakPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IBlueprint)
plugins.implements(plugins.ITemplateHelpers)
plugins.implements(plugins.IAuthenticator, inherit=True)

# IConfigurer

Expand All @@ -27,3 +37,16 @@ def get_helpers(self):
'button_style': h.button_style,
'enable_internal_login': h.enable_internal_login,
}

# IAuthenticator

def logout(self):

server_url = toolkit.config.get('ckanext.keycloak.server_url', environ.get('CKANEXT__KEYCLOAK__SERVER_URL'))
client_id = toolkit.config.get('ckanext.keycloak.client_id', environ.get('CKANEXT__KEYCLOAK__CLIENT_ID'))
realm_name = toolkit.config.get('ckanext.keycloak.realm_name', environ.get('CKANEXT__KEYCLOAK__REALM_NAME'))

redirect_url = helpers1.url_for(u"home.index", _external=True)
encoded_redirect_url = quote(redirect_url, safe='')

return toolkit.redirect_to(f"{server_url}/auth/realms/{realm_name}/protocol/openid-connect/logout?post_logout_redirect_uri={encoded_redirect_url}&client_id={client_id}")

0 comments on commit f77f77b

Please sign in to comment.