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] というショートコードを使用してください。

ありがとう、すごく助かるよ、友達!