我正在尝试使用
kong oicd
和 keycloak 19.0.3
来保护我的应用程序和我的 Dockerfile
FROM kong/kong:2.7.0
ENV OIDC_PLUGIN_VERSION=1.2.3-2
ENV GIT_VERSION=2.24.4-r0
ENV UNZIP_VERSION=6.0-r7
ENV LUAROCKS_VERSION=2.4.4-r1
USER root
RUN apk update && apk add git unzip luarocks
RUN luarocks install kong-oidc
RUN git clone --branch v1.2.3-2 https://github.com/revomatico/kong-oidc.git
WORKDIR /kong-oidc
RUN luarocks make
RUN luarocks pack kong-oidc ${OIDC_PLUGIN_VERSION} \
&& luarocks install kong-oidc-${OIDC_PLUGIN_VERSION}.all.rock
WORKDIR /
RUN git clone --branch 20200505-access-token-processing https://github.com/BGaunitz/kong-plugin-jwt-keycloak.git
WORKDIR /kong-plugin-jwt-keycloak
RUN luarocks make
RUN luarocks pack kong-plugin-jwt-keycloak ${JWT_PLUGIN_VERSION} \
&& luarocks install kong-plugin-jwt-keycloak-${JWT_PLUGIN_VERSION}.all.rock
USER kong
我确实通过传递
client id
和client secret
和descovery endpoint
进行了配置
当我访问 kong 中配置的路由时,我被重定向到 keycloak 进行身份验证,成功后我被重定向回我的应用程序但是当我检查标题时我发现没有
x-userUnfo
而且我只发现session cookie
我错过了什么?
我使用 nginx 作为应用程序来测试我的案例
您不会在浏览器对 Kong 的请求中看到这些请求标头,但会在 Kong 对您的服务的上游请求中看到这些请求标头。 OIDC 插件将注入它们。
关于 jwt-keycloak 插件的一个注意事项:你必须改变它的优先级,例如到
ENV JWT_KEYCLOAK_PRIORITY="900"
否则它将在 OIDC 插件之前执行,但您想在之后执行它。
我正在使用 https://github.com/revomatico/kong-oidc 用于 oidc 和 https://github.com/hanfi/kong-plugin-jwt-keycloak 用于 jwt。 我启用了 2 个插件,所需范围是用户。 当我获得访问令牌并连接到服务时:
#!/bin/bash
auth_url='http://localhost:8080/'
realm_name='kong'
client_id='kong_client'
client_secret='CEkLLq8qhWvHhccWxk5LSirfWM0hkcDm'
username='user1'
password='123abc'
url='http://localhost:8000/httpbin2'
token=$(curl -X POST \
"${auth_url}/realms/${realm_name}/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=${client_id}" \
-d "client_secret=${client_secret}" \
-d "username=${username}" \
-d "password=${password}" \
-d "grant_type=password" | jq -r '.access_token')
连接成功验证范围为“用户”。 但是当我使用浏览器访问 kong 中配置的路由时,我被重定向到 keycloak 进行身份验证,在成功身份验证后我收到此错误:
{“消息”:“未经授权”}
.这是 cookie 的错误吗?