# Discourse-saml 不兼容多站点

**URL:** https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484
**Category:** Feature
**Created:** [2020年十一月27日 11:44 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484 "2020-11-27T11:44:49Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [2020年十一月27日 11:44 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/1 "2020-11-27T11:44:49Z")

</div>

在新配置的 Discourse 实例中，SAML 会因默认的 Content-Security-Policy 而失败，该策略会阻止提交表单的脚本…

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2020年十一月27日 12:16 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/2 "2020-11-27T12:16:36Z")

</div>

我们有许多客户成功地在 CSP 环境下使用 SAML 插件。您能否分享一下在浏览器控制台中看到的错误信息？

我们的所有托管服务都使用 CDN，因此我猜测该 CSP 规则可能对未使用 CDN 的用户不生效🤔。

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [2020年十一月27日 12:28 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/3 "2020-11-27T12:28:51Z")

</div>

是的，抱歉，我原本打算这样做，但无法复现该错误消息——尽管错误仍然存在。  
现在，我只在 favicon 和 apple icon 上遇到“混合内容”错误。这些图片是在启用 `force_https` 之前上传的，但我认为该设置应该能处理所有图标的来源……这是一个 bug 吗？

我正试图复现最初遇到的错误，但到目前为止还没有成功。屏幕上显示的错误是“抱歉，授权您的账户时发生错误。请重试。”我认为这是一个无效票据，尽管所有配置都与 Discourse 和 Keycloak 两端现有的运行实例相匹配。真奇怪。

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [2020年十一月27日 14:24 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/4 "2020-11-27T14:24:08Z")

</div>

是的，抱歉，我原本打算这样做，但我无法复现该错误消息——尽管错误依然存在。

好的，我找到问题了。我认为问题出在配置上：

1. 这是一个多站点实例，其中 [ps.zoethical.org](http://ps.zoethical.org) 是“主”站点，SAML 最初是为其配置的。
2. forum.zoonklopper.be 实例上显示了 SAML 按钮，但其作用域被定义为 [ps.zoethical.org](http://ps.zoethical.org)。

```plaintext
(saml) 认证失败！invalid_ticket: OneLogin::RubySaml::ValidationError, https://ps.zoethical.org 不是此响应有效的受众 - 有效受众: https://forum.zonnklopper.be

```

如果我添加 [ps.zoethical.org](http://ps.zoethical.org) 受众，则会得到另一个错误：

```plaintext
(saml) 认证失败！invalid_ticket: OneLogin::RubySaml::ValidationError, 响应接收地址为 https://forum.zonnklopper.be/auth/saml/callback，而非 https://ps.zoethical.org/auth/saml/callback

```

---

<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: [2020年十一月27日 14:27 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/5 "2020-11-27T14:27:59Z")

</div>

> [@hellekin](#):
>
> 这是一个多站点实例

SAML 插件不支持多站点。

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [2020年十一月27日 14:29 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/6 "2020-11-27T14:29:13Z")

</div>

是的，这正是我刚刚意识到的。非常不幸。☹

所以实际上，插件不兼容意味着：

1. 它会在多站点中的第一个站点（或通过 `DISCOURSE_HOSTNAME` 配置的站点）上正常工作
2. 按钮会出现在所有其他实例的登录界面中
3. 但这些按钮在没有明确解决方案的情况下会失效。

由于在 #Customization > Plugin 中没有关于 `discourse-saml` 的专门主题，我建议创建一个并在此帖的第一条中提及这个注意事项。我相信可以从 [提及 SAML 的 50 多个主题](https://meta.discourse.org/search?q=saml) 中进行一些整合。如果我知道这一点，我会以不同的方式设置我的服务。

（顺便说一下，原始的 CSP 错误可能是由于 iframe 尝试加载原始站点而不是当前站点造成的。）

## 在多站点中隐藏 SAML 按钮

这是一个为在多站点上激活 SAML 插件的人提供的快速修复方法。🙂

1. 前往 管理 \> 主题 并点击“安装新主题”
2. 创建新组件（名称为：“隐藏 SAML 按钮”）
3. 添加 CSS：

```css
#login-buttons .btn.btn-social.saml {
    display: none; /* 插件与多站点不兼容 */
}

```

4. 将该组件应用到所有主题。

现在，SAML 按钮（在此实例中不起作用）将不再显示。

---

<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: [2020年十一月30日 21:00 UTC](https://meta.discourse.org/t/discourse-saml-is-not-multisite-compatible/171484/7 "2020-11-30T21:00:11Z")

</div>

此主题已在 3 天后自动关闭。不再允许新的回复。
