将OAuth与Firebase中的电子邮件/密码集成 [英] Integration OAuth with Email/password in Firebase

查看:76
本文介绍了将OAuth与Firebase中的电子邮件/密码集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试设置一个支持3种身份验证类型的应用程序: -电子邮件/密码 -Google(OAuth) -Facebook(OAuth)

在Firebase>身份验证>登录方法中,我启用了上面提到的3个选项. 在Firebase>身份验证>高级中,进行以下设置:防止创建具有相同电子邮件地址的多个帐户"

仅供参考,我在我的应用中使用[电子邮件/密码]创建帐户的密码与我的Google帐户不同,也与我的Facebook帐户不同(3个不同的密码-非常真实的情况)

  • [电子邮件/密码]:john.doe@gmail.com,密码123
  • [Google]:john.doe@gmail.com,密码456
  • [Facebook]:john.doe@gmail.com,密码789

我希望用户与他们想要的任何提供程序进行注册,然后再链接其他可用的登录/身份验证选项.

我可以设法正确设置[电子邮件/密码]或OAuth提供程序(Google和Facebook).但是,当我尝试将这3个部分整合在一起时,所有的事情都会变得松散.一些值得注意的错误:

  1. 场景A)

    • 使用电子邮件/密码/登录/退出创建用户(可以正常运行)
    • 使用如上所述的Google OAuth(与同一封电子邮件关联)登录,帐户链接在一起/登录/注销
    • 试图再次使用电子邮件/密码登录->错误
      • Google OAuth似乎已经覆盖了以前的帐户设置
  2. 场景B)

    • 使用电子邮件/密码/登录/退出创建用户(可以正常运行)
    • 使用如上所述的Facebook OAuth(与同一封电子邮件关联)登录,帐户被链接在一起,但是由于我使用的密码与我的Facebook密码不匹配,因此尝试登录时出现错误.但是,当我将Google和Facebook帐户关联在一起时,不会发生.为什么[电子邮件/密码]和OAuth提供程序会出现此问题?

我知道Firebase最近有一些更新/更改,也许我检查的文档/示例不是最新的.是否有人也能够成功通过OAuth提供者进行[电子邮件/密码]身份验证?谁能在网上提供一个很好的例子或我可以看看的一些最新文档?

顺便说一句,如果有帮助的话,可以在Angular5中运行代码. 在此先感谢您的帮助.

JB

解决方案

情况A)发生是因为未验证电子邮件/密码.该帐户已取消关联,以防止被劫持.例如,我可以声明另一个人的Google电子邮件并创建一个电子邮件/密码帐户.然后,该Google帐户的所有者将尝试登录该帐户.我应该失去它.要解决此问题,请在创建电子邮件/密码帐户后尝试验证电子邮件.经过验证的帐户不会取消关联.

情况B)由于密码的原因,不会发生这种情况. Firebase无法访问您的Facebook或Google密码.您确定链接正确吗?当您尝试使用与现有电子邮件/密码相同的电子邮件地址登录Facebook时,您将收到一个错误消息,即凭据已存在(该错误还返回了Facebook凭据),您需要首先登录现有的电子邮件/密码.帐户,然后将Facebook凭据链接到该帐户.

I've been trying to setup an application that supports 3 types of Authentication: - Email / password - Google (OAuth) - Facebook (OAuth)

In Firebase > Authentication > Sign-in methods, I've enabled the 3 options mentioned above. In Firebase > Authentication > Advanced, I have the following set: "Prevent creation of multiple accounts with the same email address"

Just FYI, the password I use in my app to create an account with [Email/password] is different from my Google account, which is also different from my Facebook account (3 separate passwords - very real world scenario)

  • [Email/password]: john.doe@gmail.com, Password123
  • [Google]: john.doe@gmail.com, Password456
  • [Facebook]: john.doe@gmail.com, Password789

I want a user to Sign up with whatever provider they want to and then later on, link any other available sign-in / authentication options.

I can manage to properly setup [Email / Password] or the OAuth providers (Google and Facebook). But, when I try and integrate all 3 together, all hell breaks loose. Some noted errors:

  1. Scenario A)

    • Create user with email / password / sign in / sign out (works fine)
    • Login with Google OAuth (associated to same email) as above, accounts are linked together / sign in / sign out
    • attempt to login with email/ password again -> ERROR
      • Google OAuth seems to have overridden the previous account settings
  2. Scenario B)

    • Create user with email / password / sign in / sign out (works fine)
    • Login with Facebook OAuth (associated to same email) as above, accounts are linked together but get an error when attempting to login because my password used doesn't match my Facebook password. Yet this DOESN'T HAPPEN when I link my Google and Facebook accounts together. Why this issue with [Email/password] and OAuth providers?

I know there have been some updates / changes recently within Firebase, maybe the documentation / examples I checked weren't up-to-date. Has anyone successfully been able to [Email/password] authentication with OAuth providers as well? Can anyone provide a good example online or some recent documentation I can take a look at?

Btw, running code in Angular5 if that helps. Thanks in advance for any help.

JB

解决方案

Scenario A) happens because the email/password is unverified. The account is unlinked to prevent hijacking. For example I can claim another person's google email and create an email/password account. The owner of that Google account will then try to login to that account. I should lose access to it. To solve, try verifying the email after the email/password account is created. The verified account will not be unlinked.

Scenario B) This does not happen because of the passwords. Firebase doesn't have access to your Facebook or Google password. Are you sure you linking the account correctly? When you try to login with Facebook using the same email as existing email/password, you will get an error that the credential already exists (the error also returns the Facebook credential), you will need to first sign in to the existing email/password account and then link the Facebook credential to that account.

这篇关于将OAuth与Firebase中的电子邮件/密码集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆