# 将用户名限制为用户名字

**URL:** <https://meta.discourse.org/t/restrict-username-to-user-first-name/297604>\
**Category:** Support\
**Created:** [2024年三月2日 13:29 UTC](https://meta.discourse.org/t/restrict-username-to-user-first-name/297604 "2024-03-02T13:29:49Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [2024年三月2日 17:58 UTC](https://meta.discourse.org/t/restrict-username-to-user-first-name/297604/4 "2024-03-02T17:58:20Z")

</div>

如果您控制着 openID 服务器，那么您应该能够让它将任何您想要的内容发送到 Discourse。

这可能会有帮助：

> [@How to configure the OIDC to set the Username as the email account name or a username like value returned from my auth providers?](https://meta.discourse.org/t/how-to-configure-the-oidc-to-set-the-username-as-the-email-account-name-or-a-username-like-value-returned-from-my-auth-providers/268438/2?u=pfaffman):
>
> The Discourse OIDC plugin will use the ‘nickname’ claim provided by the identity provider. So you’ll need to review the documentation for your identity provider and work out how to make it send the ‘nickname’ value that you’d like.

看起来您可以填充 `preferred_nickname` 字段，使其包含您想要的用户名。您在该字段中发送的是什么？如果它是空的或者他们的全名，那将是您首先应该更改的好地方。

> <https://github.com/discourse/discourse-openid-connect/blob/3af9b35c51123b82958c4d95cfcc83527408cedb/lib/omniauth_open_id_connect.rb#L204%23L204>

---

_[View the full topic](https://meta.discourse.org/t/restrict-username-to-user-first-name/297604)._
