5

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

我收到以下错误“openidc.lua:1053: authenticate(): request to the redirect_uri_path 但没有找到会话状态,客户端”

有人可以提出一些建议并尝试解决问题。

问候,阿拉巴克什

4

2 回答 2

5

您的重定向 URI 不得设置为,"/"而是设置为不应返回内容的任意路径(如/redirect_uri)。这是一个“虚荣”的 URL,由lua-resty-openidc

于 2018-06-01T07:52:27.610 回答
0

我遇到了同样的问题,并且能够通过在服务器块中设置 $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-19T12:02:39.140 回答