auth0 / auth0-java

Java client library for the Auth0 platform
https://auth0.com
MIT License
286 stars 131 forks source link

Filter Users by role and metadata #514

Closed hantsy closed 1 year ago

hantsy commented 1 year ago

I used https://github.com/auth0/auth0-java in my project(Spring Boot 3.0/Java 17/Kotlin), try to filter users by role and app metadata.


val roleId =  api.roles().list(RolesFilter()).execute().items.firstOrNull { it.name == roleName }?.id 
.... 
val users=api.roles().listUsers(roleId, PageFilter().withPage(offset / limit, limit).withTotals(true)).execute()  ``` 

But  `PageFilter` can not add app metadata as filter condition.
jimmyjames commented 1 year ago

👋 Hi @hantsy, I don't see any filter params available on the API to that pertain to app metadata? It appears the endpoint only supports paging params: https://auth0.com/docs/api/management/v2#!/Roles/get_role_user

Let us know if I'm looking at the wrong endpoint or if you are able to apply filters to the endpoint that aren't documented. Thanks!

hantsy commented 1 year ago

There is a requirement from our project.

We need to filter users by role and some specific attributes(we save them into the app_metadata when we created a user).

jimmyjames commented 1 year ago

@hantsy are you requesting a new feature to the management API, or for this SDK to support an existing feature in the Management API? If the API supports this ability, please provide an example of it so we can understand if/why it is not documented as part of the public API. If it's not available in the API, you should work with your sales rep to request the feature or work with support. Thanks!

daniel-johns-99 commented 1 year ago

Hi @jimmyjames, Can we suggest updating the SDK to reflect the management API? I.e. for the ListByEmail method, it indicates that you can pass any filter to it https://github.com/auth0/auth0-java/blob/d82d7834adf5177041f48054a126f864e59bd1fb/src/main/java/com/auth0/client/mgmt/UsersEntity.java#L53

However, from the API there is no option to pass a filter, so the SDK should also not let a filter parameter be added. https://auth0.com/docs/api/management/v2#!/Users_By_Email/get_users_by_email

jimmyjames commented 1 year ago

Hi @daniel-johns-99 - the get_users_by_email endpoint does allow a fields filter, see the parameters section beneath the API description:

image
jimmyjames commented 1 year ago

@hantsy just to follow up, the get a role's users endpoint does not support filtering by role or or app metadata (unless I'm missing something, but I don't see that available). The PageFilter is used to configure the paging options as described in the API's documentation.

If you wish the endpoint to support this feature, you should work with support as mentioned.

Unless there is additional info I'm missing, I'll plan on closing this issue end of week. Thanks!

hantsy commented 1 year ago

There is no APIs to search users by roles and user attributes at the same time. OK, will ask Auth0 support, we paid the auth0 service in the production.

kronaemmanuel commented 1 year ago

@hantsy I was having the same problem, I've created a feature request for it. You can vote for it here: https://community.auth0.com/t/ability-to-specify-users-role-in-search-criteria-in-users-list-endpoint/99873

jimmyjames commented 1 year ago

Great, thanks @hantsy and @kronaemmanuel! I'm going to close this issue; if changes are made to the API to support the feature we can then add support to the SDK.