在正在开发的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包。
没有返回任何内容,错误文档根本没有用。我们的团队已经完成了我们可以在网上找到的几乎所有信息,并已作为最后的手段在这里发布。
感谢您的帮助。
答案 0 :(得分:0)
夫妇的想法:
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.)