Skip to content

Commit

Permalink
♻️ Alphabetise Keycloak attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jemrobinson committed Oct 23, 2024
1 parent 64dbbc7 commit 15c7641
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions apricot/oauth/keycloak_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ class KeycloakClient(OAuthClient):
def __init__(
self: Self,
keycloak_base_url: str,
keycloak_realm: str,
keycloak_domain_attribute: str,
keycloak_realm: str,
**kwargs: Any,
) -> None:
"""Initialise a KeycloakClient.
@param keycloak_base_url: Base URL for Keycloak server
@param keycloak_domain_attribute: Keycloak attribute used to define your domain
@param keycloak_realm: Realm for Keycloak server
"""
self.base_url = keycloak_base_url
self.realm = keycloak_realm
self.domain_attribute = keycloak_domain_attribute
self.realm = keycloak_realm

redirect_uri = "urn:ietf:wg:oauth:2.0:oob" # this is the "no redirect" URL
scopes: list[str] = [] # this is the default scope
Expand Down Expand Up @@ -153,18 +154,18 @@ def users(self: Self) -> list[JSONDict]:
username = user_dict.get("username")
attributes: JSONDict = {}
attributes["cn"] = username
attributes["uid"] = username
attributes["oauth_username"] = username
attributes["displayName"] = full_name
attributes["mail"] = user_dict.get("email")
attributes["description"] = ""
attributes["displayName"] = full_name
attributes["domain"] = user_dict["attributes"].get(self.domain_attribute, [None])[0]
attributes["gidNumber"] = user_dict["attributes"]["uid"][0]
attributes["givenName"] = first_name or ""
attributes["homeDirectory"] = f"/home/{username}" if username else None
attributes["mail"] = user_dict.get("email")
attributes["oauth_id"] = user_dict.get("id", None)
attributes["oauth_username"] = username
attributes["sn"] = last_name or ""
attributes["uid"] = username
attributes["uidNumber"] = user_dict["attributes"]["uid"][0]
attributes["domain"] = user_dict["attributes"].get(self.domain_attribute, [None])[0]
output.append(attributes)
except KeyError:
pass
Expand Down

0 comments on commit 15c7641

Please sign in to comment.