我尝试使用 Azure AD B2C 和 MSAL 使用用户名和密码登录。登录后,我们使用 Web API 验证访问 token ,该 API 返回资源 token ,获取它后,我们使用资源 token 连接 DocumentClient,如下所述,但是当我们尝试在 Cosmos DB 中执行诸如 savedocument 之类的操作时,面临以下错误
var Client = new DocumentClient(new System.Uri(App.accURL), resourceToken);
消息:
{"Errors": ["Authorization Token doesn't present sufficient permissions to serve the request."]}
ActivityId: 3360415e-b937-4061-b74d-485d44550df2,
Request URI: /apps/7dc938ac-8c47-4af3-9760-5e80284624b0/services/4344f786-4b9a-4293-ab0a-d27a5ccae76a/partitions/26b66fff-1ad2-47dc-90c8-cc9ee7b0d23b/replicas/131448621059935679p: Error: ...
最佳答案
when we try to perform the action like savedocument in cosmosDB, facing following error. Authorization Token doesn't present sufficient permissions to serve the request.
据我所知,我们只能将一个权限与用户的特定资源关联起来。并且权限模式只有两种:全部(读、写、删除权限)或读。如果您为用户指定的配置正确,我建议您检查 permissionMode
、ResourceLink
、ResourceTokenExpirySeconds
。
你可以List Permissions for a user并使用DocumentClient.ReadPermissionFeedAsync用于检索用户的权限。另外,您可以引用相关教程Permissions in Azure DocumentDB和 Cosmos DB > Permissions .
如果您仍然无法找到此问题,请使用相关代码更新您的问题,以向您的用户授予权限并利用 fiddler使用 resourceToken
token 访问资源时收集网络跟踪。
关于azure - 访问 Cosmos DB 文档的授权 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45525096/