Login to discourse automatically via SSO

AI-generated summary

Nishkarsh_Tripathi is seeking to enable automatic login to their Discourse forum via SSO from a mobile app, avoiding repeated login prompts for already-authenticated users. Currently, clicking a link like forum.example.com/session/sso?return_to=t/slug/3 always redirects to the SSO login page, even if the user is already logged in. Nishkarsh_Tripathi asks whether their SSO page should detect existing authentication and skip the login step by directly returning the redirect link. simon confirms this is correct and references how the WP Discourse plugin handles it here, promising to update the main topic post with this detail. Nishkarsh_Tripathi acknowledges and plans to review the resource.

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.

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.

Thanks, will check this out