Migrating users to SSO


I have created an user on the dashboard (with Username-Password-Authentication, which is the only authentication method possible). I also enabled Microsoft social connection. Basically, I would like to give our users the option of being able to log in with username/password, and if they sign in using any social connection we have enabled, then I would like to automatically transfer over their account from Username-Password-Authentication to the social account (including any values in user_metadata and app_metadata).

Is this possible? Since i found if i connect using any social connection, it’ll just create a duplicate user with the same email.



This is definitely possible, but does require at least the Developer subscription, the free plan doesn’t support it.

Sounds like what you want to do, is automatically merge user accounts and transfer metadata. Auth0 has a rule template for that: https://github.com/auth0/rules/blob/master/rules/link-users-by-email-with-metadata.md.

I haven’t tested it, but I’m pretty sure there’s a slight error in it. In the docs they tell you to user context.primaryUser to switch the current login to the new merged account. However, in my testing I’ve noticed you need to also set the user object to the new merged account.

Basically, if you find that the above sample code doesn’t work as expected, changing

context.primaryUser = originalUser.user_id;


context.primaryUser = originalUser.user_id;
user = originalUser;

should fix the problem.

Hope that helps!