Search code examples
c#onedriveazure-ad-graph-api

How to get the file shared persons details from OneDrive using graph API


I'm trying to read the permission details and the persons whom the file being shared in OneDrive. While checking the permission I get only the Manage Accessed persons details as "GrantedTo:" the rest showing like this.

{
  "id": "89sd809e-a6fe-47cf-a563-d21fgac9fa3",
  "roles": [
    "read"
  ],
  "link": {
    "scope": "users",
    "type": "view",
    "webUrl": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  }
},

How can I get those persons details ? Why the API returns grantedTo only for the managed access persons ?

The code that I tried :

var permissionss = await graphClient.Me.Drive.Items["itemID"].Permissions
                        .Request(requestOptions)
                        .WithUserAccount(ClaimsPrincipal.Current.ToGraphUserAccount())
                        .GetAsync();

Please help me to find a solution.

Thanks in advance


Solution

  • Only the explicit permission for a user can be listed with person details.

    What is "explicit permission"? You can give this kind of permission like this:

    enter image description here

    enter image description here

    After granting access like this, the person details will be shown via /permissions endpoint.

    If you use other methods to share this file like this:

    enter image description here

    It actually just generates a sharing link. There is no specific audience who has been shared with this file. People who have access to this file will be able to access it via this sharing link.

    So you can only get a sharing link "webUrl": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" in the response.

    It is by-design of this Graph endpoint.