Recall, the original sensor and sensor2 projects were plumbed with Login With Amazon as the identity provider to Cognito. This new experiment adds GooglePlus as a second provider. Here you can see the test platform on the iPhone:
Keep in mind that for this sensor2 application, the returned CognitoId is used as the customer's key into the storage databases. Both for access control and as the DynamoDB hash key.
The flow on the iPhone goes roughly as follows:
- A user can login via one or both of the providers
- A user can logout
- A user can also login using same credentials on a different devices (e.g. another iPhone with the application loaded)
Now here's the interesting part. Depending on the login ordering, the CognitoId returned to the application (on the watch in this case) can change! Here's how it goes with my test application (which includes "Logins" merge)
- Starting from scratch on a device
- Login via Amazon where user's Amazon identity isn't known to this Cognito pool:
- User will get a new CognitoId allocated
- If user logs out and logs back in via Amazon, the same Id will be returned
- If the user now logs into a second device via Amazon, the same Id will be returned
- (so far this makes complete sense)
- Now, if the user logs out and logs in via Google, a new Id will be returned
- Again, if the user logs out and in again and same on second device, the new Id will continue to be returned
- (this all makes sense)
- At this point, the system thinks these are two users and those two CognitoIds will be used as different primary keys into the sensor database...
- Now, if the user logs in via Amazon and also logs in via Google, a CognitoId merge will occur
- One, or the other of those existing Ids from above will be returned
- And, the other Id will be marked via Cognito as disabled
- This is a merge of the identities
- And this new merge will be returned on other devices from now on, regardless of whether they log in solely via Amazon or Google
- (TODO: what happens if user is logged into Amazon, has a merged CognitoId and then they log in using a second Google credential?)
- As with my application, if the sensor database is keyed by the CognitoId, then there will be issues of accessing the data indexed by the disabled CognitoId after a merge
- TODO: will this happen with multiple devices going through an anonymous -> identified flow?
- It may be that additional resolution is needed to help with the merge -- e.g. if there is a merge, then ask the user to force a join -- and then externally keep track of the merged Ids as a set of Ids -> primary keys for this user...
Anyway, I'm adding in a couple more providers to make this more of a ridiculous effort. After which I'll think about resolution strategies.
"As with my application, if the sensor database is keyed by the CognitoId, then there will be issues of accessing the data indexed by the disabled CognitoId after a merge"
ReplyDeleteIt seems like a similar problem was raised by this AWS forum question (there is a slightly different case with "anonymous to authenticated" workflow, but the root issue is the same: CognitoId changes). And the official answer is quite discouraging: delete your old records in DynamoDB and re-add them with a new CognitoId...