Keycloak 在Eclispe中使用KeyClope定义策略中的主题同上

Keycloak 在Eclispe中使用KeyClope定义策略中的主题同上,keycloak,eclipse-ditto,Keycloak,Eclipse Ditto,我当前的使用案例是:我有一个前端应用程序,其中用户通过KeyClope登录。我想在这个前端()中实现Ditto HTTP API的一些部分 例如,我想为授权创建策略()。我在文档中读到,可以使用符合OpenID Connect的提供程序,其形式是:() 页面底部有一个基本的auth示例,在本例中似乎使用了用户名 { "policyId": "my.namespace:policy-a", "entries": {

我当前的使用案例是:我有一个前端应用程序,其中用户通过KeyClope登录。我想在这个前端()中实现Ditto HTTP API的一些部分

例如,我想为授权创建策略()。我在文档中读到,可以使用符合OpenID Connect的提供程序,其形式是:()

页面底部有一个基本的auth示例,在本例中似乎使用了用户名

{
    "policyId": "my.namespace:policy-a",
    "entries": {
      "owner": {
        "subjects": {
          "nginx:ditto": {
            "type": "nginx basic auth user"
          }
        },
        
    ...
}
我的问题是:如果我想使用KeyClope,子索赔到底是什么?它也是我想授予权限的用户的用户名吗?我如何在我的前端得到它,在那里我想指定以后发送给同上的策略


更新1

我尝试以同上的方式启用KeyClope身份验证,如下所述:

因为我正在使用Docker Compose运行同上,所以我在第136行的Ditto/deployment/Docker/Docker-Compose.yml中添加了以下行作为环境变量:
-ddito.gateway.authentication.oauth.openid-connect-issuers.keydove=http://localhost:8090/auth/realms/twin
此URL与我从KeyClope收到的令牌的发卡机构声明中的URL相同

现在,如果我尝试使用Postman向{{basePath}}/things发出post请求,我会得到以下错误:

<html>

<head>
    <title>401 Authorization Required</title>
</head>

<body bgcolor="white">
    <center>
        <h1>401 Authorization Required</h1>
    </center>
    <hr>
    <center>nginx/1.13.12</center>
</body>

</html>

更新3

我在gateway.conf中的配置现在如下所示:

oauth {
        protocol = "http"
        openid-connect-issuers = {
          keycloak = "localhost:8090/auth/realms/twin"
        }
      }
我还尝试在docker-compose.yml中添加这两行:

- Dditto.gateway.authentication.oauth.protocol=http
- Dditto.gateway.authentication.oauth.openid-connect-issuers.keycloak=localhost:8090/auth/realms/twin
不幸的是,我仍然没有运气,与上面相同的错误:/之前似乎有一个用户在keybeave()上有类似的问题,但遗憾的是,他没有提到解决方案

EDIT:事实证明,我以错误的方式指定了这些变量,正确的解决方案是将它们添加为
命令:java的一部分更多信息


更新4

我尝试在本地构建同上,而不是使用最新的docker映像,我想我现在可能更进一步了,似乎我的oauth配置正在工作。我现在明白了:

{
    "status": 503,
    "error": "gateway:publickey.provider.unavailable",
    "message": "The public key provider is not available.",
    "description": "If after retry it is still unavailable, please contact the service team."
}
日志中的错误消息为:

gateway_1        | 2020-11-05 15:33:18,669 WARN  [] o.e.d.s.g.s.a.j.DittoPublicKeyProvider  - Got Exception from discovery endpoint <http://localhost:8090/auth/realms/twin/.well-known/openid-configuration>.
gateway_1        | akka.stream.StreamTcpException: Tcp command [Connect(localhost:8090,None,List(),Some(10 seconds),true)] failed because of java.net.ConnectException: Connection refused
gateway_1        | Caused by: java.net.ConnectException: Connection refused
...
gateway_1        | java.util.concurrent.CompletionException: org.eclipse.ditto.services.gateway.security.authentication.jwt.PublicKeyProviderUnavailableException [message='The public key provider is not available.', errorCode=gateway:publickey.provider.unavailable, statusCode=SERVICE_UNAVAILABLE, description='If after retry it is still unavailable, please contact the service team.', href=null, dittoHeaders=ImmutableDittoHeaders [{}]]
...
gateway_1        | Caused by: org.eclipse.ditto.services.gateway.security.authentication.jwt.PublicKeyProviderUnavailableException [message='The public key provider is not available.', errorCode=gateway:publickey.provider.unavailable, statusCode=SERVICE_UNAVAILABLE, description='If after retry it is still unavailable, please contact the service team.', href=null, dittoHeaders=ImmutableDittoHeaders [{}]]
...
gateway_1        | Caused by: akka.stream.StreamTcpException: Tcp command [Connect(localhost:8090,None,List(),Some(10 seconds),true)] failed because of java.net.ConnectException: Connection refused
gateway_1        | Caused by: java.net.ConnectException: Connection refused

  • 现在,网关可以通过别名找到keydrope容器,我仍然可以使用localhoast中的keydrope管理ui:
  • 其他信息:

    如果我想使用KeyClope,子索赔具体是什么

    KeyClope为您提供JWT

    JWT是一种加密的JSON,它包含多个称为“声明”的字段。您可以通过访问并粘贴您的令牌来检查令牌的外观。其中一个字段称为
    sub
    。这是最新的

    要在EclipseDitto中启用KeyClope身份验证,您需要将颁发者添加到ditto配置中

    可以找到一个例子。 地址必须与JWT令牌中的URL匹配

    ditto.gateway.authentication {
        oauth {
          protocol = "http"
          openid-connect-issuers = {
            some-name = "localhost:8090/auth/realms/twin"
          }
        }
    }
    
    它也是我想授予权限的用户的用户名吗

    在eclipse中,也没有真正的“用户名”概念。Eclipse同上身份验证基于授权主题。对于您提供的基本身份验证示例,在同上中生成的授权主题是
    nginx:ditto

    对于JWT身份验证,授权主题是由您配置的开放id连接颁发者的名称(在我的案例中是
    一些名称
    )和子声明的值的组合生成的。授权主题可能如下所示:
    某个名称:8d078113-3ee5-4dbf-8db1-eb1a6cf0fe81

    我如何在我的前端得到它,在那里我想指定以后发送给同上的策略

    我不确定我是否正确理解了这个问题。如果您的意思是如何对eclipse ditto的前端HTTP请求进行身份验证,则需要通过以下形式将JWT添加到HTTP请求的授权头中,从而向eclipse ditto提供JWT:

    授权:JWT

    如果您的意思是如何知道JWT的子声明,那么您需要将其复制到JSON对象,然后从payload部分读取子声明

    如果我想使用KeyClope,子索赔具体是什么

    KeyClope为您提供JWT

    JWT是一种加密的JSON,它包含多个称为“声明”的字段。您可以通过访问并粘贴您的令牌来检查令牌的外观。其中一个字段称为
    sub
    。这是最新的

    要在EclipseDitto中启用KeyClope身份验证,您需要将颁发者添加到ditto配置中

    可以找到一个例子。 地址必须与JWT令牌中的URL匹配

    ditto.gateway.authentication {
        oauth {
          protocol = "http"
          openid-connect-issuers = {
            some-name = "localhost:8090/auth/realms/twin"
          }
        }
    }
    
    它也是我想授予权限的用户的用户名吗

    在eclipse中,也没有真正的“用户名”概念。Eclipse同上身份验证基于授权主题。对于您提供的基本身份验证示例,在同上中生成的授权主题是
    nginx:ditto

    对于JWT身份验证,授权主题是由您配置的开放id连接颁发者的名称(在我的案例中是
    一些名称
    )和子声明的值的组合生成的。授权主题可能如下所示:
    某个名称:8d078113-3ee5-4dbf-8db1-eb1a6cf0fe81

    我如何在我的前端得到它,在那里我想指定以后发送给同上的策略

    我不确定我是否正确理解了这个问题。如果您的意思是如何对eclipse ditto的前端HTTP请求进行身份验证,则需要通过以下形式将JWT添加到HTTP请求的授权头中,从而向eclipse ditto提供JWT:

    授权:JWT


    如果您的意思是如何知道JWT的子声明,那么您需要创建一个JSON对象,然后从payload部分读取子声明。

    谢谢您的详细回答Yann
    ditto.gateway.authentication {
        oauth {
          protocol = "http"
          openid-connect-issuers = {
            some-name = "localhost:8090/auth/realms/twin"
          }
        }
    }