【发布时间】:2020-04-27 01:05:43
【问题描述】:
我无法访问 Microsoft graph 中的端点。
当我设置好通信后,我会将文件上传到用户的一个驱动器 但现在我只是想获取驱动器中的项目列表。
这是我从https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children 得到的回复
{
"error": {
"code": "AccessDenied",
"message": "Either scp or roles claim need to be present in the token.",
"innerError": {
"request-id": "123",
"date": "2020-01-09T11:43:20"
}
}
}
我在端点 https://graph.microsoft.com/v1.0/me/ 上使用图形资源管理器检索了 drive_id 在已登录的用户上。
需要注意的是我可以使用这个端点https://graph.microsoft.com/v1.0/subscriptions 所以我必须用访问令牌做一些正确的事情。
我按照this 教程使用客户端凭据流获取访问令牌。
这是我用来获取访问令牌的代码
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-
form-urlencoded"));
var req = new HttpRequestMessage(HttpMethod.Post, $"https://login.microsoftonline.com/<tenant>/oauth2/token");
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"grant_type", "client_credentials"},
{"client_id", "123"},
{"client_secret", "123"},
{"resource", "https://graph.microsoft.com"}
});
当我解码 JWT 时,我在令牌中看不到任何范围,但如果我理解正确的话 header 应该得到管理员允许的范围。
管理员已为我的应用授予图表浏览器的以下权限: (虽然我没有委托权限,但这有关系吗?)
Filse.Read,
Files.ReadWriteAll,
Sites.ReadWtiteAll,
User.Read
我在邮递员中使用this集合进行测试。
提前感谢任何建议。
【问题讨论】: