Wordpress SSO Provider - Blank Page

I’m trying out using wordpress as the sso provider for discourse via the plugin. When I click login on the forum site, it sends me to my web site with an sso url parameter appended but the site/page shows up blank. Is the plugin supposed to read that url parameter and take action that’s failing? Am I supposed to send it to a specific path on the web site? I’m just not sure what the expected behavior is so I’m not sure how to troubleshoot. I’m not seeing any errors in my server error logs.

Does your site use the default WordPress login page at /login.php? If not, you may need to add a path to the ‘Path to your Login Page’ option (found on the WP Discourse SSO Provider tab.)

Do you have Woocommerce installed on your site?

4 Likes

It does not use the default and I did specify it in the field. Still no luck, just a blank page.

And no, no woocommerce.

So I think maybe my understanding of how this would work is off or I need some additional change. In testing I realized that if I’m already logged on to the web site, then it works as expected. My expectation though was that if I’m not already logged on to the web site, it would kick off my login process, but that doesn’t seem to be happening. Based on that a couple follow up questions:

  1. Is the login redirect from discourse supposed to send the user to /?sso=abcd1235… on my site or /sign-in/?sso=abcd1235… on my site (including my custom login path)? It’s currently using /.
  2. Is the expectation that my custom login code would maintain the sso url parameters and include them in the redirect back to my site once they’re logged on to then make the sso connection happen?

And I just realized it uses the wordpress username for the discourse username. In our case we would need to use the nickname from wordpress because the username is a hash value based on the 3rd party auth provider. So may be a dead end.

Yes. After clicking the ‘login’ button on Discourse, users will be redirected to the URL you have set as the sso url on Discourse. This should be your site’s home URL.

If you are not already logged into WordPress, the SSO code will redirect you to your site’s login URL. This URL defaults to /wp-login.php. It can be overridden by setting the ‘Path to your login page’ option. After login, users should be redirected back to your site’s home URL, with the query parameters sent from Discourse intact.

If this isn’t working for you when you are not already logged into WordPress, the issue could be that you have a login redirect setup on your site that is overriding the login redirect set by the WP Discourse SSO code. Another possibility is that the query parameters set by Discourse are being stripped by your site’s login code.

You could use the wpdc_sso_params filter to override the username that is set by the plugin:

add_filter( 'wpdc_sso_params', 'wpdc_custom_sso_params', 10, 2 );
function wpdc_custom_sso_params( $params, $user ) {
    $params['username'] = $user->user_nicename;

    return $params;
}

For details about what is going on have a look at https://github.com/discourse/wp-discourse/blob/master/lib/sso-provider/discourse-sso.php.

4 Likes

I was just looking at the plugin code and saw where I could change that. Using an override is a much better approach, thanks! I’ll check my custom login code and see if/where it might be interfering with the process. This is very helpful, thanks again.

1 Like