我有一个托管在云上的 API 和一个守护程序应用程序客户端,该客户端位于同一组织和同一网络上,但位于我的本地计算机上。我对设置进行了两次和三次检查,但仍然无法将它们相互连接。
因此,为了查看这个问题,我将它们分为两个子问题。
- 将守护程序应用程序连接到 Azure AD,检索 token ,然后使用该 token 访问 Microsoft Graph。 检索 token 后出错。
Failed to call the Web Api: Forbidden
Content: {
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "2646f5f8-9c25-482d-a89f-f14ca6c06cf7",
"date": "2019-07-22T01:13:30"
}
}
我用过这个Azure Document和 Sample产生上述错误。
- 使用守护程序应用程序访问 API - 所以我从未接触过,因为我始终无法通过第 1 步。
关于如何解决这个问题的任何想法。我错过了一些简单的事情吗?
最佳答案
Azure AD Graph API与 Microsoft Graph API 不同。因此有两种方法可以使其发挥作用。
1。使用 Microsoft Graph API。
您应该授予应用程序 microsoft graph api 权限。
2。使用 Azure AD Graph API。
您需要更新以下代码。
a.将范围更改为https://graph.windows.net/.default
。
b.将 api 更改为 GET https://graph.windows.net/myorganization/users?api-version=1.6
注意:
We strongly recommend that you use Microsoft Graph instead of Azure AD Graph API to access Azure Active Directory resources.
关于使用客户端凭据的 Azure AD 服务到服务调用 - 共享 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57153271/