Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

KeycloakClient strips realm path when realm URL lacks trailing slash

オープン 初心者向け
#606 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go

調査の方向性

pkg/connectors/keycloak_client.go、特に NewKeycloakClientWithContextから始め、その後pkg/connectors/keycloak_client_test.goを確認してください。connectorのテストを実行し、末尾にスラッシュのないrealm URLでも、tokenおよびOIDCの設定リクエストでrealmのパスが保持されることを確認してください。この入力に対する回帰テストが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
59
フォーク
74
平均マージ
4日 8時間
マージ済み PR(30日)
23

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microcks/microcks-cli のほかの issue

microcks/microcks-cli の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。