SSO 重定向链接

I am using wordpress as a SSO client to discourse.

How do I set it up so a user is sent back to the page he/she was on after logging in.

Here is what my SSO URL looks like:


As you can see it redirects to my website homepage. Could I edit this link to redirect the user back to the page he was on? will this mess up the SSO?

Yes, you can set any page on your WordPress site as the value for redirect_to. You probably do not have to URL encode the redirect_to parameter. Something like this should work:

http://theprojectvanlife.com/?discourse_sso=1&redirect_to=http://theprojectvanlife.com/my-wordpress-page

so by adding “my-wordpress-page” as the redirect it will redirect user to the page he/she was on?
Or did you mean to replace “my-wordpress-page” with the page I want the user redirected to?

Yes. set the redirect_to parameter to the URL of the page you want users to end up on.

Is it possible to setup a redirect to link that just sends them back to the same page they were on?

You can use the [discourse_sso_client] shortcode on any WordPress page to create a ‘Login with Discourse’ link that will redirect users back to the page that the shortcode was placed on.

There is some documentation on the plugin’s SSO Client tab for the shortcode.

There was a bug in the most recent versions of the plugin that was causing the shortcode to display the ‘Link your account with Discourse’ text for logged in users who had already linked their account. Update to WP Discourse version 1.6.0 to get the fix.

嘿,我认为如果能实现这个功能,将会是对插件功能的一个简单而出色的补充:独立的注册表单/链接?。我目前将 Discourse 用作 SSO 主服务器,如果能同时提供面向现有用户的登录页面和面向新用户的注册链接,并将他们重定向回他们原本所在的页面,将会非常有用。

嘿,我们目前除了 redirect_to 参数外,没有其他实施计划。

“将用户重定向回他们原本所在的页面”看似简单,实则复杂得多,存在不少边缘情况。如果我们将其作为核心功能添加,就等于承诺支持所有这些边缘情况 :slight_smile: 正如您可能想象的那样,WordPress 网站的配置方式多种多样。

我之前已经给您提供了一些提示,但为了进一步帮助您,您或您的开发人员可以这样做:扩展现有的短代码,使其自动将 route_to 设置为当前网站 URL。然后,您可以针对自己特定的网站处理相关的边缘情况。

functions.php 中:

use WPDiscourse\\SSOClient\\SSOClientShortcode;

function render_discourse_sso_client_link_with_redirect() {
    $sso = new SSOClientShortcode();
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
    $current_url = "$protocol://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $options = array(
      "redirect"  => $current_url,
      "login"     => "Login"
    );
    return $sso->discourse_sso_client_shortcode( $options );
}
add_shortcode( 'discourse_sso_client_link_with_redirect', 'render_discourse_sso_client_link_with_redirect' );

然后在您的模板中使用短代码 [discourse_sso_client_link_with_redirect]

非常感谢,兄弟,这帮了大忙!