I am developing an app that uses both Facebook and Google login with AWS Cognito identities, using Amazon.CognitoIdentity. I am trying to do some testing with the two different identity providers on my Android phone. For my testing, I want to have two separate Cognito identities: one for Facebook login, and one for Google login. However, I am running into the following problem.
I initially logged in on my phone via Facebook. This works fine. I can log in repatedly with Facebook, and I always get the same Cognito Identity ID, which is good. But now, I want to test the Google login. So this time, I use the new Google Login button that I just added to my app. Since my Google account had never been associated with my Cognito Identity, I was expecting Cognito to assign me a new Identity ID. However, when I run the following code, using the Google provider name and token:
CognitoAWSCredentials _cognitoCredentials = new CognitoAWSCredentials( "us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Identity Pool ID _awsRegion); // Region if (_identityProviderInfo.ProviderName != null) _cognitoCredentials.AddLogin(_identityProviderInfo.ProviderName, _identityProviderInfo.Token); _identityId = _cognitoCredentials.GetIdentityId();
I get back the same Identity ID as before (when I was using Facebook), which I didn't expect.
Also, the call to AddLogin() doesn't seem to be doing anything. If I browse my identities in the AWS console, it shows that I still only have one linked login (Facebook). My assumption is that this is happening because I'm trying to add Google as a linked login, but it's using an existing Cognito Identity ID, and I haven't logged in via Facebook first to authenticate, and it's thus failing. Unfortunately, AddLogin() doesn't return a value, and it's not throwing an exception either, so as far as I can tell, it's just failing silently, which makes it difficult to test my hypothesis.
So, what I'd really like to do it to have it create a new Cognito identity when I log in with a new identity provider, but I don't know how I can do that. I'm guessing that the SDK is caching my Cognito Identity ID somewhere on the device, and thus using the same one every time, but I would like to somehow clear that, so that I can start fresh with a new Cognito identity ID for Google. I know that I could delete the Identity from the AWS console, but I don't want to do that because I have a lot of data stored in DynamoDB linked to that identity that I don't want to lose, and I'm still not sure that that would solve my problem on my device.
What can I do?