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:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Steve Mu
Steve Mu

No responses yet

Write a response