SSO redirect link

Hey, we don’t have any current plans to implement anything here beyond the redirect_to param.

It’s a little more complicated than it seems to “redirect someone back to the same page they were on”. There are quite a few edge cases. If we added that as a core feature we’d effectively be signing up to support all those edge cases as well :slight_smile: As you might imagine, there are a lot of different ways to configure a Wordpress site.

I gave you a bit of a hint on this already, but to help you along a bit more, you or your developer will want to do something like this, namely extend the existing shortcode to automatically set the route_to to the current url of the site. You can then figure out the edge cases for that for your own specific site.

In 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' );

Then in your template use the shortcode [discourse_sso_client_link_with_redirect]

3 Likes