I am trying to change a user's attribute (i.e family name) after they have signed up. This is an attribute that has been selected in the cognito user pool and was filled out when they initially signed up. I have only setup a user pool and not an identity pool.
For that, I am using the method adminUpdateUserAttributes in the AWSCognitoIdentityProvider, using the iOS SDK but it gives me the following error:
Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" UserInfo={__type=MissingAuthenticationTokenException, message=Missing Authentication Token}
Here is my setup in the AppDelegate:
let clientId:String = self.cognitoConfig!.getClientId()
let poolId:String = self.cognitoConfig!.getPoolId()
let clientSecret:String = self.cognitoConfig!.getClientSecret()
let region:AWSRegionType = self.cognitoConfig!.getRegion()
let serviceConfiguration:AWSServiceConfiguration = AWSServiceConfiguration(region: region, credentialsProvider: nil)
let cognitoConfiguration:AWSCognitoIdentityUserPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: clientId, clientSecret: clientSecret, poolId: poolId)
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: cognitoConfiguration, forKey: userPoolID)
let pool:AWSCognitoIdentityUserPool = AppDelegate.defaultUserPool()
pool.delegate = self
AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration
Here is my code for actually trying to change the attribute
let identityProvider = AWSCognitoIdentityProvider.default()
let requestAttributeChange = AWSCognitoIdentityProviderAdminUpdateUserAttributesRequest()
requestAttributeChange?.username = user?.username
requestAttributeChange?.userPoolId = AppDelegate.defaultUserPool().userPoolConfiguration.poolId
let attribute = AWSCognitoIdentityProviderAttributeType.init()
attribute?.name = "given_name"
attribute?.value = "TEST"
if let att = attribute {
print("Change attribute")
requestAttributeChange?.userAttributes = [att]
identityProvider.adminUpdateUserAttributes(requestAttributeChange!).continueWith(block: { (res) -> Any? in
print(res.error)
})
}
Do I need to setup a separate identity pool too? I am also not sure about the type of data/keys that i will need to store in addition to get more access? As I am trying to avoid storing any sensitive data on the actual device.
from Unable to mutate user attributes using iOS Cognito UserPool SDK after signup
No comments:
Post a Comment