# 嵌入需要登录的主题和DiscourseConnect

**URL:** <https://meta.discourse.org/t/embedding-topics-with-login-required-and-discourseconnect/221009>\
**Category:** Support\
**Created:** [2022年三月15日 15:16 UTC](https://meta.discourse.org/t/embedding-topics-with-login-required-and-discourseconnect/221009 "2022-03-15T15:16:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aubreyholland](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@aubreyholland](https://meta.discourse.org/u/aubreyholland)\
**Post date:** [2022年三月15日 15:16 UTC](https://meta.discourse.org/t/embedding-topics-with-login-required-and-discourseconnect/221009/1 "2022-03-15T15:16:31Z")

</div>

我有一个自己的网站，我想在上面嵌入一个主题列表。我的论坛设置在 [community.withgrayce.com](http://community.withgrayce.com)，并且它要求使用 [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) 作为唯一的登录方法才能查看内容。我已经为我的网站设置了 d-topics-list。发生的情况是：

- d-topics-list 创建的 iframe 加载了 URL `https://community.withgrayce.com/embed/topics?discourse_embed_id=de-d4px4nnxj&per_page=5`
- 因为需要登录，该 URL 会重定向到我的 discourse conect URL。我正在本地测试，所以这会转到 `http://localhost:3001/sso?sso=SSO_PARAMS_SNIPPED`
- 该 URL 加载一个页面，该页面会命中一个 API 来获取 SSO 重定向，然后在 iframe 内设置 `window.location.href` 为该 URL。我已经测试过使用这种技术可以正常进行 SSO。
- 当 iframe 尝试加载 SSO 重定向时，它会收到一个 419 错误，提示登录已过期。

我无法弄清楚为什么在这种情况下会发生 419 错误，但这种方法是否注定会失败？在需要登录并使用 [discourse connect](https://meta.discourse.org/t/13045?silent=true) 的情况下，是否有可行的方法来嵌入主题列表？

谢谢！

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年三月15日 15:26 UTC](https://meta.discourse.org/t/embedding-topics-with-login-required-and-discourseconnect/221009/2 "2022-03-15T15:26:26Z")

</div>

这在生产环境中运行正常，但在本地进行测试却很棘手。

---

<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:** [2022年四月14日 15:26 UTC](https://meta.discourse.org/t/embedding-topics-with-login-required-and-discourseconnect/221009/3 "2022-04-14T15:26:42Z")

</div>

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