我在Azure中创建了一个应用程序,并设置其使用访问令牌和ID令牌。
我希望能够连接到不同的租户并读取SharePoint站点。以下是我请求并已获得管理员同意的权限:
然而,当我尝试读取以下根站点时
我遇到了这个错误:
我做错了什么?
目前,我已经设置了一个应用程序秘钥,但是我计划以后转移到证书。
我有这段代码来获取访问令牌,我确实得到了一个访问令牌:
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
我做错了什么?