Hi all,
I assigned roles to my users.
When I call the management API to get the list of all users registered, I would like to read also the roles that I have assigned before.
How can I do it?
Thank you so much
Hi @fabijay88!
This will take a small bit of scripting to create, and you have two options to accomplish this.
Get roles by user
- get all of your users. /api/v2/users
- run each user_id against this endpoint to get respective roles /api/v2/users/{id}/roles
OR
Get users by roles
- get all of your roles /api/v2/roles
- run each rule_id against this endpoint to get respective users /api/v2/roles/{id}/users
Let me know if this helps you .
Hi dan.woda,
Yes, I already implemented the first option, but I’m wondering if there is no way to get the roles assigned to my users with the autentication token.
I think I need more information to understand what you want to accomplish. Could you give an example?
I would like to get a list of all my users,and show results in data grids. I would like to see also all the roles that I assigned previously to the users.
John Doe | johndoe@gmail.com | “Admin”,“Staff” | ecc…
I would like to read roles and showing them in the data grid with all other user’s information.
It sounds like you will want add the user’s roles to the user object you originally received from the management api. I would be happy to help walk through this if it all sounds right.
Yes, exactly! I would like to do that!
Do you currently have an application that interfaces with the management API or are you just using the explorer? If so, what language/framework are you using?
From the react frontend I’m calling a .net core api that calls auth0 management Api.
Hello,
The user’s assigned roles are available in context.authorization.roles
in the rules context. You use that data to then add the roles to the tokens (with context.accessToken or context.idToken with a custom claim).
We are working on updating the documentation (Context Object Properties in Rules) to reflect this.
Regards,
Justin
Yes, it’s not very clear inside auth0, but justin’s answer helped me to find the solution.
Rules-> Set roles to user->
Then customize the function and access the context.authorization.roles to read the roles assigned to users and adding them into the token.
Thank you Justin.
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.