Database schema for Facebook, Google and my own authentication

I want to accomplish almost the same as this question , which is to store authentication data from multiple sources (Facebook, Twitter, my own app, etc.). so that one person can log into their account with all / all specified providers.

Next, I posted a screenshot of the two tables I created.

Database Schema

The "identity" table will be responsible for saving the login method (Facebook, Google or my login system). A user can have one or more identifiers.

The "identity" table will store the authentication method (facebook, google, myapp) in the "adapter" column. The "hash" column will store the authentication method identifier (for Google or Facebook), or if it's a record of my own application authentication method, the "hash" colunm will store the user's registered password, encrypted with SHA1.

My question is, for example: How can I determine if the user who authenticates through the Facebook account is no longer a "user" created using a different authentication method? Because I don't want to create multiple users, the same social network account owner or my own app account owner. Can I get this through the email column? So I can check if the authenticating user already has the same email address that was registered in the "user" table, if he does, then can I create an ID with the same user_id?

+3


source to share


1 answer


If possible, I would recommend that you add the user before adding the id. Before creating a user, check for a matching email, then add a new ID.



I would have thought that there should be an identity constraint that the user exists before being created. Otherwise, you run the risk of adding "Identity" to the database without any connected user.

0


source







All Articles