繁体   English   中英

使用c#应用和firebase认证登录

[英]Use c# application and firebase authentication to log in

我已经建立了一个实时 firebase 数据库,用于存储大学项目的一些信息。 因此,只会存储琐碎的数据,而不会存储敏感信息。 我想创建一个 c# 应用程序,它可以使用内置的 firebase 身份验证登录。

我已经使用以下代码成功地将我的 c# 和 firebase 连接在一起

IFirebaseConfig ifc = new FirebaseConfig()
    {
        AuthSecret = "secretcode",
        BasePath = "https://mydbpath/"
    };

    IFirebaseClient client; 

我现在希望能够将新用户添加到 firebase 并让他们登录。我注意到 IFirebaseClient 有

CreateUser(string email , String passwword) 

但我不确定如何使用它们,因为当我只是尝试在按钮单击上添加用户时,我收到以下错误。

FireSharp.Exceptions.FirebaseException: Request responded with status 
code=MethodNotAllowed, response=<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>

我不确定这是否与我在 firebase 中的设置或我对 ciode 的实现有关,因此非常感谢任何指向文档或帮助的链接。

确保在Firebase实时数据库中正确配置了规则,以便读取或更改类似以下内容的数据:

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

更多信息: https : //firebase.google.com/docs/database/security

要使用 Firebase 身份验证,您可以使用管理员身份验证 Api并且您可以在添加 SDK设置说明后在您的项目中使用它

这是添加新用户的示例代码:

UserRecordArgs args = new UserRecordArgs()
{
    Email = "user@example.com",
    EmailVerified = false,
    PhoneNumber = "+11234567890",
    Password = "secretPassword",
    DisplayName = "John Doe",
    PhotoUrl = "http://www.example.com/12345678/photo.png",
    Disabled = false,
};
UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(args);
// See the UserRecord reference doc for the contents of userRecord.
Console.WriteLine($"Successfully created new user: {userRecord.Uid}");

暂无
暂无

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

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