如何在认证网站允许用户更改邮箱时处理 Discourse SSO?

我们使用基于本指南实现的 Discourse SSO 流程:Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)

该流程一直运行良好。但现在我们希望允许系统内的用户更改其电子邮件地址,这似乎引发了一些问题。

当我们在系统中更改用户的电子邮件地址时,到 Discourse 的 SSO 登录就会停止工作。

登录错误

您的账户存在问题。请联系站点管理员。

我猜测 Discourse 接收到的负载中包含不匹配的电子邮件和用户名,因此不知如何处理。

有什么好的处理方法吗?

我想到的最佳方案是:在发起 SSO 之前,先使用 Discourse API 将 Discourse 中用户的电子邮件地址更新为与系统中一致。

但我不确定这是否可行。以下是我失败的尝试。

我的请求如下:

https://forum-stage.{domain}.com/users/{username}/preferences/email

Headers:
Content-Type: application/x-www-form-urlencoded
Accept: application/json

Body(在 Postman 中作为 x-www-form-urlencoded 格式):
email: testemail@testdomain.com
api_key: 75a...77d
api_username: system

收到的响应如下:

{
    "errors": [
        "您无权查看所请求的资源。"
    ],
    "error_type": "invalid_access"
}
1 个赞

I’m experiencing this too - did you ever figure out a way around this?

This should not be the case, we primarily key on the SSO id.

You can use the sync sso endpoint to sync the emails on Discourse side if you want to do so proactively but changing emails in your system should always work.

The one exception is

Discourse thinks SSO id is 5 email is bob@jane.com

You log in with SSO id of 6 email is bob@jane.com

This is not resolvable so you will need to manually intervene. (sync sso id 6 first)

1 个赞