Amazon Cognito set identityId using Obj C Developer Authentication

I am trying to authenticate my user using authenticated Cognito and developer identifiers. My question is how to set the identifier with the correct version returned from my iOS backend using objective-c?

If I make calls manually in the code or using a postman, the correct identifier is returned by my server, and Cognito recognizes it and correctly changes the tokens.

The iOS kernel seems to assign an identifier itself, which is not true. I am really trying to understand the documentation as it is outdated and vague.

Here is my code below:

NSLog(@"Complete login"); NSMutableDictionary *merge = [NSMutableDictionary dictionaryWithDictionary:self.credentialsProvider.logins]; [merge addEntriesFromDictionary:logins]; self.credentialsProvider.logins = merge; // Force a refresh of credentials to see if we need to merge task = [self.credentialsProvider refresh]; NSLog(@"Complete login 2-- %@", self.credentialsProvider.identityId); //The identityId assigned is incorrect... NSLog(@"Complete login 2-- %@", self.credentialsProvider.identityPoolId); //The identityPoolId is correct 

SOME FLOWERS BELOW: Here's how it works: 1 - When starting the application, a random identifier identifier from Amazon is automatically assigned (therefore, the user is not authenticated initially). 2 - The user enters his credentials, then my code queries the URL for my server, which returns a valid token and the correct identifier for the username and password. 3 - Now this new identifier must be initialized in the code to override the old unverified identifier. 4 - The new idendityId and token that were returned from my server must be sent to Cognito for final authentication, and Cognito returns more authentication. When I speak manually, I send a request through the postman.

In short: 1: How do I change / set my identifier? 2: How to send updated credentials received from my end on my client to Cognito?

+7
ios objective-c amazon-web-services amazon-cognito
source share
1 answer

The identityId in the AWSCognitoCredentialsProvider instance has a readonly attribute, so it cannot be changed after it is initialized. The only way to set it up is through initialization.

 id<AWSCognitoCredentialsProvider> credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:<Region> identityProvider:identityProvider unauthRoleArn:nil authRoleArn:nil]; 

After user authentication, be sure to update the login card as follows:

 credentialsProvider.logins = @{DeveloperProviderName: userIdentifier} [credentialsProvider refresh]; 

source: http://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html

ps: make sure that you implement the identity provider correctly and you must set the identifier identifier in the update method

 - (AWSTask *)refresh { /* * Get the identityId and token by making a call to your backend */ // Call to your backend // Set the identity id and token self.identityId = response.identityId; self.token = response.token; return [AWSTask taskWithResult:self.identityId]; } 
+2
source share

All Articles