Skip to content

Commit a9c03a4

Browse files
committed
feat: user profile metadata parameter for get_user method
1 parent b9f8bd2 commit a9c03a4

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/keycloak/keycloak_admin.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,18 +619,23 @@ def get_user_id(self, username):
619619
users = self.get_users(query={"username": lower_user_name, "max": 1, "exact": True})
620620
return users[0]["id"] if len(users) == 1 else None
621621

622-
def get_user(self, user_id):
622+
def get_user(self, user_id, user_profile_metadata=False):
623623
"""Get representation of the user.
624624
625625
UserRepresentation
626626
https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_userrepresentation
627627
628628
:param user_id: User id
629629
:type user_id: str
630+
:param user_profile_metadata: Whether to include user profile metadata in the response
631+
:type user_profile_metadata: bool
630632
:return: UserRepresentation
631633
"""
632634
params_path = {"realm-name": self.connection.realm_name, "id": user_id}
633-
data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_USER.format(**params_path))
635+
data_raw = self.connection.raw_get(
636+
urls_patterns.URL_ADMIN_USER.format(**params_path),
637+
userProfileMetadata=user_profile_metadata,
638+
)
634639
return raise_error_from_response(data_raw, KeycloakGetError)
635640

636641
def get_user_groups(self, user_id, query=None, brief_representation=True):
@@ -4922,19 +4927,22 @@ async def a_get_user_id(self, username):
49224927
)
49234928
return users[0]["id"] if len(users) == 1 else None
49244929

4925-
async def a_get_user(self, user_id):
4930+
async def a_get_user(self, user_id, user_profile_metadata=False):
49264931
"""Get representation of the user asynchronously.
49274932
49284933
UserRepresentation
49294934
https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_userrepresentation
49304935
49314936
:param user_id: User id
49324937
:type user_id: str
4938+
:param user_profile_metadata: whether to include user profile metadata in the response
4939+
:type user_profile_metadata: bool
49334940
:return: UserRepresentation
49344941
"""
49354942
params_path = {"realm-name": self.connection.realm_name, "id": user_id}
49364943
data_raw = await self.connection.a_raw_get(
4937-
urls_patterns.URL_ADMIN_USER.format(**params_path)
4944+
urls_patterns.URL_ADMIN_USER.format(**params_path),
4945+
userProfileMetadata=user_profile_metadata,
49384946
)
49394947
return raise_error_from_response(data_raw, KeycloakGetError)
49404948

0 commit comments

Comments
 (0)