lvermeulen / Keycloak.Net

C# client for Keycloak 6.x
MIT License
204 stars 119 forks source link

How to create a new user with client roles #18

Closed jScope closed 4 years ago

jScope commented 4 years ago

Hello,

I have a basic question and I hope you can help me. Probably it's very stupid.

I'm able to create new users without problems but now I would like to pass client roles with the new user on create. I have to pass a dictionary<string, object> but how does the dictionary really have to look like if I want to pass multiple client-roles for multiple clients?

At the moment I pass it like this but the role is not assigned to the new user afterwards. ClientRoles = new Dictionary<string, object>() { { "client_name", new string[] { "client_role_name" } }

Can you please give a simple example.

Thank you very much!

lvermeulen commented 4 years ago

Hi @jScope , to be perfectly honest I have no idea. I was using Keycloak in a previous project, but I'm not anymore. Maybe someone who's reading this can help you out?

jScope commented 4 years ago

Hello @lvermeulen,

thank you for your quick reply. From my current investigations it looks like that Keycloak Admin REST Api really wants each resource update in seperate request. So I have to create the user as I do already and then add roles to the created user. I found the desired method AddClientRoleMappingsToUserAsync for that task in your library under ClientRoleMappings folder.

So you don't plan to update this package with ongoing Keycloak releases? I just ask because you did a release of this package recently and it's very helpful.

At the moment there doesn't seem to be any better mentained alternatives for .Net.

lvermeulen commented 4 years ago

Hi @jScope , I did a little bit of investigating into this issue. Here's what I found:

When this is ever added to the API, and you give me a signal, I am perfectly willing to add this in.