如何在身份验证后重定向回主页

我正在尝试在NGINX服务器上配置lua-resty-openidc。用户验证后如何重定向回主页?当用户被验证后,回调url将从服务器获取代码、session_state和其他参数。这会导致认证后加载出现问题。 用户返回的url类似于http://xyz.abc.com:8080/secured?code=32edkew2kjjjdf

https://github.com/pingidentity/lua-resty-openidc

我的配置如下。我希望将用户带回http://xyz.abc.com:8080。重定向_uri应该是什么?

 local opts = {
             -- 完整的重定向URI必须由此脚本保护,并变为:
             -- ngx.var.scheme.."://"..ngx.var.http_host..opts.redirect_uri_path
             redirect_uri_path = "/secured",
             discovery = "https://accounts.google.com/.well-known/openid-configuration",
             client_id = "<client_id",
             client_secret = "<client_secret"
             --授权参数={hd="pingidentity.com"},
             --范围="openid电子邮件个人资料",
             --iat_slack = 600,
          }
点赞
用户162054
用户162054

重定向是由 redirect_uri_path 选项定义的。您已将 /secured 放入此字段中,因此将重定向到 http://xyz.abc.com:8080/secured?...。如果您想将重定向指向 /,您可以在选项中放置 redirect_uri_path = "/"

但这可能不是一个很好的解决方案,因为您可能希望在重定向到主页之前执行一些处理。下面的 nginx.conf 部分可能会解决您的问题:

location "=/secured" {
  access_by_lua_block {
    ... -- 执行一些处理
    return ngx.redirect "/"
  }
}

location 块是为 /secured 路径定义的。它允许在重定向到主页(/ 路径)之前执行某些代码。

2017-03-22 11:01:24
用户3748349
用户3748349

lua-resty-openidc 本身会处理重定向回原始页面的操作,您不需要为此执行任何特定操作,它将在触发身份验证时找到该 URL,参见:https://github.com/pingidentity/lua-resty-openidc/blob/master/lib/resty/openidc.lua#L539,并将其存储在会话中。

它将拦截重定向回重定向 URI,参见:https://github.com/pingidentity/lua-resty-openidc/blob/master/lib/resty/openidc.lua#L557,并最终重定向回原始 URL,参见 https://github.com/pingidentity/lua-resty-openidc/blob/master/lib/resty/openidc.lua#L350

重定向 URI 本身可以是任何路径,只要它不需要提供内容,因为 lua-resty-openidc 会拦截它并执行自己的操作。它需要在提供者中注册。

2017-03-23 12:27:31
用户8459725
用户8459725

尝试使用这个模块 - github.com/tarachandverma/nginx-openidc

该模块非常易于在 xml 语法中进行配置,并在简单的 xml 配置中提供了广泛的重定向支持,可以在不重新启动 nginx web 服务器的情况下进行更新。

2017-12-25 15:59:47