@@ -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 ):
@@ -1149,7 +1154,7 @@ def get_group_by_path(self, path):
11491154 data_raw = self .connection .raw_get (
11501155 urls_patterns .URL_ADMIN_GROUP_BY_PATH .format (** params_path )
11511156 )
1152- return raise_error_from_response (data_raw , KeycloakGetError )
1157+ return raise_error_from_response (data_raw , KeycloakGetError , [ 200 , 404 ] )
11531158
11541159 def create_group (self , payload , parent = None , skip_exists = False ):
11551160 """Create a group in the Realm.
@@ -2124,9 +2129,7 @@ def get_client_roles(self, client_id, brief_representation=True):
21242129 return raise_error_from_response (data_raw , KeycloakGetError )
21252130
21262131 def get_client_role (self , client_id , role_name ):
2127- """Get client role id by name.
2128-
2129- This is required for further actions with this role.
2132+ """Get client role by name.
21302133
21312134 RoleRepresentation
21322135 https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_rolerepresentation
@@ -2135,8 +2138,8 @@ def get_client_role(self, client_id, role_name):
21352138 :type client_id: str
21362139 :param role_name: role's name (not id!)
21372140 :type role_name: str
2138- :return: role_id
2139- :rtype: str
2141+ :return: Role object
2142+ :rtype: dict
21402143 """
21412144 params_path = {
21422145 "realm-name" : self .connection .realm_name ,
@@ -3963,22 +3966,26 @@ def set_events(self, payload):
39633966 )
39643967 return raise_error_from_response (data_raw , KeycloakPutError , expected_codes = [204 ])
39653968
3966- def get_client_all_sessions (self , client_id ):
3969+ def get_client_all_sessions (self , client_id , query = None ):
39673970 """Get sessions associated with the client.
39683971
39693972 UserSessionRepresentation
39703973 https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_usersessionrepresentation
39713974
39723975 :param client_id: id of client
39733976 :type client_id: str
3977+ :param query: Additional query parameters
3978+ :type query: dict
39743979 :return: UserSessionRepresentation
39753980 :rtype: list
39763981 """
3982+ query = query or {}
39773983 params_path = {"realm-name" : self .connection .realm_name , "id" : client_id }
3978- data_raw = self .connection .raw_get (
3979- urls_patterns .URL_ADMIN_CLIENT_ALL_SESSIONS .format (** params_path )
3980- )
3981- return raise_error_from_response (data_raw , KeycloakGetError )
3984+ url = urls_patterns .URL_ADMIN_CLIENT_ALL_SESSIONS .format (** params_path )
3985+ if "first" in query or "max" in query :
3986+ return self .__fetch_paginated (url , query )
3987+
3988+ return self .__fetch_all (url , query )
39823989
39833990 def get_client_sessions_stats (self ):
39843991 """Get current session count for all clients with active sessions.
@@ -4922,19 +4929,22 @@ async def a_get_user_id(self, username):
49224929 )
49234930 return users [0 ]["id" ] if len (users ) == 1 else None
49244931
4925- async def a_get_user (self , user_id ):
4932+ async def a_get_user (self , user_id , user_profile_metadata = False ):
49264933 """Get representation of the user asynchronously.
49274934
49284935 UserRepresentation
49294936 https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_userrepresentation
49304937
49314938 :param user_id: User id
49324939 :type user_id: str
4940+ :param user_profile_metadata: whether to include user profile metadata in the response
4941+ :type user_profile_metadata: bool
49334942 :return: UserRepresentation
49344943 """
49354944 params_path = {"realm-name" : self .connection .realm_name , "id" : user_id }
49364945 data_raw = await self .connection .a_raw_get (
4937- urls_patterns .URL_ADMIN_USER .format (** params_path )
4946+ urls_patterns .URL_ADMIN_USER .format (** params_path ),
4947+ userProfileMetadata = user_profile_metadata ,
49384948 )
49394949 return raise_error_from_response (data_raw , KeycloakGetError )
49404950
@@ -5460,7 +5470,7 @@ async def a_get_group_by_path(self, path):
54605470 data_raw = await self .connection .a_raw_get (
54615471 urls_patterns .URL_ADMIN_GROUP_BY_PATH .format (** params_path )
54625472 )
5463- return raise_error_from_response (data_raw , KeycloakGetError )
5473+ return raise_error_from_response (data_raw , KeycloakGetError , [ 200 , 404 ] )
54645474
54655475 async def a_create_group (self , payload , parent = None , skip_exists = False ):
54665476 """Create a group in the Realm asynchronously.
@@ -6445,19 +6455,14 @@ async def a_get_client_roles(self, client_id, brief_representation=True):
64456455 return raise_error_from_response (data_raw , KeycloakGetError )
64466456
64476457 async def a_get_client_role (self , client_id , role_name ):
6448- """Get client role id by name asynchronously.
6449-
6450- This is required for further actions with this role.
6451-
6452- RoleRepresentation
6453- https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_rolerepresentation
6458+ """Get client role by name asynchronously.
64546459
64556460 :param client_id: id of client (not client-id)
64566461 :type client_id: str
64576462 :param role_name: role's name (not id!)
64586463 :type role_name: str
6459- :return: role_id
6460- :rtype: str
6464+ :return: Role object
6465+ :rtype: dict
64616466 """
64626467 params_path = {
64636468 "realm-name" : self .connection .realm_name ,
@@ -8299,22 +8304,26 @@ async def a_set_events(self, payload):
82998304 )
83008305 return raise_error_from_response (data_raw , KeycloakPutError , expected_codes = [204 ])
83018306
8302- async def a_get_client_all_sessions (self , client_id ):
8307+ async def a_get_client_all_sessions (self , client_id , query = None ):
83038308 """Get sessions associated with the client asynchronously.
83048309
83058310 UserSessionRepresentation
83068311 https://www.keycloak.org/docs-api/24.0.2/rest-api/index.html#_usersessionrepresentation
83078312
83088313 :param client_id: id of client
83098314 :type client_id: str
8315+ :param query: Additional query parameters
8316+ :type query: dict
83108317 :return: UserSessionRepresentation
83118318 :rtype: list
83128319 """
8320+ query = query or {}
83138321 params_path = {"realm-name" : self .connection .realm_name , "id" : client_id }
8314- data_raw = await self .connection .a_raw_get (
8315- urls_patterns .URL_ADMIN_CLIENT_ALL_SESSIONS .format (** params_path )
8316- )
8317- return raise_error_from_response (data_raw , KeycloakGetError )
8322+ url = urls_patterns .URL_ADMIN_CLIENT_ALL_SESSIONS .format (** params_path )
8323+ if "first" in query or "max" in query :
8324+ return await self .a___fetch_paginated (url , query )
8325+
8326+ return await self .a___fetch_all (url , query )
83188327
83198328 async def a_get_client_sessions_stats (self ):
83208329 """Get current session count for all clients with active sessions asynchronously.
0 commit comments