Openidc with Keycloak error authenticate(): 请求到重定向_uri_path但未找到会话状态,客户端

我正在使用Openresty作为服务器。我按照https://eclipsesource.com/blogs/2018/01/11/authenticating-reverse-proxy-with-keycloak/的nginx配置文件。

我遇到了以下错误:“openidc.lua: 1053: authenticate():请求到重定向_uri_path,但未找到会话状态,客户端”

有没有人能够解决这个问题呢?

问候 Allahbaksh

点赞
用户4014583
用户4014583

你的重定向 URI 不能设置为 "/",而应该设置为某些非返回内容的任意路径(例如 /redirect_uri)。它是一个“虚拟”的 URL,由 lua-resty-openidc 处理。

2018-06-01 07:52:27
用户9956894
用户9956894

我遇到了相同的问题,并通过在服务器块中设置 $session_name 变量来解决它。示例:

server {
  ...
  server_name proxy.localhost;
  #lua_code_cache off;
  set $session_name nginx_session;
  location / {
          access_by_lua_block {
            local opts = {
               redirect_uri = "http://proxy.localhost/cb",
               discovery = "http://127.0.0.1:9000/.well-known/openid-configuration",
               client_id = "proxyclient-id",
               client_secret = "secret",
               ssl_verify = "no",
               scope = "openid"
            }
            -- call authenticate for OpenID Connect user authentication
            local res, err = require("resty.openidc").authenticate(opts)

            if err then
              ngx.status = 500
              ngx.say(err)
              ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
            end

            ngx.req.set_header("X-USER", res.id_token.sub)
          }

          proxy_pass http://localhost:8080/;
          proxy_set_header x-forwarded-proto $scheme;
        }
}

需要注意的另一件事是 lua_code_cache off 指令可能会破坏会话。请参见:https://github.com/bungle/lua-resty-session#notes-about-turning-lua-code-cache-off

2021-01-19 12:02:39