Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

KeycloakClient strips realm path when realm URL lacks trailing slash

Aperta Adatta ai principianti
#606 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Inizia da pkg/connectors/keycloak_client.go, in particolare da NewKeycloakClientWithContext, poi esamina pkg/connectors/keycloak_client_test.go. Esegui i test del connector e verifica che un URL del realm senza slash finale mantenga il percorso del realm nelle richieste di configurazione del token e OIDC; il lavoro è completato quando il test di regressione passa per questo input.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

When initializing a KeycloakClient using connectors.NewKeycloakClient or connectors.NewKeycloakClientWithContext, if the provided realmURL does not include a trailing slash (e.g., http://keycloak.example.com/realms/microcks), subsequent requests to obtain tokens or fetch OIDC configuration fail with HTTP 404.

This happens because relative endpoints (protocol/openid-connect/token and .well-known/openid-configuration) are resolved against kc.BaseURL using c.BaseURL.ResolveReference(rel).

Under RFC 3986 relative URL resolution rules, resolving a relative path against a base URL without a trailing slash strips the final path segment (microcks).

As a result, the request resolves to:

http://keycloak.example.com/realms/protocol/openid-connect/token

instead of:

http://keycloak.example.com/realms/microcks/protocol/openid-connect/token

In comparison, MicrocksClient in pkg/connectors/microcks_client.go defensively normalizes its incoming base URL, but KeycloakClient does not.

Expected behavior

NewKeycloakClient and NewKeycloakClientWithContext should ensure that kc.BaseURL.Path ends with a trailing /, so relative endpoints always resolve under the specified realm.

For example:

http://keycloak.example.com/realms/microcks/protocol/openid-connect/token

This should work regardless of whether the input URL includes a trailing slash.

Actual behavior

The realm name is stripped from the URL path.

  • Configured URL: http://keycloak.example.com/realms/microcks
  • Resolved Token URL: http://keycloak.example.com/realms/protocol/openid-connect/token (HTTP 404)
How to Reproduce?
  1. Initialize a KeycloakClient with a realm URL that omits the trailing slash:

    kc, err := connectors.NewKeycloakClientWithContext(
        context.Background(),
        "http://keycloak.example.com/realms/microcks",
        "client-id",
        "client-secret",
    )
    
    
  2. Call kc.ConnectAndGetToken() or kc.GetOIDCConfig().

  3. Inspect the resolved request URL. The realm segment /microcks will be stripped from the path.

Microcks version or git rev

master

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

No response

Additional information

This can be addressed in pkg/connectors/keycloak_client.go, inside NewKeycloakClientWithContext, by ensuring that the URL path always ends with a trailing slash:

if !strings.HasSuffix(u.Path, "/") {
    u.Path += "/"
}

Along with a unit test in pkg/connectors/keycloak_client_test.go covering a realm URL with a subpath.

Lingua principale
Go
Stelle
59
Fork
74
Merge medio
4g 8h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microcks/microcks-cli

Tutte le issue di microcks/microcks-cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.