Choosing user ID in application that relies on Auth0 for Facebook authentication?

依然范特西╮ 提交于 2019-12-11 04:19:24

问题


I'm creating a TODO list application using Angular and PHP.

I use Auth0 to allow Facebook authentication and after the process completes the user is redirected to add TODO page. However, I'm confused on how to save that TODO item in my MySQL database. Which user ID should I use to save the TODO item?

I'm getting Facebook user ID in return; can I save it using the FB user ID?


回答1:


You can, but if you use the Facebook ID as your internal way to identify users in your MySQL database you're making your application less flexible to change.

For example, you save the Facebook ID in a column with a data type that supports the Facebook ID format. Now imagine, that in two months you also want to support Google users.

The Google ID may be in a format that your chosen data type does not support, so you'll need to make changes. Additionally, it could even the case that Google and Facebook identifiers are not globally unique so the same identifier can be used by Google to represent user A while at Facebook it's used for user B.

Your best bet is to save the data in association with an internal identifier that you manage and them mapped it to a globally unique way to identify your users; for example an email address.

Given you are using Auth0 you can take advantage of the fact that it will provide you with a globally unique identifier for each user. This means you can later support new ways to authenticate your users and Auth0 will always provide your application with a globally unique ID, even in scenarios that users authenticate without having to provide email addresses.



来源:https://stackoverflow.com/questions/40695511/choosing-user-id-in-application-that-relies-on-auth0-for-facebook-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!