keycloak-nodejs-admin-client icon indicating copy to clipboard operation
keycloak-nodejs-admin-client copied to clipboard

search users by custom attributes

Open wjh000123 opened this issue 3 years ago • 3 comments

Describe the bug

The test case for searching user by custom attributes is wrong here. By the documentation of keycloak rest api, the search params should be like users.find({ q: 'key1:value1 key2:value2' }), instead of users.find({key: 'value'}).

Type Name Description Schema
Query q A query to search for custom attributes, in the format 'key1:value2 key2:value2' string

Version

16.1.0

Expected behavior

search user by custom attributes, should only return the matched users.

Actual behavior

all users are returned by following the test case code.

How to Reproduce?

user1 has attribute phone = 123, user2 has attribute phone = 456, if use code: users.find({phone: '123'}), two users will be filtered out.

Anything else?

Official rest api documentation links here.

wjh000123 avatar Jan 14 '22 08:01 wjh000123

When will be above bug be resolved?

banjarakunal avatar Mar 31 '22 14:03 banjarakunal

This is also affecting us and it's been best persistent through what, 3-4 major version changes?

The parameters appear to be getting placed in the payload part of the request rather than the query params:

image

Edit: Also, as an aside it's very hard to debug this library. Using axios-debug-log doesn't appear to do anything where you'd expect requests and responses to be logged.

Edit 2: Not sure that the values ending up on the payload prop is the exact problem, but the test specs for user.find() definitely shows behavior that's not actually possible as currently implemented.

c0bra avatar Jun 06 '22 17:06 c0bra

We came across this issue as well and you can use the search field of UserQuery to search by attribute. While I couldn't find good documentation on this it does seem to work.

Example code: const matchingUsers = await client.users.find({ search: custom_attribute: ${custom_attribute_value}, });

Edit: Upon further review it this seems to only work for name email and some other fields but not attributes. So back to square one

josh-nale avatar Jul 11 '22 21:07 josh-nale