Authentication via social networks

2

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.

    
asked by anonymous 18.08.2016 / 20:50

1 answer

0

In your case I would use a master table for the user's local register and create tables for each social network (Face, Twt, etc.) with the ID of the master table being used as the key for all other tables. So you could even capture extra user data (local ?!), record dates of access made by each social network (individually), etc.

|  Tabela      |          Campos         |          
+--------------+-------------------------+
| User (master)| ID | name | email | etc |
| Facebook     | ID | SID  | email | etc |
| Twitter      | ID | SID  | email | etc |
| Outra        | ID | SID  | email | etc |
|______________|____|______|_______|_____|

The ID is the key; SID is the ID of each social network (or token); the other fields ( etc ) will be in charge of the need for your application.

Just add an extra sentence to the social network table in the INSERT or UPDATE.

    
29.07.2017 / 17:44