A pre-configured testcontainers container for Keycloak.
In addition to the default container configuration, it is also possible to specify realms, clients and users that should be created before the container is considered started:
var client = new Client("demoapp", new("http://localhost:8000/*")) { Secret = "client_secret" };
var user = new User("john.doe", "password123");
var realmConfiguration = new RealmConfiguration("demorealm", new List<Client> { client }, new List<User> { user });
var keycloakConfiguration = new KeycloakTestcontainerConfiguration { Realms = new[] { realmConfiguration } };
await using var keycloak = new TestcontainersBuilder<KeycloakTestcontainer>()
.WithKeycloak(keycloakConfiguration)
.Build();
await keycloak.StartAsync();
After starting the container, additional realm information is available:
var realm = keycloak.Realms.Single();
var realmBaseAddress = realm.ServerRealm;
var oidcMetadat = realm.Metadata;