Create a DiscourseConnect login link

I think what is happening is that when you visit a route like https://forum.example.com/session/sso?return_path=/t/some-slug/23, Discourse redirects you to the discourse connect url, regardless of whether you are logged into Discourse or not. That happens here:

The SSO provider site is then expected to handle the case of users who are already logged into the site. Here’s how the WP Discourse plugin handles it:

That code (what follows the else statement) handles the case of users who are already logged into WordPress. They are redirected back to the URL that’s supplied by the return_path query param. So from the user’s point of view, they are taken directly to the return path URL, but what actually happens is that they are redirected to the SSO provider site, then back to Discourse.

I think the problem on your site is that your SSO code isn’t handling the case of users who are already logged into the site.

I don’t have things setup to test this right now. It’s possible that I’m reading the code incorrectly. Before looking at the code, I thought that a check was run on the Discourse end to see if the user was already logged into Discourse, but that does not seem to be the way it works.

3 Likes