Question:
I’m using AWS Cognito and aws-cpp-sdk for my application. I defined a user pool and an application, then I got app client id and app secret.
I can create user pool object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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); |
After I defined an user with SignUpRequest, there was an error like this: NotAuthorizedException A client attempted to write unauthorized attribute
This is my signup code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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); |
What is the problem? How can I solve it?
Answer:
Omg! The reason of exception is only writing mistake. The problem is solved by correcting typing error from familiy to family at this line:
1 2 |
family_name.WithName("familiy_name").WithValue("xxx"); |