<div dir="ltr"><div><div>As far as I know, you have to trigger the Assign Client Role (<a href="http://keycloak.github.io/docs/rest-api/index.html#_add_client_level_roles_to_the_user_role_mapping">http://keycloak.github.io/docs/rest-api/index.html#_add_client_level_roles_to_the_user_role_mapping</a>) endpoint to achieve that. Although the payload allows you to supply roles to the Create User endpoint, it doesn't assign any roles underneath. This has been the behavior for a long time.<br><br><br></div>Regards,<br></div>Lohitha.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 17, 2016 at 7:47 PM, <span dir="ltr"><<a href="mailto:daniele.capasso@dnshosting.it" target="_blank">daniele.capasso@dnshosting.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, i want to register a user via keycloak admin client.<br>
<br>
This is the source, it works except for the role, what i wrong?<br>
<br>
CredentialRepresentation credential = new CredentialRepresentation();<br>
credential.setType(CredentialRepresentation.PASSWORD);<br>
credential.setValue(model.getPassword());<br>
credential.setTemporary(false);<br>
<br>
UserRepresentation userRepresentation = new UserRepresentation();<br>
userRepresentation.setEmail(model.getEmail());<br>
userRepresentation.setFirstName(model.getName());<br>
userRepresentation.setLastName(model.getSurname());<br>
userRepresentation.setUsername(model.getEmail());<br>
userRepresentation.setCredentials(Arrays.asList(credential));<br>
userRepresentation.setEnabled(true);<br>
userRepresentation.setClientRoles(new HashMap<String, List<String>>(){{<br>
put(kcApi.getKeycloakCurrentClient(),Arrays.asList("ROLE_USER_HOST"));<br>
}});<br>
<br>
Response resp = kcApi.createUser(userRepresentation);<br>
<br>
<br>
thank you<br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</blockquote></div><br></div>