使用 Google 问题进行 Firebase 身份验证

Ari*_*Roy 5 android firebase firebase-authentication

我一直在我的应用程序中使用 Firebase 身份验证,并注意到一个特定用例的问题。

我为我的应用程序启用了帐户链接注册流程,因此我可以附加与单个电子邮件地址关联的多个提供商。

场景 1:(工作正常)

用户最初与 Google 注册,稍后使用 Facebook 登录或使用电子邮件和密码注册。

帐户链接正常工作和Facebook和/或电子邮件在供应商列表中。

因此,我可以有 2 或 3 个电子邮件提供商,Google(最初)、Facebook 和密码(之后)。

场景2:(错误)

用户最初使用 Facebook 和/或电子邮件注册,后来使用 Google 登录,现在帐户链接不起作用。谷歌替换了以前的提供者。

帐户链接失败,我只是将 Google 作为与电子邮件地址关联的唯一提供商,而其他提供商都消失了。

在第二种情况下,当使用 Google 登录时,它应该失败并抛出,FirebaseAuthCollisionException但它没有成功。这是主要问题。

我不能在这里粘贴整个代码,但肯定只是一个片段。

firebaseAuth
                        .signInWithCredential(credential)
                        .addOnFailureListener(exception -> {
                            if (exception instanceof FirebaseAuthUserCollisionException) {
                                mCredentialToLinkWith = credential;
                                if (mProviderList.size() == 1) {
                                    if (mProviderList.contains(EmailAuthProvider.PROVIDER_ID)) {
                                        mRegisterProviderPresenter.linkWithEmailProvider(credential, email);
                                    } else {
                                        linkProviderAccounts(email, AuthenticationHelper.getProviderToLinkAccounts(mWeakActivity, mProviderList));
                                    }
                                } else {
                                    linkProviderAccounts(email, AuthenticationHelper.getProviderToLinkAccounts(mWeakActivity, mProviderList));
                                }
                            } else {
                                Timber.d("Failed in signInWithCredential and unexpected exception %s", exception.getLocalizedMessage());
                                mRegisterProviderPresenter.onRegistrationFailed(new ErrorBundle(ErrorBundle.FIREBASE_ERROR, exception.getLocalizedMessage()));
                            }
                        })
                        .addOnSuccessListener(authResult -> {
                            Timber.d("Success: signInCred");
                            FirebaseUser firebaseUser = authResult.getUser();
                            /**
                             * Store the user details only for first time registration
                             * and not while acc linking
                             */
                            storeUserCredentials(firebaseUser);
                            AuthenticationHelper.logUserDetails(firebaseUser);
                            mRegisterProviderPresenter.onRegistrationSuccess(mAlreadyRegistered);

                        });
Run Code Online (Sandbox Code Playgroud)

希望有人能提出一些帮助。

小智 2

Facebook 是一家社交身份提供商,但它不拥有电子邮件。如果电子邮件被黑客入侵,Facebook 无法检测到它并禁用该电子邮件注册的帐户。虽然谷歌是一家电子邮件提供商,但其帐户被认为更安全。

根据这一理论,场景 2 与场景 1 不同。在场景 1 中,用户首先通过与 Google 签名来证明这封电子邮件的所有权。因此,用户可以使用同一电子邮件添加 Facebook 帐户。在场景 2 中,首先进行 Facebook 登录,并且此提供商记录不受信任,因此当用户使用另一个受信任的提供商登录时,该记录将被删除。

您的代码行为在这两种情况下都是正确的。

  • 感谢您的精彩解释。那么,为什么最初用电子邮件和密码注册,然后用谷歌注册后,谷歌仍然取代它呢? (2认同)