apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: failure to authenticate using the `authz-keycloak` plugin

Open whatsmore opened this issue 6 years ago • 12 comments

Issue description

启动测试基本可用了,因为需要鉴权服务,所以想使用其中的几个插件来满足鉴权的能力,使用 key-auth 测试了一下基本通了,但是对于一个 route,可能会有多个用户,因此改用 authz-keycloak 插件。 因为并不了解 ,因此按照文档,启动一个容器然后上去配置 docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=123456 -p 8090:8080 sshniro/keycloak-apisix 配置过程基于网上的教程,配置了相应的client和对应的用户,并设置了密码。 使用 curl --location --request POST 'http://localhost:8090/auth/realms/test/protocol/openid-connect/token' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'username=test' --data-urlencode 'password=123456' --data-urlencode 'client_id=test-client' --data-urlencode 'grant_type=password' 获取了对应的access_token 使用 curl --location --request POST 'http://localhost:8090/auth/realms/test/protocol/openid-connect/userinfo' --header 'Content-Type: application/x-www-form-urlencoded' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'access_token=eyJ.................hbG 验证token是正确可用的 返回结果 {"sub":"11d5f929-9348-4114-8e7a-e3ee3fa2fac3","email_verified":false,"preferred_username":"test"} 再在route中配置相应的token_endpoint http://127.0.0.1:8090/auth/realms/test/protocol/openid-connect/token 将policy_enforcement_mode设置为PERMISSIVE 调用 curl http://127.0.0.1:9080/authtest/ -H 'Authorization: Bearer {eyJ.................hbG}' 报错如下: {"error":"invalid_grant","error_description":"Invalid bearer token"} 改为 curl http://127.0.0.1:9080/authtest/ -H 'Authorization: Bearer eyJ.................hbG' 报错如下: {"error":"invalid_request","error_description":"You must provide the issuedFor"}

在未开启 authz-keycloak 插件时,上述 curl 命令是可用的 请问是我的 keycloak 的配置有问题吗?

Environment

  • apisix version (cmd: apisix version):1.5
  • OS:macOS

whatsmore avatar Oct 15 '20 06:10 whatsmore

另:新写的一个自定义插件,怎么定义为Authentication的啊?我想自己写一个鉴权插件,但是被分在other里了,创建用户的时候提示:请启用至少一种身份认证类插件

whatsmore avatar Oct 15 '20 08:10 whatsmore

@whatsmore 大兄弟交流交流,我这边也在自定义插件做鉴权

Caelebs avatar Oct 15 '20 08:10 Caelebs

@Caelebs 我也才刚开始,等大佬告诉我怎么设置为Authentication的,现在在重写body,唉,社区不够活跃

whatsmore avatar Oct 15 '20 08:10 whatsmore

@whatsmore 我也是刚开始搞,现有的插件不太满足我这的鉴权要求,lua以前也没用过,现在有点头大

Caelebs avatar Oct 15 '20 09:10 Caelebs

ping @Yiyiyimu

idbeta avatar Oct 15 '20 09:10 idbeta

我在plugin.lua 的type里设置了auth好像也没生效,依旧是other,其实直接拷贝的key-auth,只不过改了一下名字和priority结果冲突

whatsmore avatar Oct 15 '20 09:10 whatsmore

@whatsmore please use English in public channel

membphis avatar Oct 15 '20 17:10 membphis

If you can rephrase in EN I can help you with this. 🙂

sshniro avatar Oct 16 '20 18:10 sshniro

算了,自己搞定了

whatsmore avatar Oct 20 '20 05:10 whatsmore

@whatsmore Welcome adding what you found to documentation, in order to help other people who might come across this problem in the future.

Yiyiyimu avatar Oct 20 '20 07:10 Yiyiyimu

@whatsmore 铁子怎么搞的 围观围观?

Caelebs avatar Oct 20 '20 12:10 Caelebs

Closed as lack of response.

spacewander avatar Apr 09 '21 04:04 spacewander