I'm implementing authentication via Facebook and Twitter , and then other networks, but some doubts have arisen. How would the logic for creating a new account when the user authenticated via social network?
I assume that I get id
and e-mail
, but what would be the 'foreign key', between my database and the social network?
I take as an example the code below taken from a tutorial:
# baseado no ID do Facebook
select * from Users where Fuid = '$fuid'
# (IF) novo usuario
INSERT INTO User (Fuid , Femail) VALUES ('$fuid' , '$femail')
# (ELSE) atualiza dados do usuario
UPDATE Users SET Femail = '$femail' where Fuid = '$fuid'
In the example it takes id
of Facebook as a single base, inserts or updates the email, name and any other information available.
How do I integrate networks when the Facebook user and Twitter have the same email? Each authentication would return a id
different, so it does not apply to the above code.