问题
as written in the title is it possible change username of a Amazon Cognito user? I can't find anything in documentation
回答1:
It is possible to update the preferred_username
of a Cognito User using the iOS SDK, using the updateAttributes
API call. However, kindly note that you would not be able to modify the username
of a user. Quoting the official AWS documentation,
The username value is a separate attribute and not the same as the name attribute. A username is always required to register a user, and it cannot be changed after a user is created.
But, the preferred_username
value can indeed be changed, and a sample code to change the preferred username using the iOS SDK, as per the official documentation is stated as follows:
AWSCognitoIdentityUserAttributeType * attribute = [AWSCognitoIdentityUserAttributeType new];
attribute.name = @"preferred_username";
attribute.value = @"John User";
[[user updateAttributes:@[attribute]] continueWithSuccessBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserUpdateAttributesResponse *> * _Nonnull task) {
//success
return nil;
}];
I would also like to state that the AWS API documentations for the iOS SDK are rather minimal, and I would recommend developers to go through the SDK source code whenever in doubt.
来源:https://stackoverflow.com/questions/55774309/is-it-possible-change-username-in-amazon-cognito-with-ios-sdk