Documentation lacking on how to connect to an existing keycloak
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
In the documentation it says you can use an existing keycloak by using the AddConnectionString() approach.
https://github.com/dotnet/docs-aspire/blob/47fc67af9059d9dcd132609f2ce6ad1523da1d98/docs/authentication/keycloak-integration.md?plain=1#L78
However it doesn't detail how this should work i.e. the structure of the connection string. When I've tried this myself, my services are just stuck in the waiting for keycloak to start.
Additionally builder.AddKeycloak("keycloak", 8080) is not interchangeable with builder.AddConnectionString("keycloak").
i.e. the former returns an IResourceBuilder< KeycloakResource >? where as, the latter returns IResourceBuilder< IResourceWithConnectionString >.
Conversely when compared to something like Azure Table storage, both the AddTables And AddConnectionString are interchangeable.
You can see the difference here:
```
public class AzureTableStorageResource(string name, AzureStorageResource storage) : Resource(name),
IResourceWithConnectionString,
IResourceWithParent
public sealed class KeycloakResource(string name, ParameterResource? admin, ParameterResource adminPassword)
: ContainerResource(ThrowIfNull(name)), IResourceWithServiceDiscovery
```
### Discussed in https://github.com/dotnet/aspire/discussions/7064
Originally posted by **iamandymcinnes** January 10, 2025
I've been using the AddKeycloak() extension during initial development to spin up a Keycloak container for local development, but as I'm trying to move toward releasing something I wanted to test out connecting to an existing Keycloak instance that's running in AKS. In the docs it recommends using AddConnectionString(), but this is not supported without a cast to IResourceBuilder, so I just wondered if I am missing something?
Thanks in advance
```
var keycloak = builder.Environment.IsDevelopment()
? builder.AddKeycloak("keycloak", 8080)
.WithArgs("--features=preview")
// for more details regarding disable-trust-manager
// see https://www.keycloak.org/server/outgoinghttp#_client_configuration_command
// IMPORTANT: use this command ONLY in local development environment!
.When(builder.Environment.IsDevelopment(), x
=> x.WithArgs("--spi-connections-http-client-default-disable-trust-manager=true"))
.WithDataVolume()
.WithRealmImport("../realms")
.RunWithHttpsDevCertificate(port: 8081)
: builder.AddConnectionString("keycloak"); // <<< This won't work
```
Where as table storage for example doesn't need anything extra
```
var tables = builder.Environment.IsDevelopment()
? builder.AddAzureStorage("storage").RunAsEmulator(
azurite =>
{
azurite.WithTablePort(27002);
azurite.WithDataVolume();
}).AddTables("tables")
: builder.AddConnectionString("tables");
```
Contributor guide
Assessment
This issue has not been assessed yet.