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

AWS Cognito NotAuthorizedException A client attempted to write unauthorized attribute

我正在为我的应用程序使用 AWS Cognitoaws-cpp-sdk。我定义了一个用户池和一个应用程序,然后我得到了应用程序客户端 ID 和应用程序密码。 我可以创建用户池对象:

    Aws::Client::ClientConfiguration clientConfig;
    clientConfig.region =
        Aws::Region::EU_CENTRAL_1;  // "RegionEndpoint.EUCentral1";
    clientConfig.scheme = Aws::Http::Scheme::HTTPS;
    clientConfig.connectTimeoutMs = 30000;
    clientConfig.requestTimeoutMs = 600000;

    CognitoIdentityProviderClient client;
    client = CognitoIdentityProviderClient(clientConfig);

    DescribeUserPoolClientRequest describeUserPoolClientRequest;
    describeUserPoolClientRequest.WithUserPoolId(POOL_ID)
        .WithClientId(TEST_APP_CLIENT_ID);
    DescribeUserPoolClientOutcome describeUserPoolClientOutcome =
        client.DescribeUserPoolClient(describeUserPoolClientRequest);

在我用 SignUpRequest 定义了一个用户后,出现了这样的错误:NotAuthorizedException A client attempted to write unauthorized attribute

这是我的注册码:

    SignUpRequest signUpRequest;
    signUpRequest.SetClientId(describeUserPoolClientOutcome.GetResult()
                                  .GetUserPoolClient()
                                  .GetClientId());
    signUpRequest.SetUsername("xxxxx");
    signUpRequest.SetPassword("xxxxxx?");
    AttributeType email, phone_number, gender, given_name, family_name, picture;
    email.WithName("email").WithValue("gacer@ku.edu.tr");
    phone_number.WithName("phone_number").WithValue("+xxxxx");
    given_name.WithName("given_name").WithValue("xxx");
    family_name.WithName("familiy_name").WithValue("xxx");
    gender.WithName("gender").WithValue("MALE");
    picture.WithName("picture").WithValue(
        "http://xxxx");
    signUpRequest.AddUserAttributes(email);
    signUpRequest.AddUserAttributes(phone_number);
    signUpRequest.AddUserAttributes(given_name);
    signUpRequest.AddUserAttributes(family_name);
    signUpRequest.AddUserAttributes(gender);
    signUpRequest.AddUserAttributes(picture);

    SignUpOutcome signUpOutcome = client.SignUp(signUpRequest);

问题是什么?我该如何解决?

在 AWS 网站中,转到您的用户池 -> 应用程序 -> 显示详细信息 -> 设置属性读写权限。确保您尝试写入的每个属性都在可写属性列表中,并且它们都有一个复选标记。

天哪!异常的原因只是写错了。通过在以下行更正 familiy 到 family 的输入错误来解决问题:

family_name.WithName("familiy_name").WithValue("xxx");

我有同样的问题,但通过在其他属性中添加 custom: 解决了这个问题。 在添加自定义属性时 您需要添加

custom:family_name