Multiple AWS Cognito Federated Identities (e.g. Facebook and Google logins for the same email) can be merged into a single identity by passing both logins in the Cognito call. But knowing that I can merge identities doesn't answer whether I should merge identities.
What are the pros and cons of merging identities vs. keeping them separate? (We store user profiles in our own database; we don't use Cognito User Pools. If we don't merge identities, then our back-end database would store the mapping of each identity ID to the correct user ID in our back-end database.)
Here's the current workflow of the app when the same user tries to auth using both Facebook and Google:
- On the client (it's a web app), a new user clicks Login and chooses to log in using Facebook.
- The client code logs the user into Cognito Federated Identities and obtains new a federated identity ID that is authorized to call our AWS Lambda functions.
- The client calls our
getOrCreateUserProfile
Lambda function which uses the Cognito Identity ID as a key to see if that Cognito identity is already associated with a user. - Because no other users with this identity ID are found in our database, and because no other user has this email address (because it's a brand-new user), then our Lambda function will create a new user profile in our database and return the profile back to the user.
- At some point later, the user tries to log in (on the same device or on another device) using Google.
- A new Federated Identity is created for this Google identity.
- Our
getOrCreateUserProfile
Lambda function can't find an existing user matching this Identity ID, but does find another user with the same email address.
At this point we have three options:
- A) Return an error to the user, e.g. "Please log in using your Facebook account". This is the current behavior that we want to change.
- B) Merge the identities by requiring the user to log in using Facebook too, and then pass both identities to Cognito which will merge them. See https://mcmap.net/q/1011103/-how-does-aws-cognito-merge-identities
- C) Add a mapping row in our back-end database to map the new identity to user's existing user profile. Now this user will have two Federated Identities: one using the Facebook provider, one using the Google provider.
What are the pros and cons of option (B) vs. option (C)? Below is a starting point for this comparison. What pros/cons am I missing?
Merge Identities
- Pro
- Simpler/faster lookups because there's only one Identity ID per user that must be indexed on the back end
- I assume this is the most secure solution?
- Con
- The merging process itself seems complex and error-prone. For example, after merging, if the new ID "wins" the merge, then we'll need to replace the old ID with the new one in the user profile... and if something goes wrong during that process we might be left in an unrecoverable state where Cognito only knows about the new (merged) ID but our database only knows about the old one.
- More complex UX where user must log in (albeit only once) to both Facebook and Google accounts in the same session in order to link those accounts.
- Any later changes to linking must go through Cognito API
Keep Separate
- Pro
- Simpler UX: we can link social accounts by matching the email addresses; no need for both logins in one session
- Can control linking solely within our back-end database, which should make it easier to build admin tools that add/remove/change identity->user-profile links as opposed to having to call Cognito's API to perform these actions.
- No risk of Cognito getting out of sync with our back-end DB. If linking fails, the user can simply retry.
- Con
- Need a many:1 index to map Identity ID -> User Profile, instead of a single indexed column
- Is this a less secure solution? If so, why?
- Is this more costly in AWS charges? If so, why?
I'm leaning towards the "Keep Separate" solution because it seems simpler to implement (no extra UX workflow) and easier for users (for the same reason: no new UX workflow). Is this a mistake?