【问题标题】:Xamarin.Forms Firebase User Authentication 401 unauthorized errorXamarin.Forms Firebase 用户身份验证 401 未经授权的错误
【发布时间】:2017-05-25 09:00:16
【问题描述】:

我正在尝试在 Xamarin.Forms 中使用 Firebase。我正在使用this library by Ricardo。到目前为止,我能够在没有身份验证的情况下获取、放置、发布数据。还能够随着数据的变化实时获取事件。但我坚持使用身份验证发布数据。

这是我的代码:

            var firebase = new FirebaseClient("https://XXXXXX-bdded.firebaseio.com/test");
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaxxxxxxxxxxxxxxXE"));
            var auth = await authProvider.SignInWithEmailAndPasswordAsync("pal@gmail.com", "abc@1234");
            var item =await firebase
              .Child("MyMeetings")
              .WithAuth(auth.FirebaseToken) 
              .PostAsync("Please Post me");

数据库规则是:

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

它抛出 401 未经授权的错误。我可以尝试什么来解决这个问题?

【问题讨论】:

    标签: firebase firebase-realtime-database xamarin.forms firebase-authentication http-status-code-401


    【解决方案1】:

    我忘了在那个 git 库的问题中看到它提到了there

    只需像这样将 false 作为第二个参数传递给 PostAsync() - var item = await FirebaseClient .Child("someTable") .WithAuth(Auth.FirebaseToken) .PostAsync(someObject, false);

    【讨论】:

      猜你喜欢
      • 2018-07-09
      • 2013-08-09
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 2013-02-06
      • 2016-04-15
      • 2018-01-23
      相关资源
      最近更新 更多