# Triggering automatic authentication via SSO when linking to private topics?

**URL:** <https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913>\
**Category:** SSO\
**Created:** [January 18, 2019, 3:00pm UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913 "2019-01-18T15:00:40Z")\
**Posts on this page:** 6\
**Page:** 1

## AI-generated summary

The original poster, [ngm](/t/-/106913/1), is experiencing issues with triggering automatic authentication via SSO when linking to private topics in their Discourse forum. When users authenticate in their system and are linked to a private category or topic in Discourse, they are shown a login page. 

However, [simon](/t/-/106913/2) suggested a solution by creating a login link on the SSO provider site with a `return_path` parameter in the URL, which would redirect the user to the desired endpoint after authentication. This solution has worked for [ngm](/t/-/106913/5). Additionally, [pfaffman](/t/-/106913/3) mentioned that the SSO could also be set up to log users in to Discourse simultaneously, but [simon](/t/-/106913/4) noted that this might not be necessary with the use of SSO login links and the `sync_sso` route.

<div class="post-metadata">

**Author:** ![ngm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ngm/32/113693_2.png) [@ngm](https://meta.discourse.org/u/ngm)\
**Post date:** [January 18, 2019, 3:00pm UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/1 "2019-01-18T15:00:40Z")

</div>

We are using our own application as the SSO provider to Discourse, and we’re having an issue when linking users to private topics in our Discourse forum from our application, in that authentication is only triggered when clicking the ‘Login’ button.

- We use our own system as the SSO provider to Discourse.
- We have a mixture of public and private pages on our Discourse, so we don’t have login\_required set.
- If a user authenticates in to our system, and we link them to our Discourse root url, they are shown the public categories but are not logged in.
- If a user authenticates in to our system, and we link them to our Discourse + /login, they are logged in fine, and redirected to the root Discourse URL.
- If a user authenticates in to our system, and we link them to the URL of a private category/topic in Discourse, they are shown a page asking them to login. If they click Login, they are automatically logged in and shown the category/topic.

This last case is the problematic one. I think one of the following would be good:

- we can link to ourdiscourse dot com/c/some-category?login=true and an auth check is performed - if user is logged in, show them the topic. If not, send them to our SSO provider, and redirect them back to the topic after logging in.
- we can link to ourdiscourse dot com/login?redirect=c/some-category and an auth check is performed - if successful, redirect to the page on the query string, if not, redirect to SSO provider, and redirect to the page on the query string after successful authentication
- we can link to ourdiscourse dot com/c/some-category, and if it’s a private page, Discourse performs an auth check, which if successful takes you to the category; if not successful, redirects to SSO provider, then redirects back.

Thanks!

(I’ve posted the issue before [here](https://meta.discourse.org/t/any-way-to-force-login-popup-to-open-by-url-query-string/46193/5) - apologies for multiple postings, but I thought perhaps a new topic might get more response)

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [January 18, 2019, 7:55pm UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/2 "2019-01-18T19:55:48Z")

</div>

You can create an login link on your SSO provider site with a `return_path` parameter in the URL. After authentication, Discourse will redirect the user to the value set for the `return_path`. The link should be in this form:

```plaintext
<a href="https://forum.example.com/session/sso?return_path=https://forum.example.com/your-discourse-endpoint">Link Text</a>

```

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [January 19, 2019, 3:05am UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/3 "2019-01-19T03:05:22Z")

</div>

Can’t they also have the SSO do something similar so that when they log in to the SSO they are also logged in to Discourse?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [January 19, 2019, 3:31am UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/4 "2019-01-19T03:31:22Z")

</div>

The only ways I know of auto logging in users to Discourse when the login to the SSO provider site seem a little hacky. With the use of SSO login links in the form I gave above and the `sync_sso` route for updating users without requiring them to login, I can’t see where it would be required.

---

<div class="post-metadata">

**Author:** ![ngm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ngm/32/113693_2.png) [@ngm](https://meta.discourse.org/u/ngm)\
**Post date:** [January 22, 2019, 12:34pm UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/5 "2019-01-22T12:34:53Z")

</div>

> [@simon](#):
>
> With the use of SSO login links in the form I gave above

Thank you - this has worked perfectly.

> [@simon](#):
>
> and the `sync_sso` route for updating users without requiring them to login

I’m not sure if we are doing this - what would be the way to check?

_EDIT_: should have searched first… details here: [Sync DiscourseConnect user data with the sync\_sso route](https://meta.discourse.org/t/sync-sso-user-data-with-the-sync-sso-route/84398)

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [February 21, 2019, 12:34pm UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/6 "2019-02-21T12:34:53Z")

</div>

Closed on February 21, 2019, 12:34pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
