我尝试了来自不同文章的两个不同API,如下所示。
API 1**
的数据
此API正在工作,令牌正在生成。
然后在API的下一部分中,我使用生成的令牌来获取数据:
的
但它也给出了以下错误,如屏幕截图所示。
{
"error": {
"code": "AuthorizationFailed",
"message": "The client '**************' with object id '**************' does not have authorization to perform action 'Microsoft.Web/sites/read' over scope '/subscriptions/**************' or the scope is invalid. If access was recently granted, please refresh your credentials."
}
}
字符串
API 2**
的
但是在这个API中,甚至没有生成令牌,并给出以下错误
{
"error": "invalid_request",
"error_description": "AADSTS901002: The 'resource' request parameter is not supported. Trace ID: ************ Correlation ID: ************ Timestamp: 2023-12-28 07:17:52Z",
"error_codes": [
901002
],
"timestamp": "2023-12-28 07:17:52Z",
"trace_id": "************",
"correlation_id": "************"
}
型
我搜索了但找不到解决方案。我想通过Rest API从Azure Active Directory获取数据。但这似乎不起作用。
1条答案
按热度按时间ie3xauqp1#
我创建了一个Azure AD应用程序并授予了API权限,如下所示:
x1c 0d1x的数据
我使用以下参数生成了访问令牌:
字符串
的
使用上面生成的访问令牌,我尝试调用API,得到相同的错误:
型
的
如果Azure AD应用程序没有访问API所需的权限/角色,则通常会发生此错误。
若要解决此错误,请确保为Azure AD应用程序分配
Reader
角色,如下所示:现在重新生成token,就可以成功调用API了:
要生成访问令牌以调用Microsoft Graph API,请将**
https://graph.microsoft.com
**作为资源传递。型
https://management.azure.com
和https://graph.microsoft.com
。https://management.azure.com/.default
和https://graph.microsoft.com/.default
传递。