aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Keycloak Aspire integration: allow configuring a fixed HTTPS authority port for local development

Open enrico23 opened this issue 10 months ago • 8 comments

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 httpsPort parameter to AddKeycloak(...), 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

enrico23 avatar Jan 08 '26 12:01 enrico23

This would be awesome. Yeah, seems odd that I have to manually go configure this for the dev build.

Fieora avatar Jan 29 '26 06:01 Fieora

The lake of this feature causes me pain in the development environment

MarwanTarik avatar Feb 01 '26 10:02 MarwanTarik

@enrico23 Will you work on it, or could I take it?

MarwanTarik avatar Feb 01 '26 10:02 MarwanTarik

I mention this issue in https://discord.com/channels/1361488941836140614/1484216902585946173

Kbdavis007 avatar Mar 19 '26 15:03 Kbdavis007

@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 😊

Kbdavis007 avatar Mar 19 '26 15:03 Kbdavis007

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.

danegsta avatar Mar 19 '26 20:03 danegsta

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));

danegsta avatar Mar 19 '26 21:03 danegsta

Multiple calls to WithEndpoint/WithHttpEndpoint, WithHttpsEndpoint with the same name will now update/upsert the endpoint instead of throw.

davidfowl avatar Apr 11 '26 01:04 davidfowl