I am doing a little work with Facebook Connect and wondering how on Stack Overflow for example, you are able to login using another login provider such as Facebook or Yahoo, and for the site to be able to pick up your user details as you registered them on Stack Overflow? As far as I am aware, you could have registered using a different email address and your first name and last name are not unique identifiers, so how is it done?
Share
You would most likely add a new column on to your user table such as facebook_uid. Then, if a user has an existing account, you would get them to sign in to that first, before connecting to facebook, you can then store their facebook_uid against your existing user_id. Then if the user turns up and is already signed in to facebook, you can sign them into your website as well. If the user doesn’t have an existing account on your site, you would simply create one (possibly filling it with the users name from facebook)
If you wanted to allow multiple methods of sign in, you could potentially have another table that holds a mapping between a provider (facebook,twitter,google etc) and the associated id for that account back to your user table.
The basics are, when they sign in with a 3rd party login system, you either map it to a current account on your site, or you create new account on your site if one does not already exist, and you map the account to it. You would obviously need to make this clear to your users, or have some way to merge accounts in case they aren’t already signed in when they use a 3rd party. You could also potentially ask for email access from facebook and try and map that to an existing account, before creating a new one
Thanks