Guidance on merging/converting local and social logins

(Ryan Bolger) #1

I’m currently in the process of migrating from a custom forum solution to Discourse. Part of this involves importing the existing local users into the Discourse users database. However, one of the primary features we were planning on using are the various social login options. Some of our users would prefer to ditch their forum specific login credentials and switch to Facebook/Google/Twitter after the migration is complete.

The user details page for a given user lists an attribute called “Associated accounts” which makes it sound like a given “user” can be associated with more than one login type. Is that actually the case? And if so, is there any way to associate a social login to an existing local account?

Alternatively, is there any way to simply convert an existing local login to a social login? I assume the process would go something like this:

  • Placeholder user is imported from old forum
  • User registers new account using one of the social logins
  • Admin does magical hand waving and transfers the social login association from the new account to the old account, deleting the new account in the process
  • All of old user’s associated posts and preferences are now attached to the social login.

(Jeff Atwood) #2

Identity is keyed on email address, so what you want already exists – if the social login provides a validated (confirmed, known to be 100% accurate) email address, you can log in with any social login that maps to a known email address.

For example, if

  • your email is
  • you hold a traditional username/password account


  • you log in via Facebook which returns as your FB email

You will be automatically logged into your account as if you had typed in the username and password.

(Ryan Bolger) #3

That is perfect and makes total sense. So yay!

And in the case where the user’s FB email is different than their old forum email, we should be able to administratively change the email address associated with the traditional account to match the FB one assuming it is known in advance?

(Ryan Bolger) #4

I was just thinking of an edge case in our current solution that might need a separate feature request, but is somewhat related to this topic.

Assume a setup where posts and replies can be submitted via email. Some of our users tend to send email from multiple addresses. Or in other cases, their inbound email address is different than their outbound email address (aliases, forwards, etc). But in order to support that in Discourse right now, I’m guessing there would have to be separate users configured for each address that would be submitting posts/replies from. Is that right? It would have to be a feature request (or plugin?) to support multiple email aliases on a given account.

(Kane York) #5

Yes, somewhat unfortunately. The inbound email processor will look at all the From addresses and try to match up a user account to any of the emails.

(Ryan Bolger) #6

Is that something a plugin would hypothetically be able to remedy? Or would the changes necessary to the email processor not really work with a plugin?

I imagine an additional field on user accounts called something like Alternate Emails. They wouldn’t necessarily be used to login with (though that could be an option as well). They’d go through the same verification process that the primary email address does. And the email processor would include them in its search for a matching account.

(Kane York) #7

It would work better with a refactor to core: pull out these lines into their own method. That was already done for the destination addresses.

After looking at the code, reply-by-email actually pulls the user ID from the key - so alternate emails work fine there! So you’ll probably be fine unless you want email-in.

. discourse/receiver.rb at b37d845dd3f598bd7e7b825a36648f3cfa239b78 · discourse/discourse · GitHub