简体   繁体   English

如何使用Firebase身份验证检索用于登录链接帐户的登录方法

[英]How to retrieve which login method used to login with linked accounts using Firebase authentication

If i have two linked accounts for the same UserID, lets say, Facebook and email based. 如果我有两个链接帐户使用相同的UserID,可以说基于Facebook和电子邮件。 When authenticating FireBase triggers the following: 验证FireBase时会触发以下内容:

 // Track ID token changes.
    private void IdTokenChanged(object sender, System.EventArgs eventArgs)
    {
        Firebase.Auth.FirebaseAuth senderAuth = sender as Firebase.Auth.FirebaseAuth;
        if (senderAuth == auth && senderAuth.CurrentUser != null)// && !fetchingToken)
        {
            senderAuth.CurrentUser.TokenAsync(false).ContinueWith(
              task =>
              {
                  fetchingToken = true; 
                  UserLoginDetails.provideId = new List<Firebase.Auth.IUserInfo>(senderAuth.CurrentUser.ProviderData)[0].ProviderId;
                  UserLoginDetails.userId = senderAuth.CurrentUser.UserId;
                  UserLoginDetails.name = senderAuth.CurrentUser.DisplayName;
                 //DO MORE STUFF HERE
              }
        }
    }

As you can see i can get user information, and get the Providers using ProviderData . 如您所见,我可以获取用户信息,并使用ProviderData获取提供ProviderData

Issue is that when getting main ProviderId from senderAuth.CurrentUser.ProviderId: you get "Firebase" And from ProviderData you cannot know which is the used to authenticate. 问题是,当从senderAuth.CurrentUser.ProviderId:获取主ProviderId时senderAuth.CurrentUser.ProviderId:您获得“ Firebase”,并且从ProviderData您不知道哪个用于身份验证。

This sounds to me pretty basic to have some info with whom you last logged in with in some field in the main object. 在我看来,这听起来很基础,您可以在主要对象的某个字段中找到上一次与谁登录的信息。

I don't think there's any way to find what profile the user last used to sign in from their profile. 我认为无法通过任何方式找到用户最后一次使用其个人资料登录的个人资料。

If you need this information, you'll need to capture it when the user signs in. For example from the documentation on signing in with email/password : 如果需要此信息,则需要在用户登录时捕获它。例如, 从有关使用电子邮件/密码登录的文档中

auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
  if (task.IsCanceled) {
    Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
    return;
  }
  if (task.IsFaulted) {
    Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
    return;
  }

  Firebase.Auth.FirebaseUser newUser = task.Result;
  Debug.LogFormat("User signed in successfully: {0} ({1})",
      newUser.DisplayName, newUser.UserId);

  this.SignInMethod = "Password";
});

Or if you sign in directly with Credential : 或者,如果您直接使用Credential登录:

auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
  ...
  this.SignInMethod = credential.Provider;
})

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

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