简体   繁体   English

Microsoft Graph Api:权限不足,无法完成操作

[英]Microsoft Graph Api : Insufficient privileges to complete the operation

I'm trying to download files from OneDrive using the Microsoft Graph. 我正在尝试使用Microsoft Graph从OneDrive下载文件。 I'm currently in the testing phase and have not yet written any code. 我目前处于测试阶段,还没有编写任何代码。

Here is what I did so far: 这是我到目前为止所做的:

  1. Created and registered an app through https://apps.dev.microsoft.com 通过https://apps.dev.microsoft.com创建并注册了应用
  2. Generated a secret, enabled implicit flow 生成一个秘密的,启用的隐式流
  3. Provided it with the following list of Microsoft Graph Permissions: 为它提供了以下Microsoft Graph权限列表:

    Delegated : Files.ReadWrite.All , offline_access , Group.ReadWrite.All , Directory.ReadWriteAll , User.ReadWriteAll 委派Files.ReadWrite.Alloffline_accessGroup.ReadWrite.AllDirectory.ReadWriteAllUser.ReadWriteAll

    Application : Directory.ReadWrite.All , Files.ReadWrite.All , Group.ReadWrite.All , User.ReadWrite.All 应用程序Directory.ReadWrite.AllFiles.ReadWrite.AllGroup.ReadWrite.AllUser.ReadWrite.All

    1. Used the code flow with a scope of offline_access and Files.ReadWrite.All , got a code and then a token. 使用范围为offline_accessFiles.ReadWrite.Allcode流, Files.ReadWrite.All代码,然后获得令牌。

    2. Using this token to download a file via /me drive works well ( /v1.0/me/drive/items/itemid/content ), but when I try to download or just query other users I get back the error of insufficient privileges. 使用此令牌通过/me驱动器下载文件效果很好( /v1.0/me/drive/items/itemid/content ),但是当我尝试下载或仅查询其他用户时,我会得到特权不足的错误。

Calling https://graph.microsoft.com/v1.0/users gets the response: 调用https://graph.microsoft.com/v1.0/users可获得响应:

{
  "error": {
    "code": "Authorization_RequestDenied",
    "message": "Insufficient privileges to complete the operation.",
    "innerError": {
      "request-id": "cee06586-12af-4768-9135-b9709d7ecb5d",
      "date": "2018-05-29T14:45:48"
    }
  }
}

The same happens when I add a user Id. 添加用户ID时也会发生同样的情况。 When I ask to get the user's device I get a "not found" response. 当我要求获取用户的设备时,会收到“未找到”响应。

I saw some answers to similar questions saying that I should add permissions to my app to Azure Active Directory via the Azure portal, but my app is listed only in the "Enterprise application" section and I don't see it on the "app registrations" section where I can add permissions, in the Enterprise applications section I'm unable to add any permissions, only search. 我看到了类似问题的一些答案,这些回答说我应该通过Azure门户向我的应用程序添加权限到Azure Active Directory,但是我的应用程序仅在“企业应用程序”部分中列出,而在“应用程序注册”中则看不到它。我可以在其中添加权限的部分,在企业应用程序部分中,我无法添加任何权限,只能搜索。

Note: my user id is the global admin in the Azure portal. 注意:我的用户ID是Azure门户中的全局管理员。 This user also is the user that created and owns the application. 该用户也是创建并拥有该应用程序的用户。

Any idea what I may be missing here? 知道我在这里可能会缺少什么吗?

Thanks 谢谢

Edit : 编辑

I was able to make some progress, I tried to create the app via the Azure portal and not the applications portal. 我取得了一些进展,我尝试通过Azure门户而非应用程序门户创建应用程序。 Now it shows in the app registration page so I was able to add permissions to it. 现在它显示在应用程序注册页面中,因此我可以为其添加权限。

So now I'm able to view all the users, but still, when I try to view their drive I get the "not found" response: 因此,现在我可以查看所有用户,但是当我尝试查看他们的驱动器时,仍然收到“未找到”响应:

Calling https://graph.microsoft.com/v1.0/users/userid/drive returns the response: 调用https://graph.microsoft.com/v1.0/users/userid/drive返回响应:

{
  "error": {
    "code": "itemNotFound",
    "message": "The resource could not be found.",
    "innerError": {
      "request-id": "ec6ed197-15ea-498a-80d0-e2a9f832a0b9",
      "date": "2018-05-29T15:49:18"
    }
  }
}

Calling /users requires you have at least User.ReadBasic.All or User.Read.All permissions. 调用/users要求您至少具有User.ReadBasic.AllUser.Read.All权限。 Since you've only requested Files.ReadWrite.All , you do not have sufficient access to via other user's profiles. 由于只请求了Files.ReadWrite.All ,因此您没有足够的访问权限,无法通过其他用户的配置文件进行访问。

Try against using the scope: 尝试使用范围:

User.Read.All+Files.ReadWrite.All+offline_access

OK I managed to resolve this by asking the token without a user : https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service . 确定,我设法通过在没有用户的情况下询问令牌来解决此问题: https : //developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service It how has all the required privileges and I'm able to download any file that I need. 它具有所有必需的特权,并且能够下载所需的任何文件。 Thanks to Marc and Juunas for helping me with this. 感谢Marc和Juunas为我提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM