Create user via Rest api

Hello,

Im Stuck on the Realm Management configuration / user creation.

I have a Service in a Bearer-only mode that calls the keycloak rest api to create a new user.
Then I created a Registration access token and I put it in side my app


Then, try it inside my app, I do the following things :

Response response = client.target("https://myhost.com/auth/admin").path("realms").path("myrealm").path("users")
.request(MediaType.APPLICATION_JSON_TYPE)
.header("Authorization", "Bearer " + bearer) //where bearer is the `Registration access token`
.post(Entity.entity(new User("to...@toto.toto"), MediaType.APPLICATION_JSON_TYPE));
System.out.println(response.readEntity(String.class));

And I get the following response:

<html><head><title>Error</title></head><body>403 - Forbidden</body></html>

For me 401 mean : Im authenticate but the resources is not under my permission
403 mean : Im not authenticate and try to access protected resources
Maybe I dont have the right token, and I need to ask for a token but when I do it I have a response like bearer-only not allowed
Or maybe I dont have the correct right inside Realm management, So I try to add it everywhere inside client/realm-management/Authorization/permissions but the same issue occurs

Have you ideas ?

Best Regards,

Romain.

Hi,

First, how you’re authenticating the client?
You need to verify if the user at token that you’re providing has permissions to create users, such admin or realm-management.

Go to clients > (Current client that generate the token) > Roles