Create new user in Keycloak with Admin restful API

Steve Mu
2 min readOct 24, 2022

--

warning: I don’t consider the approach in this article is optimizal anymore. In this article, I used the admin-client in the master realm, but I think it is better to create a client in a specific realm and assign proper “service accounts roles” for it, such as the “manage-users” role:

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

I have a Nextjs app where I have a customer registration screen in the app, so when a new user registers, I need to make a API request to a keycloak server to create a new user. I used the Admin Rest API.

First, in the master realm, find the admin-cli client, turn Client authentication On, and Server accounts roles as On:

Then, in Clients -> admin-cli -> Service accounts roles, assign the admin role.

Then get the access token:

Then use the token to create the user:

--

--