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

**URL:** <https://meta.discourse.org/t/how-to-handle-discourse-sso-when-the-authentication-site-allows-users-to-change-emails/107374>\
**Category:** SSO\
**Created:** [2019 年1 月 24 日 08:03 UTC](https://meta.discourse.org/t/how-to-handle-discourse-sso-when-the-authentication-site-allows-users-to-change-emails/107374 "2019-01-24T08:03:59Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![jp9](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jp9](https://meta.discourse.org/u/jp9)\
发布日期： [2019 年1 月 24 日 08:03 UTC](https://meta.discourse.org/t/how-to-handle-discourse-sso-when-the-authentication-site-allows-users-to-change-emails/107374/1 "2019-01-24T08:03:59Z")

</div>

我们使用基于本指南实现的 [Discourse SSO](https://meta.discourse.org/t/13045?silent=true) 流程：[Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045)

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

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

> 登录错误
> 
> 您的账户存在问题。请联系站点管理员。

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

**有什么好的处理方法吗？**

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

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

我的请求如下：

```plaintext
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

```

收到的响应如下：

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

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-handle-discourse-sso-when-the-authentication-site-allows-users-to-change-emails/107374)._
