Create a DiscourseConnect login link

Sites using DiscourseConnect sometimes want to include links on their DiscourseConnect provider site that will log users into Discourse and redirect them to a specific Discourse URL. This can be done by creating an anchor on the SSO provider site with an href property that points to /session/sso and has a return_path parameter set to the path of the Discourse page you want users to end up on.

The link’s href property should be in this form:

https://forum.example.com/session/sso?return_path=/relative_path

Here’s a full anchor that will log in a user and redirect them to your Discourse site’s homepage:

<a href="https://forum.example.com/session/sso?return_path=/">Community</a>

Here’s a link that will log in a user and redirect them to your Top Topics page:

<a href="https://forum.example.com/session/sso?return_path=/top">Top Topics</a>

Discourse allows you to login a user and redirect them to a non-Discourse URL if you configure the discourse connect allowed redirect domains site setting. By default this setting is blank - preventing redirects to non-Discourse URLs. If you enable it, be sure to use the absolute URL in the return_path parameter for any non-Discourse URLs that you want to direct users to.

17 Likes