问题描述
当我尝试通过在kong上创建的代理访问端点时,服务器收到连接拒绝响应。 我用来打代理的curl命令-
curl --location --request GET 'http://localhost:8000/listProducts/'
--header 'Accept: application/json'
--header 'Authorization: Bearer token'
要获取令牌,我使用以下curl-
curl --location --request POST 'http://localhost:8180/auth/realms/experimental/protocol/openid-connect/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'username=username'
--data-urlencode 'password=password'
--data-urlencode 'grant_type=password'
--data-urlencode 'client_id=myapp'
客户端协议是开放连接的,访问类型是公共的。
我在Oidc插件中完成的配置:
consumer:
response type:
code:
introspection endpoint: http://{MyHostIP}:8180/auth/realms/experimental/protocol/openid-connect/token/introspect
filters:
bearer only: yes
ssl verify: no
session secret:
introspection endpoint auth method:
realm: experimental
redirect after logout uri: /
scope: openid
token endpoint auth method:
client_secret_post:
logout path: /logout
client id: kong
discovery: https://{MyHostIP}:8180/auth/realms/master/.well-kNown/openid-configuration
client secret: myClientSecret
recovery page path:
redirect uri path:
预先感谢
解决方法
你是如何部署 Keycloak 的?我看到 2 点:
- 您的发现端点是 https
- 您的内省端点只是 http
此外,如果您使用 Docker 来部署 Kong + Keycloak,请转到您的主机文件并使用 MyHostIP 添加一个包含本地 ip 的新行。
sudo nano /etc/hosts
然后添加
your.ip.address. keycloak-host
更新 docker-compose 文件
kong:
build:
context: kong/
dockerfile: Dockerfile
extra_hosts:
- "Keycloak-host:your.ip.address"
现在使用 keycloak-host 配置你的内省和发现 url
例如:http://keycloak-host:8180/auth/realms/master/protocol/openid-connect/token/introspect
如果您需要有关 Kong + openID + Keycloak 的功能示例,请查看 this 存储库。