简体   繁体   English

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

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

I have set up a real time firebase database that will be used to store some information for a University project.我已经建立了一个实时 firebase 数据库,用于存储大学项目的一些信息。 So only trivial data will be stored with no sensitive information.因此,只会存储琐碎的数据,而不会存储敏感信息。 I would like to create a c# application that can login using the built in firebase authentication.我想创建一个 c# 应用程序,它可以使用内置的 firebase 身份验证登录。

I have successfully connected my c# and firebase together using the following code我已经使用以下代码成功地将我的 c# 和 firebase 连接在一起

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

    IFirebaseClient client; 

And i now wish to be able to add new users to the firebase as well as let them log in. I noticed IFirebaseClient has the我现在希望能够将新用户添加到 firebase 并让他们登录。我注意到 IFirebaseClient 有

CreateUser(string email , String passwword) 

but i am unsure on how to use them since when i simply tried adding a user on a button click I get the following error.但我不确定如何使用它们,因为当我只是尝试在按钮单击上添加用户时,我收到以下错误。

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>

I am unsure whether this has something to do with my settings in the firebase or with my implementation of the ciode so any links to documentation or assistance would be much appreciated.我不确定这是否与我在 firebase 中的设置或我对 ciode 的实现有关,因此非常感谢任何指向文档或帮助的链接。

In your Firebase realtime database make sure you have configured rules correctly in order to read or change data something like this: 确保在Firebase实时数据库中正确配置了规则,以便读取或更改类似以下内容的数据:

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

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

to use Firebase Authentication you can use the Admin Auth Api and you can use it in your project after you add the SDK Setup Instructions要使用 Firebase 身份验证,您可以使用管理员身份验证 Api并且您可以在添加 SDK设置说明后在您的项目中使用它

this is a sample code to add a new user:这是添加新用户的示例代码:

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.

相关问题 桌面应用程序中的 Firebase 身份验证 - Firebase authentication in desktop application 将 Firebase 电话身份验证与协程一起使用 - Use Firebase Phone Authentication with Coroutines 如何在 Firebase 中使用电子邮件和电话进行身份验证? - How to use email and phone to authentication in Firebase? Firebase Python桌面应用的认证流程 - Firebase authentication process for Python desktop application 如何在 viewModel 中使用 firebase 身份验证实例 - how to use firebase authentication instance in viewModel 我们可以使用 Firebase 身份验证并符合 GDPR 吗? - Can we use Firebase Authentication and be GDPR compliant? “此应用无权在模拟器中使用 Firebase 身份验证” - "This app is not authorized to use Firebase Authentication" in Emulator 使用 Firebase 测试实验室电话身份验证与 Firebase UI - Use Firebase Test Lab phone authentication with Firebase UI 如何将 firebase 身份验证与 Android 应用程序的 instagram 登录集成 - How to integrate firebase authentication with instagram login for android application 如何使用 c# 和使用 JSON 密钥但不使用 GOOGLE_APPLICATION_CREDENTIALS 从 Firebase 获取数据 - How to get data from Firebase using c# and using JSON key but not using GOOGLE_APPLICATION_CREDENTIALS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM