Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify user id when creating user in keycloak

Tags:

keycloak

I'm investigating a migration process from a legacy system into keycloak. Based on some of the ideas here: https://github.com/Smartling/keycloak-user-migration-provider we're looking to create user accounts in keycloak at the point of login by looking up user credentials from some dedicated endpoints on our legacy system.

As part of this, I need the user ID to remain the same as it was in the legacy system.

Is it possible to create a user with a specified ID rather than relying on keycloak to auto-generate it?

like image 315
xanld Avatar asked Oct 02 '17 16:10

xanld


2 Answers

Running into this issue when attempting to create users via the API, I looked into the code for the users service. It looks like it is currently not possible to set the user id due to how the user is created.

From the code in https://github.com/keycloak/keycloak/blob/master/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java specifically on line https://github.com/keycloak/keycloak/blob/7cfe6addf01676939206e034a87c791460031032/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java#L115 the user is first created using the username, then updated. I believe id is not an updatable field. Thus it is not currently possible.

like image 51
Jeremy Giberson Avatar answered Oct 12 '22 22:10

Jeremy Giberson


Checking the api I see it is now possible to add an optional "id" field in the userRepresentation object that you pass to create a new user in keycloak.

Find more information here: https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_userrepresentation

like image 36
eum602 Avatar answered Oct 12 '22 20:10

eum602