# 链接到私密主题时，是否可通过 SSO 触发自动认证？

**URL:** https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913
**Category:** SSO
**Created:** [2019年一月18日 15:00 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

<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: [2019年一月18日 15:00 UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/1 "2019-01-18T15:00:40Z")

</div>

我们使用自己的应用程序作为 Discourse 的 SSO 提供商，但在从我们的应用程序将用户链接到 Discourse 论坛中的私密主题时遇到了问题：只有在点击“登录”按钮时才会触发身份验证。

- 我们使用自己的系统作为 Discourse 的 SSO 提供商。
- 我们的 Discourse 论坛中混合了公开页面和私密页面，因此未设置 login\_required。
- 如果用户在系统中完成身份验证，并被链接到 Discourse 的根 URL，他们可以看到公开分类，但并未登录。
- 如果用户在系统中完成身份验证，并被链接到 Discourse 的 /login 路径，他们可以正常登录，并被重定向到 Discourse 根 URL。
- 如果用户在系统中完成身份验证，并被链接到 Discourse 中私密分类或主题的 URL，系统会显示一个要求登录的页面。如果他们点击“登录”，则会自动完成登录并显示该分类或主题。

最后一种情况是问题所在。我认为以下任一方案都是可行的：

- 我们可以链接到 [ourdiscourse.com/c/some-category?login=true，并执行身份验证检查：如果用户已登录，则显示该主题；如果未登录，则将其发送到我们的](http://ourdiscourse.com/c/some-category?login=true%EF%BC%8C%E5%B9%B6%E6%89%A7%E8%A1%8C%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E6%A3%80%E6%9F%A5%EF%BC%9A%E5%A6%82%E6%9E%9C%E7%94%A8%E6%88%B7%E5%B7%B2%E7%99%BB%E5%BD%95%EF%BC%8C%E5%88%99%E6%98%BE%E7%A4%BA%E8%AF%A5%E4%B8%BB%E9%A2%98%EF%BC%9B%E5%A6%82%E6%9E%9C%E6%9C%AA%E7%99%BB%E5%BD%95%EF%BC%8C%E5%88%99%E5%B0%86%E5%85%B6%E5%8F%91%E9%80%81%E5%88%B0%E6%88%91%E4%BB%AC%E7%9A%84) SSO 提供商，并在登录后重定向回该主题。
- 我们可以链接到 [ourdiscourse.com/login?redirect=c/some-category，并执行身份验证检查：如果成功，则重定向到查询字符串中的页面；如果失败，则重定向到](http://ourdiscourse.com/login?redirect=c/some-category%EF%BC%8C%E5%B9%B6%E6%89%A7%E8%A1%8C%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E6%A3%80%E6%9F%A5%EF%BC%9A%E5%A6%82%E6%9E%9C%E6%88%90%E5%8A%9F%EF%BC%8C%E5%88%99%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%E6%9F%A5%E8%AF%A2%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E7%9A%84%E9%A1%B5%E9%9D%A2%EF%BC%9B%E5%A6%82%E6%9E%9C%E5%A4%B1%E8%B4%A5%EF%BC%8C%E5%88%99%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0) SSO 提供商，并在成功登录后重定向回查询字符串中的页面。
- 我们可以链接到 [ourdiscourse.com/c/some-category，如果是私密页面，Discourse](http://ourdiscourse.com/c/some-category%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%98%AF%E7%A7%81%E5%AF%86%E9%A1%B5%E9%9D%A2%EF%BC%8CDiscourse) 将执行身份验证检查：如果成功，则进入该分类；如果失败，则重定向到 SSO 提供商，随后再重定向回来。

谢谢！

（我之前曾在 [此处](https://meta.discourse.org/t/any-way-to-force-login-popup-to-open-by-url-query-string/46193/5) 发布过该问题，抱歉重复发帖，但我认为创建一个新主题可能会获得更多回应。）

---

<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: [2019年一月18日 19:55 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: [2019年一月19日 03:05 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: [2019年一月19日 03:31 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: [2019年一月22日 12:34 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: [2019年二月21日 12:34 UTC](https://meta.discourse.org/t/triggering-automatic-authentication-via-sso-when-linking-to-private-topics/106913/6 "2019-02-21T12:34:53Z")

</div>

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