Keycloak OpenID配置响应中缺少KeyClope端口

Keycloak OpenID配置响应中缺少KeyClope端口,keycloak,Keycloak,这件看起来很奇怪。当我通过邮递员或在浏览器中获取OpenID配置时,我会得到一个有效的配置响应 例如,通过邮递员或在浏览器中获取 http://127.0.0.1:8080/auth/realms/myrealm/.well-known/openid-configuration 正确返回包含端口8080的端点: { snip "jwks_uri": "http://127.0.0.1:8080/auth/realms/myrealm/protocol/openid-connect/certs

这件看起来很奇怪。当我通过邮递员或在浏览器中获取OpenID配置时,我会得到一个有效的配置响应

例如,通过邮递员或在浏览器中获取

http://127.0.0.1:8080/auth/realms/myrealm/.well-known/openid-configuration
正确返回包含端口8080的端点:

{
 snip
"jwks_uri": "http://127.0.0.1:8080/auth/realms/myrealm/protocol/openid-connect/certs"
snip
}

但是,在我的C++应用程序中,从非常相同的主机、目标、端口、方案(HTTP)中提取所有的COMI端点,而没有端口(例如8080缺失)

<>我在C++客户端代码中没有看到任何问题,我不知道到底是什么造成了差异。为了完整性,这是在发送请求时,我实际使用的C++代码,虽然这不应该是使用的编程语言:

    req_.version(version); // HTTP 1.1
    req_.method(method); // GET
    req_.target(target); // /auth/realms/myrealm/.well-known/openid-configuration
    req_.set(http::field::host, host); // 127.0.0.1
    static const std::string agent = app.myAgent(); 
    req_.set(http::field::user_agent, agent);
    req_.set(http::field::content_type, contentType); // application/json
我这里有两个问题:

1) 是什么导致Key斗篷不将端口添加到端点?如何解决这个问题


2) 这两个电话有什么区别?这应该是一个普通的GET请求

找到了答案。根据HTTP规范,如果端口不是默认名称,则该端口必须包含在主机名中:


这解决了问题。不过,我的意见是,它也应该固定在Keyclope中。我希望静态URL,而不是根据您的请求而改变的东西。例如,您可以在请求期间将host设置为localhost,它将在配置中返回“localhost”,将其设置为127.0.0.1,它将返回该值。当在本地查询实际IP时,如果服务器有公共IP,它将返回什么?我没有试过,但这似乎很奇怪。

您好,您可能可以在与主机名管理相关的keydape文档中找到您的问题的一些答案:
    req_.version(version); // HTTP 1.1
    req_.method(method); // GET
    req_.target(target); // /auth/realms/myrealm/.well-known/openid-configuration
    req_.set(http::field::host, host); // 127.0.0.1
    static const std::string agent = app.myAgent(); 
    req_.set(http::field::user_agent, agent);
    req_.set(http::field::content_type, contentType); // application/json