CosmosDB 授予对多个资源的权限?

CosmosDB grant permission to multiple resources?

我正在尝试了解如何使用 DocumentDB 向多个资源授予权限。我不清楚我将如何解决这个问题,或者目前是否可行。

https://docs.microsoft.com/en-us/azure/cosmos-db/mobile-apps-with-xamarin

他们在此处的文档中声明

If you want two users to have access to the same to-do list, you can add additional permissions to the access token in Resource Token Broker.

资源令牌代理链接如下:

https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/xamarin/UserItems/ResourceTokenBroker/ResourceTokenBroker/Controllers/ResourceTokenController.cs#L153-L159

而且我认为他们的具体意思是:

using Microsoft.Azure.Documents;

Permission p = new Permission
{
    PermissionMode =  PermissionMode.All,
    ResourceLink = collection.SelfLink,
    ResourcePartitionKey = new PartitionKey(userId),
    Id = permissionId //needs to be unique for a given user
};

但是,此代码段仅支持一个分区键。这就是我想要做的,为集合中的多个分区键授予权限。

这是我假设创建令牌的调用:

permission = await Client.CreatePermissionAsync(UriFactory.CreateUserUri(databaseId, userId), p);

但同样,它看起来像是一个单独的许可。这意味着您必须创建 N 个权限,并且每次您访问其中一个资源时,您都需要从 Resource Broker 请求令牌?换句话说,如果我授予 5 个资源的权限,当我的客户端转到 Resource Broker 时,我需要 return 5 个令牌?

没有办法说:此资源令牌授予对所有这些资源的 PermissionMode.All 权限吗?

if I grant permission to 5 resources, when my client goes to the Resource Broker, I need to return 5 tokens?

DocumentClient class 有四个构造函数,其中两个构造函数支持提供多个资源密钥,从而允许使用生成的 DocumentClient 对象来验证针对多个资源的操作。您可以在 Resource Token Broker API 和 return 权限对象列表(而不是单个资源令牌)中向客户端应用程序授予用户对多个资源的权限。

FeedResponse<Permission> permFeed = await client.ReadPermissionFeedAsync(UriFactory.CreateUserUri("dbid", " userId")); 

List<Permission> permList = permFeed.ToList();

客户端应用程序可以初始化 DocumentClient 实例 class 并在客户端应用程序获取后传递 permList

var client = new DocumentClient(new Uri(EndpointUri), permList);