# Cognito 和 SAML 因用户名出现问题

**URL:** https://meta.discourse.org/t/issue-with-cognito-and-saml-due-to-usernames/182866
**Category:** Feature
**Created:** [2021年三月11日 09:38 UTC](https://meta.discourse.org/t/issue-with-cognito-and-saml-due-to-usernames/182866 "2021-03-11T09:38:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dassun](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dassun/32/114528_2.png) [@dassun](https://meta.discourse.org/u/dassun)
#### Post date: [2021年三月11日 09:38 UTC](https://meta.discourse.org/t/issue-with-cognito-and-saml-due-to-usernames/182866/1 "2021-03-11T09:38:02Z")

</div>

您好，

在 OpenID 的上下文中，Cognito 为 SAML 提供商生成的用户名采用 `{provider}_{email}` 的格式，例如 `google_john.doe@gmail.com`。由于 @ 符号不是用户名中的有效字符，这会导致无法在 Discourse 中创建用户。是否有办法绕过此限制，可能仅针对 OpenID 用户？

谢谢，

David

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2021年三月11日 11:40 UTC](https://meta.discourse.org/t/issue-with-cognito-and-saml-due-to-usernames/182866/2 "2021-03-11T11:40:58Z")

</div>

我不太确定，但解决方案似乎是：要么配置 Cognito 使用不同的用户名，要么改用 Cognito 的 `preferred_username` 作为 Discourse 用户名。

---

<div class="post-metadata">

### Author: ![dassun](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dassun/32/114528_2.png) [@dassun](https://meta.discourse.org/u/dassun)
#### Post date: [2021年三月12日 13:47 UTC](https://meta.discourse.org/t/issue-with-cognito-and-saml-due-to-usernames/182866/3 "2021-03-12T13:47:26Z")

</div>

已解决！我已升级到 2.7.0.beta5，一切符合预期。这意味着我的理论不正确，问题出在其他地方，现在已解决。谢谢。
