Menu
Amazon Cognito
Developer Guide (Version Last Updated: 07/28/2016)

Switching Identities

Android

Users can begin their life in an application as unauthenticated guests. Eventually they may decide to log in using one of the supported identity providers. Amazon Cognito will ensure that an old identity retains the same unique identifier as the new one, and the profile data will be merged automatically.

Your application is informed of a profile merge through the IdentityChangedListener interface. Implement the identityChanged method in the interface to receive these messages:

Copy
@override public void identityChanged(String oldIdentityId, String newIdentityId) { // handle the change }

iOS - Objective-C

Users can begin their life in an application as unauthenticated guests. Eventually they may decide to log in using one of the supported identity providers. Amazon Cognito will ensure that an old identity retains the same unique identifier as the new one, and the profile data will be merged automatically.

NSNotificationCenter informs your application of a profile merge:

Copy
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(identityIdDidChange:) name:AWSCognitoIdentityIdChangedNotification object:nil]; -(void)identityDidChange:(NSNotification*)notification { NSDictionary *userInfo = notification.userInfo; NSLog(@"identity changed from %@ to %@", [userInfo objectForKey:AWSCognitoNotificationPreviousId], [userInfo objectForKey:AWSCognitoNotificationNewId]); }

iOS - Swift

Users can begin their life in an application as unauthenticated guests. Eventually they may decide to log in using one of the supported identity providers. Amazon Cognito will ensure that an old identity retains the same unique identifier as the new one, and the profile data will be merged automatically.

NSNotificationCenter informs your application of a profile merge:

Copy
[NSNotificationCenter.defaultCenter().addObserver(observer: self selector:"identityDidChange" name:AWSCognitoIdentityIdChangedNotification object:nil) func identityDidChange(notification: NSNotification!) { if let userInfo = notification.userInfo as? [String: AnyObject] { print("identity changed from: \(userInfo[AWSCognitoNotificationPreviousId]) to: \(userInfo[AWSCognitoNotificationNewId])") } }

JavaScript

Users can begin their life in an application as unauthenticated guests. Eventually they may decide to log in using one of the supported identity providers. Amazon Cognito will ensure that an old identity retains the same unique identifier as the new one, and the profile data will be merged automatically.

Unity

Users can begin their life in an application as unauthenticated guests. Eventually they may decide to log in using one of the supported identity providers. Amazon Cognito will ensure that an old identity retains the same unique identifier as the new one, and the profile data will be merged automatically.

You can subscribe to the IdentityChangedEvent to be notified of profile merges:

Copy
credentialsProvider.IdentityChangedEvent += delegate(object sender, CognitoAWSCredentials.IdentityChangedArgs e) { // handle the change Debug.log("Identity changed from " + e.OldIdentityId + " to " + e.NewIdentityId); };

Xamarin

Users can begin their life in an application as unauthenticated guests. Eventually they may decide to log in using one of the supported identity providers. Amazon Cognito will ensure that an old identity retains the same unique identifier as the new one, and the profile data will be merged automatically.

Copy
credentialsProvider.IdentityChangedEvent += delegate(object sender, CognitoAWSCredentials.IdentityChangedArgs e){ // handle the change Console.WriteLine("Identity changed from " + e.OldIdentityId + " to " + e.NewIdentityId); };