dasniko / testcontainers-keycloak

A Testcontainer implementation for Keycloak IAM & SSO.
Apache License 2.0
328 stars 51 forks source link

Provide methods to add users programmatically #43

Closed GregJohnStewart closed 2 years ago

GregJohnStewart commented 2 years ago

I would love it if there was a way to add a user programmatically.

I realize I could probably do so using the admin endpoints, but that seems hefty to do by hand.

My particular use-case is that I would like to create new, random users for use in testing rather than rely on users already existing. This helps keep tests threadsafe and (ideally) less brittle.

jmax01 commented 2 years ago

Have you tried using the keycloak-admin-client?

    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-admin-client</artifactId>
    </dependency>
dasniko commented 2 years ago

Providing an option to create any kind of resources (no matter if users, clients, etc.) would result in either a very opinionated way to create the resources which will only be suitable for very few users or in an interface that will be very similar to the admin api models, to be flexible enough.

So, I will also argue to use the admin client (this will be available as a transitive dependency beginning with v2.x) or to create a ready configured and exported realm JSON with any resources included.

GregJohnStewart commented 2 years ago

Makes sense, though I might argue it's a little of a hassle to do it separately with the admin client (though this is how I have currently implemented it). Alternatively, might be a thing to be able to get the Keycloak admin-configured object directly from the container object.

Just some ease-of-life suggestions!

dasniko commented 2 years ago

This (getting the admin client directly from container) will be the case with v2.x, when Keycloak-X is available. I don't want to change dependencies for v1.x for the rest of its lifetime.