We need to import hundreds of users to Keycloak from csv-file. I haven't found any ready-made import functionality to do this.
Has anyone made any import routine or at least some skeleton to build on? REST API is probably the only way to do it - or is there another way?
I've recently build something like that in Java. You can use the REST Api, but there is also the admin-client. See Programmatically adding users in Keycloak for some pointers. It should be trivial to add CSV support for that using e.g. Apache Commons CSV.
Basically you can add a Maven dependency:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>1.4.0.Final</version>
</dependency>
And use it like this:
Keycloak kc = Keycloak.getInstance(
"http://localhost:8080/auth",
"master", // the realm to log in to
"admin", "password", // the user
"security-admin-console");
CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue("test123");
UserRepresentation user = new UserRepresentation();
user.setUsername("testuser");
user.setFirstName("Test");
user.setLastName("User");
user.setCredentials(Arrays.asList(credential));
kc.realm("master").users().create(user);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With