【问题标题】:Auth0: How to add custom properties to UserObject?Auth0:如何向 UserObject 添加自定义属性?
【发布时间】:2021-01-27 20:35:37
【问题描述】:

亲爱的 StackOverFlow 社区,您好, 我对 Auth0 了解不多,需要帮助。我想知道在创建用户时如何添加自己的属性?仅供参考,我已将 Auth0 连接到我自己的 MongoDB atlas 数据库。

我想在创建用户的时候添加一个customId,这个应该是一个16位的随机数。

然后我的 userObj 应该看起来像这样:

{
_id: ObjectId("5f720126054c87001662a138"),
connection:"MongoDB"
client_id:"zoClZ3gZE56iwblHXQ1vgwEcLfYr81Bx"
email:"gustek@gustek.com"
username:"gustek"
password:"$2b$10$dE69gGsDqVfWtmnXZ6EaKetILUmEju8N9PVjtDpgzzAp4jYNQbe8G"
tenant:"dev-test"
email_verified:false
customId:"9829539769841530"
}

我的意思是我在文档中找到了一些东西,但我不知道如何实现它: https://auth0.com/docs/users/set-metadata-properties-on-creation

我必须在这个表面上做吗?

正如我之前所说,我不知道如何才能做到这一点。我很感激每一个答案!

【问题讨论】:

    标签: javascript reactjs mongodb auth0


    【解决方案1】:

    您可以在用户对象中使用app_metadata 属性来存储不属于规范化用户配置文件的数据。这将包括您在此处描述的自定义 UUID。

    用户对象如下所示:

    {
        client_id: "<ID of creating client (application)>",
        tenant: "<name of creating Auth0 tenant>",
        email: "<email address for the user>",
        password: "<password for the user>",
        username: "<name associated with the user>",
        user_metadata: {
            "language": "en"
        },
        app_metadata: {
            "custom_id": "1234567890"
        }
    }
    

    虽然user_metadataapp_metadata 是可选的,但如果提供,它们不需要存储在旧身份存储中; Auth0 自动将这些值存储为内部创建的用户配置文件记录的一部分。这些值(可选)作为参考提供:它们的内容可能对传统身份创建产生影响。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多