kratos icon indicating copy to clipboard operation
kratos copied to clipboard

Add a way to merge identity credentials.

Open David-Wobrock opened this issue 2 years ago • 0 comments

Preflight checklist

Describe your problem

Kratos does not allow automatic account linking when doing social sign-in. This is great for security reasons. So, for instance, when an account for [email protected] exists in Kratos, and I connect through Google SSO, a new identity with [email protected] will be created if this Google account has never been used.

In our case, we want to allow our users to prove that they own the existing account by typing their password. If they can prove this, we want to merge both identities together. More precisely, we want the Google SSO credentials to be linked to the existing identity - so that next time the user connects, they are connected with the existing identity.

Describe your ideal solution

One possible solution would be to provide an admin API endpoint in Kratos, that allows merging two identites. We could identify the current identity through the Kratos cookie, and the target identity by passing their UUID in the URL. The end result would be that the current identity has been deleted, and the credentials associated to it are now linked to the target identity.

This will allow having one transaction to encapsulate the logic. The problem with the workaround is that it is subject to race conditions, if the target identity is updated at the same time by two or more requests I believe.

Workarounds or alternatives

The workaround we plan to use for now is:

  1. Fetch the credentials from identity A => using https://www.ory.sh/docs/kratos/reference/api#operation/adminGetIdentity
  2. Import the credentials from A into identity B => using https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities#social-sign-in-connections
  3. Delete identity A => using https://www.ory.sh/docs/kratos/reference/api#operation/adminDeleteIdentity

Version

0.10.1

Additional Context

Discussed in the Ory Slack with Thomas => https://ory-community.slack.com/archives/C012RJ2MQ1H/p1662728891106129

David-Wobrock avatar Sep 12 '22 13:09 David-Wobrock