Login to discourse automatically via SSO

I have SSO enabled on my Discourse website, and users are already logged in there. I want to provide an entry point in my mobile app that automatically logs them in without requiring them to log in again. How can I achieve this?

If you are using DiscourseConnect for SSO, you can automatically log users into Discourse from your website by creating a link in the form that’s outlined here: Create a DiscourseConnect login link.

1 Like

Below is the current behavior which I am having

  • I have a link in my app like this: forum.example.com/session/sso?return_to=t/slug/3
  • When users click the link, they are redirected to the SSO login page. After logging in, they are returned to Discourse as authenticated users.
  • However, if they click the link again, the same process is repeated: they are redirected back to the SSO page to log in, even though they are already authenticated.

I want to avoid forcing users to log in again if they have already authenticated. Ideally, when they click the link after being logged in, they should be redirected directly to the forum without going through the login process again.

Is it the responsibility of my SSO page to detect if the user is already logged in and, if so, skip the login process and just return the redirect link?

Is my understanding correct, or am I missing something?

Yes. Have a look at this post from the topic to see how the WP Discourse plugin handles it: Create a DiscourseConnect login link - #5 by simon.

Tomorrow I’ll update the first post in the topic to add that information.

3 Likes

Thanks, will check this out