Skip to content

Commit

Permalink
Merge pull request #73 from pehala/rhsso_auth_endpoint
Browse files Browse the repository at this point in the history
Fix running with newer Keycloak versions
  • Loading branch information
pehala authored Sep 6, 2022
2 parents 602b03e + 532c185 commit 725f790
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions testsuite/rhsso/objects.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Object wrappers of RHSSO resources"""
from urllib.parse import urlparse

from keycloak import KeycloakOpenID, KeycloakAdmin
from keycloak import KeycloakOpenID, KeycloakAdmin, KeycloakPostError


class Realm:
Expand Down Expand Up @@ -93,15 +93,24 @@ class RHSSO:
"""Helper class for RHSSO server"""

def __init__(self, server_url, username, password) -> None:
# python-keycloak API requires url to be pointed at auth/ endpoint
# pylint: disable=protected-access
self.server_url = urlparse(server_url)._replace(path="auth/").geturl()
self.master = KeycloakAdmin(server_url=self.server_url,
username=username,
password=password,
realm_name="master",
verify=False,
auto_refresh_token=['get', 'put', 'post', 'delete'])
try:
self.master = KeycloakAdmin(server_url=server_url,
username=username,
password=password,
realm_name="master",
verify=False,
auto_refresh_token=['get', 'put', 'post', 'delete'])
self.server_url = server_url
except KeycloakPostError:
# Older Keycloaks versions (and RHSSO) needs requires url to be pointed at auth/ endpoint
# pylint: disable=protected-access
self.server_url = urlparse(server_url)._replace(path="auth/").geturl()
self.master = KeycloakAdmin(server_url=self.server_url,
username=username,
password=password,
realm_name="master",
verify=False,
auto_refresh_token=['get', 'put', 'post', 'delete'])

def create_realm(self, name: str, **kwargs) -> Realm:
"""Creates new realm"""
Expand Down

0 comments on commit 725f790

Please sign in to comment.