Reputation: 163
Here’s our scenario for implementing user accounts in our app
We don’t force users to complete steps #3 and #4. As long as they don’t need to switch devices, or factory reset their device, they won't lose access to their guest account.
Using Amazon Mobile SDK 2.3.x and Cognito Federated Identity Pools, we implemented the above steps as such:
To implement these steps, we used sample code generated by AWS Mobile Hub, before the introduction of Cognito User Pools. It used a combination of AWSIdentityManager and AWSFacebookSignInProvider, and their supporting code. Everything worked as expected.
We are now trying to convert to the latest Amazon Mobile SDK 2.4.9 and use Cognito User Pools instead of Facebook login, to implement the same flow:
Steps #1 & #2 are implemented using AWSIdentityManager from the AWSMobileHubHelper.framework; steps #3 & #4 are implemented with sample code from CognitoYourUserPoolsSample sample project.
The problems we’re having are:
There is a very important step that I’m missing here. I suspect that I’m not explicitly linking the Cognito User Pool login to the Cognito Identity Pool identity. In their CognitoYourUserPoolsSample, they don’t give an example of how to integrate User Pool identities with Federated Identity Pool.
The documentation says to simply do this and it’s automatic, but I couldn’t get that to work:
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
initWithRegionType:AWSRegionUSEast1
identityPoolId:@“<identity-pool-id>"
identityProviderManager:pool];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
Anyone have any ideas or sample code that demonstrates the process? The closest sample code I could find was this fork of CognitoSyncDemo, and it still wasn’t quite what I needed.
Upvotes: 4
Views: 1968
Reputation: 2728
The merging of identities is supported by the credentials provider but is not supported by the AWSIdentityManager (a part of the mobile-hub-helper). I have a modified version of the mobile-hub-helper (it is a fork off of the mobile-hub-helper github at https://github.com/BruceBuckland/aws-mobilehub-helper-ios). That fork modifies AWSIdentityManager to support several things: 1) It supports writing new AWSSignInProviders (a mobile-hub-helper protocol) and using them to resume sessions. 2) It supports "Allow Merged Identities" and the merging of identities. 3) It has a couple of helper methods to find which provider is doing the authenticating currently and the friendly name of a provider which is useful for showing the user what is linked, and showing which provider denied a login for example.
There is also a sample app that includes an implementation in swift of an AWSSignInProvider for Cognito User Pools. It demonstrates signin signout and account linking for the three providers (UserPools FaceBook and Google). It implements several capabilities of userpools including signup, signin, forgot password, update attributes, and the confirmation of those. It is at https://github.com/BruceBuckland/SignIn-awsmhh.
Finally I recommend that you take a look at the pdf of notes in the example app. They may help you understand the interactions of the components better. It took me a long time to understand cognito and I pulled my notes together to try to clarify the system for others. They are here: Cognito Notes and Diagram
Upvotes: 6