简体   繁体   English

在我的网站上管理谷歌登录和常规用户登录的最佳方式

[英]Best way to manage google sign-in and regular user sign-in on my website

I have a website where the user can create an account, given the basic user information like "username", "password", "e-mail", etc...我有一个网站,用户可以在其中创建一个帐户,给定基本的用户信息,如“用户名”、“密码”、“电子邮件”等......

Now, I want to implement google sign-in, but im not sure how the back-end will be managed.现在,我想实现谷歌登录,但我不确定后端将如何管理。 Should I create a different table for google users, or merge it to the original user table, but the problem is the google sign-in has no password associated with it, do I make the password not required, generate a random password, or make the user create a password?我应该为谷歌用户创建一个不同的表,还是将它合并到原始用户表,但问题是谷歌登录没有与之关联的密码,我是不需要密码,生成随机密码,还是让用户创建密码?

And what if the user wants to register through the regular means with the same e-mail, but it already used the google sign-in, should the account be merged with the original one so he doesn't loose his data?如果用户想通过常规方式使用同一个邮箱注册,但已经使用了google登录,是否应该将帐户与原始帐户合并,以免丢失他的数据?

what you are describing here is a problem that many websites have.您在这里描述的是许多网站都存在的问题。 I don't think that there is a right or a wrong answer.我认为没有正确或错误的答案。

From my experience: I would suggest to maintain a column in your user table that indicates the auth type.根据我的经验:我建议在您的用户表中维护一个指示身份验证类型的列。 it could be "password" for users who login with password, and "google" for login with google users.对于使用密码登录的用户,它可能是“密码”,对于使用谷歌用户登录的用户,它可能是“谷歌”。

the password column should only be populated when the user actually uses the password auth mechanism.只有当用户实际使用密码验证机制时,才应填充密码列。 That is for security purposes to ensure no account take overs happen on accounts that are authenticated via other means.这是出于安全目的,以确保不会在通过其他方式进行身份验证的帐户上发生帐户接管。

If you want to allow users to "login with password", then you can implement a flow, that will:如果您想允许用户“使用密码登录”,那么您可以实现一个流程,这将:

  • send a confirmation email to the user (so you know the person logged in has access to that mail account)向用户发送确认 email (这样您就知道登录的人可以访问该邮件帐户)
  • when the user clicks the link asks the user to specify a password当用户单击链接时,要求用户指定密码
  • then save the password and update the authentication type.然后保存密码并更新身份验证类型。

Also - the other way around - when you have a user who has a password and then starts to click "login with google" - you should probably also have a flow to migrate the user to login with google.另外——反过来——当你有一个用户有密码然后开始点击“用谷歌登录”时——你可能还应该有一个流程来迁移用户以用谷歌登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM