Skip to content

Commit 29e2e57

Browse files
committed
Fix fetching of uid from multi value attribute fix naming issue for mirrored groups parameter
1 parent f986e41 commit 29e2e57

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

apricot/oauth/keycloak_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def groups(self) -> list[JSONDict]:
5353
# If group_gid exists then set the cache to the same value
5454
# This ensures that any groups without a `gid` attribute will receive a
5555
# UID that does not overlap with existing groups
56-
if group_gid := group_dict["attributes"]["gid"]:
56+
if (group_gid := group_dict["attributes"]["gid"]) and len(group_dict["attributes"]["gid"]) == 1:
5757
self.uid_cache.overwrite_group_uid(
58-
group_dict["id"], int(group_gid, 10)
58+
group_dict["id"], int(group_gid[0], 10)
5959
)
6060

6161
# Read group attributes
@@ -72,7 +72,7 @@ def groups(self) -> list[JSONDict]:
7272
attributes: JSONDict = {}
7373
attributes["cn"] = group_dict.get("name", None)
7474
attributes["description"] = group_dict.get("id", None)
75-
attributes["gidNumber"] = group_dict["attributes"]["gid"]
75+
attributes["gidNumber"] = group_dict["attributes"]["gid"][0]
7676
attributes["oauth_id"] = group_dict.get("id", None)
7777
# Add membership attributes
7878
members = self.query(
@@ -107,9 +107,9 @@ def users(self) -> list[JSONDict]:
107107
# If user_uid exists then set the cache to the same value.
108108
# This ensures that any groups without a `gid` attribute will receive a
109109
# UID that does not overlap with existing groups
110-
if user_uid := user_dict["attributes"]["uid"]:
110+
if (user_uid := user_dict["attributes"]["uid"]) and len(user_dict["attributes"]["uid"]) == 1:
111111
self.uid_cache.overwrite_user_uid(
112-
user_dict["id"], int(user_uid, 10)
112+
user_dict["id"], int(user_uid[0], 10)
113113
)
114114

115115
# Read user attributes
@@ -139,12 +139,12 @@ def users(self) -> list[JSONDict]:
139139
attributes["displayName"] = full_name
140140
attributes["mail"] = user_dict.get("email")
141141
attributes["description"] = ""
142-
attributes["gidNumber"] = user_dict["attributes"]["uid"]
142+
attributes["gidNumber"] = user_dict["attributes"]["uid"][0]
143143
attributes["givenName"] = first_name if first_name else ""
144144
attributes["homeDirectory"] = f"/home/{username}" if username else None
145145
attributes["oauth_id"] = user_dict.get("id", None)
146146
attributes["sn"] = last_name if last_name else ""
147-
attributes["uidNumber"] = user_dict["attributes"]["uid"]
147+
attributes["uidNumber"] = user_dict["attributes"]["uid"][0]
148148
output.append(attributes)
149149
except KeyError:
150150
pass

run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
parser.add_argument("-p", "--port", type=int, default=1389, help="Port to run on.")
1818
parser.add_argument("-s", "--client-secret", type=str, help="OAuth client secret.")
1919
parser.add_argument("--disable-mirrored-groups", action="store_false",
20-
dest="enable_mirrored", default=True,
20+
dest="enable_mirrored_groups", default=True,
2121
help="Disable creation of mirrored groups.")
2222
parser.add_argument("--debug", action="store_true", help="Enable debug logging.")
2323
# Options for Microsoft Entra backend

0 commit comments

Comments
 (0)