SSO redirect link

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].

Спасибо, очень помогает, приятель!