I am building admin portal where I have to manage auth0 users. Today I ran into an exception (429 too many requests) with the rate limiter on that api “https://AUTH_DOMAIN/api/v2/users/USER_ID/roles”
Current flow of my backend for retrieving users with their roles:
Get all users
Retrieve role for each of the users (a request to “https://AUTH_DOMAIN/api/v2/users/USER_ID/roles” for each of the users to get his role)
Return list of users to UI
Since I have more than 10 users already (and the limit for this endpoint is 10 requests) I started getting errors.
What is the best way to retrieve those roles without actually calling Management API for each user to get the role? Is there a way I can bind the user roles to the metadata with a rule for instance?
Any feedback will be appreciated.
Thanks,
Lyubomir
As an admin for the application I would like to get the roles for each of the users registered for the application - therefore I am not interested in obtaining the role on login.
With this Action in place, when a user logs in, their roles will bind to the app_metadata on that user account which is what I think you were trying to achieve. So when you “Get all users” in your point 1, if the app_metadata is also being returned then the roles will also be returned and you won’t need to use “https://AUTH_DOMAIN/api/v2/users/USER_ID/roles”
Tradeoff here though is that you need to wait for all users to login at least once for the app_metadata to populate.
Think of an application that provides a user administration view where an admin can come in and assign/unassign roles to users and perform other user management tasks. Naturally, this administration view would show a list of users. Alongside the list of users, we want to show each user’s roles. If this view shows the roles for the displayed users based on what’s in those users’ metadata, it will show out-of-date roles if any of those users have not logged in since the time the admin last changed their roles.
We need a way to get up-to-date roles for a list of users. Because the roles must be up to date, we can’t rely on a post-login action.
In a similar situation creating an alternative admin dashboard.
For anyone still looking for an alternative solution here, I think it’s better if we flip this around.
Instead of trying to get all users and their roles, you can get all roles, and then get all those role’s members. Combining this with getting all users allows you to do 3 requests instead on n user requests. This also works if you want to get all your user’s organizations. Get all orgs, then get their members.
This endpoint will allow you to list organization members. By setting the settings parameter fields=roles, you’ll retrieve the roles assigned to each listed member.
To use this parameter, you must include the read:organization_member_roles scope in the token.