【问题标题】:FireBase Authentication with Xamarin使用 Xamarin 进行 FireBase 身份验证
【发布时间】:2018-06-13 20:06:25
【问题描述】:

在正在开发的 Xamarin Forms 应用程序中遇到 Firebase 身份验证问题。尝试使用以下方式登录时:

界面:

public interface IFirebaseAuthenticator
{
    Task<string> LoginWithEmailPassword(string email, string password);
}

类:

public class FirebaseAuthenticator : IFirebaseAuthenticator
{ 
    public async Task<string> LoginWithEmailPassword(string email, string password)
    {

            IAuthResult user = await FirebaseAuth.Instance.SignInWithEmailAndPasswordAsync(email, password);
            var token = await user.User.GetIdTokenAsync(false);
            return token.Token;

该函数在应用程序的 MainActivity.cs 文件中被调用。我们确实安装并引用了 Xamarin.Firebase.Auth Nuget 包。

没有返回任何内容,错误文档也没有任何帮助。我们的团队几乎浏览了我们可以在网上找到的所有信息,并在不得已的情况下才在此处发布。

感谢您的帮助。

【问题讨论】:

  • 当你说什么都不返回。你的意思是用户为空?

标签: c# firebase xamarin xamarin.forms firebase-authentication


【解决方案1】:

几个想法:

1) 您在 Firebase 上启用了哪些登录提供商?您需要激活电子邮件/密码组合(可在“开发”>“身份验证”>“登录方法”下找到)。

2) 您如何初始化 FirebaseAuth 实例?这是一个适合我的示例:

FirebaseOptions options = new FirebaseOptions.Builder()
    .SetApiKey("your-api-key")
    .SetApplicationId("your-application-id")
    .Build();

// declared in the Activity class, ergo 'this' references the Activity's context
FirebaseApp app = FirebaseApp.InitializeApp(this, options);

FirebaseAuth authInstance = FirebaseAuth.GetInstance(app);

// Now you can use authInstance.SignInWith...(etc.)

【讨论】:

    猜你喜欢
    • 2017-11-20
    • 2020-10-09
    • 2017-03-11
    • 2020-06-26
    • 2018-10-19
    • 2021-05-26
    • 2017-09-12
    • 2021-07-20
    • 2017-11-03
    相关资源
    最近更新 更多