Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

KeycloakClient strips realm path when realm URL lacks trailing slash

未关闭 适合新手
#606 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
23

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microcks/microcks-cli 的其他 Issue

查看 microcks/microcks-cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。