簡體   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