SSO with wordpress help

Hi, I have sso set up with the wp-discourse plugin but am having problems redirecting users back to my discourse site once they login through my wordpress site. Is this possible?

Yes, users should be automatically redirected back to Discourse after logging into WordPress. Sometimes the redirect gets overridden by other plugins. Do you have any plugins on your WordPress site that could be affecting the login redirect?

1 Like

I am using wordfence security plugin which I’ve tried deactivating but still no redirect. Also for my login I am using profile builder instead of the default wp login.

1 Like

The issue is probably being caused by the profile builder plugin. If the plugin has any options to do with login redirects, you could try disabling them and see if that makes a difference. I’ll install that plugin on my test site and take a look at it, because I think this has come up before. I won’t be able to try it until tomorrow.

1 Like

I’ve tried it out and there is a conflict with the way the profile builder plugin handles the login redirect and the redirect that’s required for Discourse SSO to work correctly. There is a fix for it. I’ll try to add it to the plugin this week.

2 Likes

Thanks @simon am looking forward to it.

Are you able to add some code to your theme’s functions.php file? Adding this code should redirect users back to Discourse after logging in through WordPress for sites that are using the Profile Builder plugin.

add_filter( 'login_redirect', 'wpdc_login_redirect_override' );
function wpdc_login_redirect_override( $redirect ) {
    $output = [];
	parse_str( parse_url( $redirect, PHP_URL_QUERY ), $output );
	if ( isset( $output['redirect_to'] ) ) {
	    return $output['redirect_to'];
    }

    return $redirect;
}

I’m assuming that you have already set the path to your login page on the plugin’s SSO Provider tab. If not, you should set it here:

I would prefer for people to not have to add any custom code to get things working. I’ll look into this some more and see if I can add it to the plugin’s code.

If you have any questions about this, please ask.

3 Likes

It worked, thank you @simon for your help.

1 Like

I have the same original issue as @dena_blaze and am also using the Profile Builder plugin. I added this code to my functions.php file and it doesn’t seem to work.

I could try using the solution you had here of creating an entirely separate login page via Profile Builder and then setting a redirect to my Discourse forum homepage, but that seems like an unnecessary workaround, and it would be more ideal to use this solution since my understanding is that it would redirect the user back to the exact forum page they were looking at previously (not just the homepage as a catch-all).

Any updates on whether this has been added to the plugin’s code, and/or is it likely something may have changed with Profile Builder to need a different solution?

This has not been added to the WP Discourse code. If the code snippet from my previous post is not working for you, then it seems likely that something has changed with the Profile Builder plugin. I’ll take a look at what’s going on with it.

Edit: I just installed the Profile Builder plugin and configured it to ‘Enable Private Website.’ My login page on WordPress is at /log-in

When I set the WP Discourse ‘Path to your Login Page’ option to /log-in, and add the following code to my theme’s functions.php file, I am being correctly redirected back to Discourse during the SSO login process:

add_filter( 'login_redirect', 'wpdc_login_redirect_override' );
function wpdc_login_redirect_override( $redirect ) {
    $output = [];
    parse_str( parse_url( $redirect, PHP_URL_QUERY ), $output );
    if ( isset( $output['redirect_to'] ) ) {
        return $output['redirect_to'];
    }

    return $redirect;
}

If this isn’t working for you, it’s possible that the problem is being caused by something other than the Profile Builder plugin.

3 Likes