【发布时间】:2019-09-26 00:26:28
【问题描述】:
我在 Azure 中创建了一个应用程序并将其设置为使用访问和 ID 令牌。
我想连接到不同的租户并阅读 SharePoint 网站。以下是我已请求并收到管理员同意的权限:
目前,我已经设置了 App Secret,但我确实计划稍后迁移到证书。
我有这个代码来获取访问令牌,我确实得到了一个访问令牌:
const params = new URLSearchParams();
params.append("grant_type", "client_credentials");
params.append("scope", "https://graph.microsoft.com/.default");
params.append("client_id", process.env.client_id);
params.append("client_secret", process.env.client_secret);
var url = `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`;
const response = await fetch(url,
{
method: 'POST',
body: params,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}
);
但是当我尝试阅读下面的根站点时
var url = "https://graph.microsoft.com/v1.0/sites?search=*";
const response = await fetch(url,
{
method: 'GET',
headers: { 'Authorization': `Bearer ${access_token}` }
}
);
我收到此错误:
error: {
code: 'AccessDenied',
message: 'Either scp or roles claim need to be present in the token.',
innerError: {
'request-id': 'ec47913f-2624-4d1c-9b27-5baf05ccebfd',
date: '2019-08-16T14: 15: 37'
}
}
我检查了https://jwt.io/ 的令牌,实际上我没有看到roles 或scp 的任何条目。
看起来我错过了一步,但我不知道是哪一步。
我得到这样的令牌:
https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token
我做错了什么?
【问题讨论】:
标签: microsoft-graph-api sharepoint-online