Firestore C#:权限丢失或不足

问题描述 投票:0回答:1

我目前正在使用C#浏览Firebase的Cloud Firestore,并遇到了在搜索SO后无法解决的错误。似乎C#中Firestore的资源非常有限:

"Status(StatusCode=PermissionDenied, Detail=\"Missing or insufficient permissions.\")"

我的代码到目前为止:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "FirebaseCsharpTest.json");

        string project = "MyProjectId";

        FirestoreDb db = FirestoreDb.Create(project);
        Console.WriteLine("Created Cloud Firestore client with project ID: {0}", project);

        AddPerson(db).GetAwaiter().GetResult();

    }

    public static async Task AddPerson(FirestoreDb db)
    {
        CollectionReference collection = db.Collection("users");
        DocumentReference document = await collection.AddAsync(new
        {
            Name = new
            { First = "Ada", Last = "Lovelace" },
            Born = 1815
        });
    }
}

我已在Firebase控制台上检查了Firestore安全规则是否已设置为public(截至目前为止,为了测试)。我还确保认证json文件是从Google Developer Console生成的正确文件,如此post中所建议的。

有什么我想念的吗?

编辑:我在谷歌云控制台上的权限:enter image description here

c# firebase google-cloud-firestore
1个回答
0
投票

这是云IAM问题,而不是安全规则问题。 The C# server client library creates a privileged server environment that doesn't take into account Cloud Firestore security rules.。似乎您的密钥文件的服务帐户没有正确的IAM角色,或者您的代码没有找到您的密钥文件。

尝试使用密钥文件的完整路径而不是相对路径。

您还可以尝试设置here所述的新服务帐户和密钥文件。

另外,请确保您要更改project变量:

string project = "NewFirebaseCsharpTest";

FirestoreDb db = FirestoreDb.Create(project);
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.