<p dir="ltr">Creating a user through admin rest is 3 requests. Create user, update credentials, assign roles. Not very elegant that&#39;s true and we will improve it eventually.</p>
<div class="gmail_quote">On 17 Mar 2016 19:24, &quot;Lohitha Chiranjeewa&quot; &lt;<a href="mailto:kalc04@gmail.com">kalc04@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">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&#39;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">&lt;<a href="mailto:daniele.capasso@dnshosting.it" target="_blank">daniele.capasso@dnshosting.it</a>&gt;</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&lt;String, List&lt;String&gt;&gt;(){{<br>
        put(kcApi.getKeycloakCurrentClient(),Arrays.asList(&quot;ROLE_USER_HOST&quot;));<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" target="_blank">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>
<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>