【问题标题】:AWS Cognito error "attempted to write unauthorized attribute" but I have added the attribute to the poolAWS Cognito 错误“尝试写入未经授权的属性”,但我已将该属性添加到池中
【发布时间】:2020-06-04 23:46:56
【问题描述】:

我正在尝试为我的 cognito 用户添加 hasSubscription 的自定义属性,并在注册和登录期间添加/更新它

        var hasSubscriptionAttribute = new AttributeType
        {
            Name = "custom:hasSubscription",
            Value = "0"
        };
        request.UserAttributes.Add(hasSubscriptionAttribute);

我已经通过控制台在 cognito 中添加了属性

然而,我仍然总是得到错误

客户端试图写入未经授权的属性

我错过了什么?

【问题讨论】:

    标签: amazon-cognito


    【解决方案1】:

    在您的控制台中,您将自定义属性“两次”声明为自定义。 你的名字是custom:hasSubscription 但它只能是hasSubscription。 Cognito 知道,该字段默认为自定义属性。

    您的请求保持不变。

    例如:使用您的自定义属性的当前声明,您的请求必须是

    var hasSubscriptionAttribute = new AttributeType
        {
            Name = "custom:custom:hasSubscription",
            Value = "0"
        };
        request.UserAttributes.Add(hasSubscriptionAttribute);
    

    我也犯了这个错误,这让我发疯了:)

    【讨论】:

    • 嗯,这没有意义。我只写了“hasSubscription”,它自动以“custom:”为前缀,还有一个其他自定义属性以相同的方式设置,没有问题,相同的命名方案等等。
    • 是的,按照Name = "custom:custom:hasSubscription" 的建议尝试过,同样的错误:(还有其他想法吗?
    【解决方案2】:

    好的,感谢https://medium.com/graymatrix/using-custom-attributes-in-amazon-cognito-user-pool-288cd3128bae

    我没有设置新属性的读写权限,在App Clients -> Show More -> 设置属性读写权限

    【讨论】:

      猜你喜欢
      • 2017-07-06
      • 2019-04-27
      • 2017-10-16
      • 2018-12-18
      • 2019-12-12
      • 1970-01-01
      • 2022-01-21
      • 2020-02-06
      • 2022-11-10
      相关资源
      最近更新 更多