基本请求Xamarin表单上的FireStore权限被拒绝 [英] FireStore permission denied on basic requests Xamarin Forms

查看:32
本文介绍了基本请求Xamarin表单上的FireStore权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来我一直在努力解决这个问题,但是我没有取得太大的进步,我们将不胜感激.我是FireStore的新手,但真的很喜欢它提供的功能.我已成功使用Plugin.CloudFirestore和Xamarin.Forms从Android和iOS应用程序获取基本文档.

I have been struggling with this problem for a few days now and I am not making much progress, any help would be appreciated. I am new to FireStore but really like the possibilities it offers. I have successfully managed to get basic documents from Android and iOS apps using Plugin.CloudFirestore and Xamarin.Forms.

但是,我需要一些后端服务,例如数据设置等,并且需要能够通过常规的旧C#桌面应用程序连接到FireStore.因此,我遵循了快速入门指南Nuget的Google.Cloud.Firestore,设置了环境变量,无论我如何尝试代码,我都会得到"PERMISSION_DENIED:权限丢失或不足".

However I need some back-end services, things like data set-up etc and need to be able to connect to FireStore via regular old C# desktop app. So I followed the quick start guide, Nuget'ed Google.Cloud.Firestore, set the environment variable and no matter how I try the code I get "PERMISSION_DENIED: Missing or insufficient permissions."

一些详细信息,我正在使用一个具有项目所有者"权限的服务帐户,并且尚未更改默认访问规则.我知道正确设置了环境变量并找到了文件.所有软件包都是最新的.令人沮丧的是我的iOS/Android应用程序正在运行,但这不是,我预计移动应用程序会出现更多问题.由于我仍在探索所有这些内容,因此只是在单元测试中,因此我可以很快地执行和更改代码.

Some details, I am using a service account set with Project Owner permissions and have not changed the default access rules yet. I know the environment variable is set-up correctly and the file is found. All packages are most recent. Frustrating that my iOS/Android apps are working, but this is not, I expected more issues with the mobile apps. As I am still exploring all this is just in a unit test so I can execute and change the code pretty quickly.

在我开始将头撞在桌子上之前,将非常感谢您的帮助:-)

Help would be really appreciated before I start banging my head on the desk :-)

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        Task<string> task = Task.Run<string>(async () => await GetUserName());
        var x = task.Result;
        return ;

    }

    private async Task<string> GetUserName()
    {
        string projectId = "matchesJson";
        FirestoreDb db = FirestoreDb.Create(projectId);
        string retVal = "";

        try
        {
            CollectionReference col = db.Collection("users");
            // Exception thrown on next line
            QuerySnapshot snapshot = await col.GetSnapshotAsync();
            // get some data
            retVal = "";
        }
        catch (Exception e)
        {
            retVal =  e.Message;
        }
        return retVal;
    }

}

----编辑添加规则--------今天是2020年3月3日-

---- EDIT ADDING RULE ------- -- Today is March 3nd 2020 --

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2020, 3, 28);
    }
  }
}

推荐答案

我发现了问题.文档中的内容不是很清楚,但是在使用服务帐户时,您需要单独向该帐户添加权限.可以在Google控制台中通过搜索身份并应用正确的权限来完成此操作.现在,我仅为此POC授予了项目所有者",但可能会有更细化的权限.

I found the issue. It is not very clear in the documentation, but when using a service account you need to add the permission to the account separately. This can be done in the google console by searching for the identity and applying the correct permission. For now I granted 'project owner' just for this POC, but there is probably a more granular permission.

感谢阅读,并感谢您对"ralemos"的评论.

Thanks for reading and thanks for the comments 'ralemos'.

这篇关于基本请求Xamarin表单上的FireStore权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆