Cross tenant graph API access

Ameya Nayak 20 Reputation points
2024-08-16T14:58:07.5433333+00:00

I have a tenant A and tenant B.

I have a user A in tenant. Is it possible to access file shared with User A from tenant B via delegated permission anyhow.

If yes, provide how to do so.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,771 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Yakun Huang-MSFT 3,765 Reputation points Microsoft Vendor
    2024-08-19T07:18:18.43+00:00

    Hi @Ameya Nayak

    You can get the details of external shared files through the /sharedWithMe endpoint, but unfortunately /drives/{driveId}/items/{itemId} can only be used to get files in this tenant, not external tenant shared files.

    See this link for more details:

    https://learn.microsoft.com/en-us/graph/api/drive-sharedwithme?view=graph-rest-1.0&tabs=http

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments

  2. Hitesh Pachipulusu - MSFT 1,175 Reputation points Microsoft Vendor
    2024-08-19T07:44:37.2766667+00:00

    Hello Ameya Nayak,

    Thank you for contacting support!

    Yes, it is possible to access a file shared with User A in Tenant A from Tenant B via delegated permissions using Microsoft Graph API. Here are the steps to achieve this:

    1. Share the File:
      • User B in Tenant B needs to share the file with the user in Tenant A.
    2. Obtain Necessary Permissions:
      • Ensure that the application accessing the file has the required delegated permissions. These permissions might include Files.Read, Files.Read.All, Sites.Read.All, etc.
    3. Access the Shared File:
      • Use the Microsoft Graph API to access the shared file. Here is an example of how to do this:
         GET https://graph.microsoft.com/v1.0/me/drive/sharedWithMe?allowexternal=true
      
      This request retrieves the list of items shared with the authenticated user, including those from external tenants.

    image (4)

    image (6)

    By following these steps, you should be able to access the file shared with User A in Tenant A from Tenant B using delegated permissions. https://learn.microsoft.com/en-us/graph/api/drive-sharedwithme?view=graph-rest-1.0&tabs=http#response

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.