Skip to content

Commit 2483fa6

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

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

apricot/oauth/keycloak_client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ 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(
57+
group_dict["attributes"]["gid"]
58+
) == 1:
5759
self.uid_cache.overwrite_group_uid(
58-
group_dict["id"], int(group_gid, 10)
60+
group_dict["id"], int(group_gid[0], 10)
5961
)
6062

6163
# Read group attributes
@@ -72,7 +74,7 @@ def groups(self) -> list[JSONDict]:
7274
attributes: JSONDict = {}
7375
attributes["cn"] = group_dict.get("name", None)
7476
attributes["description"] = group_dict.get("id", None)
75-
attributes["gidNumber"] = group_dict["attributes"]["gid"]
77+
attributes["gidNumber"] = group_dict["attributes"]["gid"][0]
7678
attributes["oauth_id"] = group_dict.get("id", None)
7779
# Add membership attributes
7880
members = self.query(
@@ -107,9 +109,11 @@ def users(self) -> list[JSONDict]:
107109
# If user_uid exists then set the cache to the same value.
108110
# This ensures that any groups without a `gid` attribute will receive a
109111
# UID that does not overlap with existing groups
110-
if user_uid := user_dict["attributes"]["uid"]:
112+
if (user_uid := user_dict["attributes"]["uid"]) and len(
113+
user_dict["attributes"]["uid"]
114+
) == 1:
111115
self.uid_cache.overwrite_user_uid(
112-
user_dict["id"], int(user_uid, 10)
116+
user_dict["id"], int(user_uid[0], 10)
113117
)
114118

115119
# Read user attributes
@@ -139,12 +143,12 @@ def users(self) -> list[JSONDict]:
139143
attributes["displayName"] = full_name
140144
attributes["mail"] = user_dict.get("email")
141145
attributes["description"] = ""
142-
attributes["gidNumber"] = user_dict["attributes"]["uid"]
146+
attributes["gidNumber"] = user_dict["attributes"]["uid"][0]
143147
attributes["givenName"] = first_name if first_name else ""
144148
attributes["homeDirectory"] = f"/home/{username}" if username else None
145149
attributes["oauth_id"] = user_dict.get("id", None)
146150
attributes["sn"] = last_name if last_name else ""
147-
attributes["uidNumber"] = user_dict["attributes"]["uid"]
151+
attributes["uidNumber"] = user_dict["attributes"]["uid"][0]
148152
output.append(attributes)
149153
except KeyError:
150154
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)