使用 SAML 进行身份验证会提供已加密的用户名和电子邮件

您好,

我想使用我们大学的 SAML 来验证我的 Discourse 安装中的用户。

我使用的是带有 SAML 插件的 Discourse Docker 版本。我尝试遵循该插件 GitHub 网站上的说明。

一切正常,直到我看到以下表单:


我原本期望看到常规的电子邮件地址,但现在看到的是十六进制值,我推测这是电子邮件地址的哈希形式。我无法使用这些值继续验证过程。

任何关于此主题的协助都将不胜感激!

此致,
Ronald

你好,Ronald :slight_smile: :wave: 很高兴看到越来越多的大学加入 Discourse 大家庭 :smiley:

你遇到的问题很有意思!我对 SAML/SSO 不太熟悉,所以不太确定这里发生了什么,但你可以尝试启用 verbose sso logging 站点设置吗?这有助于在 /logs 页面显示一些有用的错误信息,也许能说明你遇到此问题的原因,或者提供一些更具体的信息,这样你就可以在这里分享,我们也能更好地帮助你。

我的猜测是(我对 SAML 的经验有限,我想我只帮助过一个人配置过一次),问题出在 SAML 端。要么是它被配置为发送哈希值,要么是你以某种方式使用了错误的字段。

非常感谢您的迅速回复!

将 SSO 日志设置为详细模式后,我在 production.log 中发现了以下内容:

Started GET "/session/csrf" for <IP> at 2020-07-24 14:32:51 +0000
Processing by SessionController#csrf as JSON
Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms | Allocations: 321)
Started POST "/auth/saml" for <IP> at 2020-07-24 14:32:51 +0000
(saml) Request phase initiated.
Started POST "/auth/saml/callback" for <IP> at 2020-07-24 14:33:23 +0000
(saml) Callback phase initiated.
Processing by Users::OmniauthCallbacksController#complete as HTML
  Parameters: {"SAMLResponse"=>"<SNIP>", "provider"=>"saml"}
Redirected to https://discourse-imphys.tudelft.nl/
Completed 302 Found in 24ms (ActiveRecord: 0.0ms | Allocations: 10562)
Started GET "/" for <IP> at 2020-07-24 14:33:24 +0000
Processing by ListController#latest as HTML
  Rendering list/list.erb within layouts/application
  Rendered list/list.erb within layouts/application (Duration: 3.8ms | Allocations: 1991)
  Rendered layouts/_head.html.erb (Duration: 1.9ms | Allocations: 911)
  Rendered common/_discourse_stylesheet.html.erb (Duration: 0.4ms | Allocations: 267)
  Rendered application/_header.html.erb (Duration: 2.2ms | Allocations: 1022)
Completed 200 OK in 34ms (Views: 13.1ms | ActiveRecord: 0.0ms | Allocations: 15963)
Started GET "/u/hp.json" for <IP> at 2020-07-24 14:33:24 +0000
Processing by UsersController#get_honeypot_value as JSON
Completed 200 OK in 2ms (Views: 0.2ms | ActiveRecord: 0.0ms | Allocations: 812)
Started GET "/u/check_username?username=&email=94422472fbfb32fdd22eaa2f88c723fb44be9958" for <IP> at 2020-07-24 14:33:25 +0000
Processing by UsersController#check_username as JSON
  Parameters: {"username"=>"", "email"=>"94422472fbfb32fdd22eaa2f88c723fb44be9958"}
Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms | Allocations: 316)
Started GET "/u/check_username?username=94422472fbfb32fdd22e&email=94422472fbfb32fdd22eaa2f88c723fb44be9958" for <IP> at 2020-07-24 14:33:25 +0000
Processing by UsersController#check_username as JSON
  Parameters: {"username"=>"94422472fbfb32fdd22e", "email"=>"94422472fbfb32fdd22eaa2f88c723fb44be9958"}
Completed 200 OK in 3ms (Views: 0.2ms | ActiveRecord: 0.0ms | Allocations: 1421)

我已将证书替换为 <SNIP>,并将我的 IP 地址替换为 <IP>

感谢您的快速回复!

这也可能是情况!我将联系 SAML 颁发方并告知有关哈希的问题…

没错!你可以清楚地看到 SAML 正在发送电子邮件和用户名哈希。

我认为存在某种配置,可以将 SAML 字段映射到 Discourse 的字段,因此可以设想在 Discourse 端进行某些更改来解决这个问题。

经过进一步研究,我发现注册表单中的“哈希”代码实际上是 IdP 发送的 NameID。在 IdP 的 SAML 配置中,我还启用了以下属性:

  • 显示名称: urn:mace:dir:attribute-def:displayName
  • 全名: urn:mace:dir:attribute-def:cn
  • 电子邮件地址: urn:mace:dir:attribute-def:mail
  • 用户 ID: urn:mace:dir:attribute-def:uid

第三方已确认这些属性确实由 IdP 发送。但出于某种原因,这些属性的值并未在 Discourse 的注册表单中使用(如前所示)。我原本以为在表单中:

  • 电子邮件 应使用 urn:mace:dir:attribute-def:mail 的值;
  • 用户名 应使用 urn:mace:dir:attribute-def:mail 的值;
  • 姓名 应使用 urn:mace:dir:attribute-def:displayName(首选)或 urn:mace:dir:attribute-def:cn 的值。

是否有办法配置 Discourse-SAML 以正确映射这些属性?

你好 @ronligt,在使用 discourse-saml 配置映射正确属性方面有成功吗?

我一直在尝试在插件中使用此配置,但到目前为止还没有成功:

祝你一天愉快! :slight_smile: