Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 1 addition & 48 deletions ansys/rep/client/auth/api/auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,53 +40,6 @@ def __init__(self, client):
def url(self):
return f"{self.client.rep_url}/auth/"

# def __init__(
# self,
# rep_url,
# *,
# realm: str = "rep",
# username: str = "repadmin",
# password: str = "repadmin",
# grant_type: str = "password",
# scope="openid",
# client_id: str = "rep-cli",
# client_secret: str = None,
# ):

# self.rep_url = rep_url
# self.auth_api_url = self.rep_url + f"/auth/"

# self.username = username
# self.password = password
# self.realm = realm
# self.grant_type = grant_type
# self.scope = scope
# self.client_id = client_id
# self.client_secret = client_secret

# tokens = authenticate(
# url=self.rep_url,
# realm=realm,
# grant_type=grant_type,
# scope=scope,
# client_id=client_id,
# client_secret=client_secret,
# username=username,
# password=password,
# )
# self.access_token = tokens["access_token"]

# self.session = create_session(self.access_token)
# self.session.headers["content-type"] = "application/json"

# # register hook to handle expiring of the refresh token
# self.session.hooks["response"] = [raise_for_status]

# def get_api_info(self):
# """Return info like version, build date etc of the Auth API the client is connected to."""
# r = self.session.get(self.auth_api_url)
# return r.json()

def get_users(self, as_objects=True):
"""Return a list of users."""
return get_users(self.client, as_objects=as_objects)
Expand All @@ -107,7 +60,7 @@ def update_user(self, user, as_objects=True):
user (:class:`ansys.rep.client.auth.User`): A User object. Defaults to None.
as_objects (bool, optional): Defaults to True.
"""
return update_user(self, user, as_objects=as_objects)
return update_user(self.client, user, as_objects=as_objects)

def delete_user(self, user):
"""Delete an existing user.
Expand Down
9 changes: 6 additions & 3 deletions ansys/rep/client/auth/resource/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ def __init__(self, **kwargs):


def _admin_client(client):
raise NotImplementedError("KeycloakAdmin currently doesn't support a token auth workflow. TODO")

custom_headers = {
"Authorization": "Bearer " + client.access_token,
"Content-Type": "application/json",
}
keycloak_admin = KeycloakAdmin(
server_url=client.auth_api_url,
username=None,
password=None,
realm_name=client.realm,
# refresh_token=client.refresh_token,
# access_token=client.access_token,
client_id=client.client_id,
verify=False,
custom_headers=custom_headers,
)
return keycloak_admin

Expand Down
7 changes: 4 additions & 3 deletions tests/auth/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Author(s): O.Koenig
# ----------------------------------------------------------
import logging
import uuid

from ansys.rep.client import Client
from ansys.rep.client.auth import AuthApi, User
Expand All @@ -25,11 +26,11 @@ def test_auth_client(self):
if user.username == self.username and not user.is_admin:
return

username = f"test_user_{self.run_id}"
username = f"test_user_{uuid.uuid4()}"
new_user = User(
username=username,
password="test_auth_client",
email="test_auth_client@test.com",
email=f"{username}@test.com",
first_name="Test",
last_name="User",
)
Expand All @@ -38,7 +39,7 @@ def test_auth_client(self):
self.assertEqual(new_user.username, username)
self.assertEqual(new_user.first_name, "Test")
self.assertEqual(new_user.last_name, "User")
self.assertEqual(new_user.email, "test_auth_client@test.com")
self.assertEqual(new_user.email, f"{username}@test.com")

new_user.email = "update_email@test.com"
new_user.last_name = "Smith"
Expand Down