Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1338 | refactoring and extracting routes
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 2, 2022
1 parent 43e570c commit 101260f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions core/common/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def create_user(_):

class OIDCAuthService(AbstractAuthService):
token_type = 'Bearer'
USERS_URL = settings.OIDC_SERVER_INTERNAL_URL + f'/admin/realms/{settings.OIDC_REALM}/users'
OIDP_ADMIN_TOKEN_URL = settings.OIDC_SERVER_INTERNAL_URL + '/realms/master/protocol/openid-connect/token'

@staticmethod
def credential_representation_from_hash(hash_, temporary=False):
Expand All @@ -305,7 +307,7 @@ def credential_representation_from_hash(hash_, temporary=False):
@classmethod
def add_user(cls, user):
response = requests.post(
settings.OIDC_SERVER_INTERNAL_URL + '/admin/realms/ocl/users',
cls.USERS_URL,
json=dict(
enabled=True,
emailVerified=user.verified,
Expand All @@ -332,7 +334,7 @@ def get_token(self):
@staticmethod
def get_admin_token():
response = requests.post(
settings.OIDC_SERVER_INTERNAL_URL + '/realms/master/protocol/openid-connect/token/',
OIDCAuthService.OIDP_ADMIN_TOKEN_URL,
data=dict(
grant_type='password',
username=settings.KEYCLOAK_ADMIN,
Expand All @@ -353,7 +355,7 @@ def get_user_headers(self):
@staticmethod
def create_user(data):
response = requests.post(
settings.OIDC_SERVER_INTERNAL_URL + '/admin/realms/ocl/users',
OIDCAuthService.USERS_URL,
json=dict(
enabled=True,
emailVerified=False,
Expand All @@ -373,7 +375,7 @@ def create_user(data):

def __get_all_users(self, headers=None):
response = requests.get(
settings.OIDC_SERVER_INTERNAL_URL + '/admin/realms/ocl/users',
self.USERS_URL,
verify=False,
headers=headers or self.get_admin_headers()
)
Expand All @@ -399,7 +401,7 @@ def update_user(self, data):
if not oid_user_id:
raise Http404()
response = requests.put(
settings.OIDC_SERVER_INTERNAL_URL + f'/admin/realms/ocl/users/{oid_user_id}',
f"{self.USERS_URL}/{oid_user_id}",
json=data,
verify=False,
headers=admin_headers
Expand All @@ -413,14 +415,14 @@ def update_password(self, password):
raise Http404()

requests.put(
settings.OIDC_SERVER_INTERNAL_URL + f'/admin/realms/ocl/users/{oid_user_id}/disable-credential-types',
f"{self.USERS_URL}/{oid_user_id}/disable-credential-types",
json=['password'],
verify=False,
headers=admin_headers
)

response = requests.put(
settings.OIDC_SERVER_INTERNAL_URL + f'/admin/realms/ocl/users/{oid_user_id}/reset-password',
f"{self.USERS_URL}/{oid_user_id}/reset-password",
json=dict(type='password', temporary=False, value=password),
verify=False,
headers=admin_headers
Expand Down

0 comments on commit 101260f

Please sign in to comment.