如何在 Android 上使用 FirebaseUI 进行帐户链接?

How to use FirebaseUI for account linking on Android?

我在 android 应用程序中使用 Firebase 身份验证。 我可以使用用户的 Gmail ID 或 phone 号码登录用户。 如果用户已经使用电子邮件 ID 或 vise-vers 登录,我想 link phone 编号。 我参考了FirebaseUI的Firebase Auth documentation for account linking but they have done it manually (getting phone number and OTP manually). But on its main page,写的是

Account Linking - flows to safely link user accounts across identity providers.

作为其特色之一。但是没有提到如何为帐户linking.

使用FirebaseUI

这是我到目前为止所做的:

我正在使用这三个功能来登录用户。

public void signInWithAllProviders() {
    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.EmailBuilder().build(),
            new AuthUI.IdpConfig.PhoneBuilder().build(),
            new AuthUI.IdpConfig.GoogleBuilder().build(),
            new AuthUI.IdpConfig.FacebookBuilder().build());
    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .build(),
            RC_SIGN_IN);
}

public void signInWithPhone() {
    startActivityForResult(
            AuthUI.getInstance().
                    createSignInIntentBuilder().
                    setAvailableProviders(Collections.singletonList(new AuthUI.IdpConfig.PhoneBuilder().build())).
                    build(),
            RC_PHONE_SIGN_IN);
}

public void signInWithEmail() {
    startActivityForResult(
            AuthUI.getInstance().
                    createSignInIntentBuilder().
                    setAvailableProviders(Arrays.asList(
                            new AuthUI.IdpConfig.GoogleBuilder().build(),
                            new AuthUI.IdpConfig.EmailBuilder().build())).
                    build(),
            RC_EMAIL_SIGN_IN);
}

When the user is already signed in, and he tries to sign in with a phone number by calling signInWithPhone(), the FirebaseUI is replacing the previously signed in credentials. So I am not able to link accounts.

我错过了什么吗?

FirebaseUI 处理自动帐户 linking(当启用每个电子邮件一个帐户时)。这包括以下类似情况:

  • 用户在一台设备上使用 Google 注册。
  • 用户尝试使用同一 Google 电子邮件在另一台设备上或注销后使用 Facebook 登录同一应用程序。
  • 通常这会抛出一个错误,表明需要 linking,因为已经存在使用相同电子邮件地址的经过验证的帐户。
  • 为了恢复,FirebaseUI 要求用户使用 Google 登录现有帐户,然后 link 向其提供 Facebook 凭据。下次用户尝试登录时,他们可以使用他们的 Google 或 Facebook 帐户。

FirebaseUI 将支持上述情况,但不支持手动 linking,因为您想要向登录用户发送 link 一个 phone 号码.欢迎在 FirebaseUI 存储库中提交功能请求。