Keycloak Aspire integration: allow configuring a fixed HTTPS authority port for local development
Is there an existing issue for this?
- [x] I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Problem
The Aspire Keycloak hosting integration adds an HTTPS endpoint at runtime using:
.WithHttpsEndpoint(targetPort: 8443, env: "KC_HTTPS_PORT")
Impact
The impact is limited but noticeable in local development scenarios.
The Keycloak resource correctly exports a connection string, so dependent
services using WithReference(...) can resolve the authority dynamically.
In many cases this avoids runtime breakage.
However, a non-deterministic HTTPS authority port still causes friction when:
- Using interactive or external OAuth/OIDC clients (e.g., Postman)
- Manually configuring or debugging token acquisition flows
- Working with API gateways, reverse proxies, or tools that cache OIDC metadata
- Writing documentation or scripts that expect a stable authority URL
This is primarily a local development and tooling ergonomics issue, not a production concern. Providing an option to pin the HTTPS host port would improve determinism without changing existing defaults or behavior.
Describe the solution you'd like
Expose a way to configure a fixed HTTPS host port for the Keycloak Aspire integration, while preserving the existing defaults and TLS/dev-certificate behavior.
Concretely, this could be achieved by:
- Adding an optional
httpsPortparameter toAddKeycloak(...), or - Providing an integration-level helper that allows setting the HTTPS endpoint host port.
The goal is not to change default behavior, but to allow deterministic HTTPS authority URLs in local development scenarios when needed.
Additional context
No response
This would be awesome. Yeah, seems odd that I have to manually go configure this for the dev build.
The lake of this feature causes me pain in the development environment
@enrico23 Will you work on it, or could I take it?
I mention this issue in https://discord.com/channels/1361488941836140614/1484216902585946173
@enrico23
Looks like you are working on this?
https://github.com/enrico23/aspire-keycloak-https-port
I am going to give that a shot to see if that helps with my case 😊
Just saw this issue via the Discord post; easiest way to set a fixed HTTPS port would be:
.WithEndpoint("https", ep => ep.Port = <myport>)
There's definitely some ways we can make managing these dynamic HTTPS endpoints easier, but we're still establishing the patterns around the feature. We'll look at opportunities to improve the API in future releases.
It's actually going to need to be:
builder.Eventing.Subscribe<BeforeStartEvent>((_, _) =>
{
keycloak.WithEndpoint("https", ep => ep.Port = 9999);
return Task.CompletedTask;
});
In 13.2 it can be simplified to:
keycloak.SubscribeHttpsEndpointsUpdate(ctx => keycloak.WithEndpoint("https", ep => ep.Port = 9999));
Multiple calls to WithEndpoint/WithHttpEndpoint, WithHttpsEndpoint with the same name will now update/upsert the endpoint instead of throw.