认证后如何跳转回首页
How do I redirect back to the home page after authentication
我正在尝试在 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
。 redirect_uri 应该是什么?
local opts = {
-- the full redirect URI must be protected by this script and becomes:
-- 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"
--authorization_params = { hd="pingidentity.com" },
--scope = "openid email profile",
--iat_slack = 600,
}
重定向由 redirect_uri_path
选项定义。您已将 /secured
放入此字段,因此您将重定向到 http://xyz.abc.com:8080/secured?...
。如果您想重定向到 /
,您可以在选项中输入 redirect_uri_path = "/"
。
但这可能不是一个好的解决方案,因为您可能希望在重定向到主页之前执行一些处理。 nginx.conf
的以下部分可以回答您的问题:
location "=/secured" {
access_by_lua_block {
... -- perform some handling
return ngx.redirect "/"
}
}
此 location
块是为 /secured
路径定义的。它允许在重定向到主页(“/”路径)之前执行一些代码。
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 and eventually redirect back to the original URL, see https://github.com/pingidentity/lua-resty-openidc/blob/master/lib/resty/openidc.lua#L350
重定向 URI 本身可以是任何路径,只要它不需要提供内容,因为 lua-resty-openidc 会拦截它并做自己的事情。它确实需要向提供商注册。
试试这个模块 - github。com/tarachandverma/nginx-openidc
这个模块在 xml 语法中非常容易配置,并在简单的 xml 配置中提供对重定向的广泛支持,无需重新启动 nginx 网络服务器即可更新。
我正在尝试在 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
。 redirect_uri 应该是什么?
local opts = {
-- the full redirect URI must be protected by this script and becomes:
-- 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"
--authorization_params = { hd="pingidentity.com" },
--scope = "openid email profile",
--iat_slack = 600,
}
重定向由 redirect_uri_path
选项定义。您已将 /secured
放入此字段,因此您将重定向到 http://xyz.abc.com:8080/secured?...
。如果您想重定向到 /
,您可以在选项中输入 redirect_uri_path = "/"
。
但这可能不是一个好的解决方案,因为您可能希望在重定向到主页之前执行一些处理。 nginx.conf
的以下部分可以回答您的问题:
location "=/secured" {
access_by_lua_block {
... -- perform some handling
return ngx.redirect "/"
}
}
此 location
块是为 /secured
路径定义的。它允许在重定向到主页(“/”路径)之前执行一些代码。
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 and eventually redirect back to the original URL, see https://github.com/pingidentity/lua-resty-openidc/blob/master/lib/resty/openidc.lua#L350
重定向 URI 本身可以是任何路径,只要它不需要提供内容,因为 lua-resty-openidc 会拦截它并做自己的事情。它确实需要向提供商注册。
试试这个模块 - github。com/tarachandverma/nginx-openidc 这个模块在 xml 语法中非常容易配置,并在简单的 xml 配置中提供对重定向的广泛支持,无需重新启动 nginx 网络服务器即可更新。