Anonymously read and upload to publicly shared OneDrive folder using MS Graph API

Romas Markovcinas 10 Reputation points
2023-04-03T13:53:10.4633333+00:00

Hello MS Team,

I am working on a web based solution that should allow reading publicly shared OneDrive folder by organizational and anonymous users using MS Graph API. I use jQuery aJax to make requests to the API.

  1. I have created publicly shared OneDrive item with anyone with link can read and edit permissions. I can access and upload files to this link without logging in.
  2. I am trying to access this folder through MS Graph endpoints below. If I provide access token, everything works as expected. I can read permissions with scope : "anonymous" and type : "edit". However if user is not logged in and access token is absent, the MS Graph return 401 unauthorized response for each three requests.
   GET https://graph.microsoft.com/v1.0/shares/{shareID}/driveID
   GET https://graph.microsoft.com/v1.0/drives/{driveID}/items/{itemID}
   POST https://graph.microsoft.com/v1.0/drives/{driveID}/items/{itemID}/createUploadSession
   [@odata.context] => https://graph.microsoft.com/v1.0/$metadata#permission
   [@odata.type] => #microsoft.graph.permission
   [id] => 9c697ba7-65bb-4b4e-bbc2-****
   [roles] => Array
               (
                  [0] => write
               )
   [shareId] => u!aHR0cHM6Ly9zZWFn****
   [hasPassword] => 
   [link] => Array
               (
                  [scope] => anonymous
                  [type] => edit
                  [webUrl] => https://{tenant}-my.sharepoint.com/:f:/g/personal/****/Ejj1aTBov-BFjqhJ***
                  [preventsDownload] => 
               )

How is it possible to access publicly shared OneDrive folder when user is anonymous (i.e. when accessToken is not available)?

Alternatively - is it possible to create some kind of context token, than anonymous users can use to access publicly shared folders?

Microsoft 365 and Office | OneDrive | For business | Windows
Microsoft Security | Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. Zehui Yao_MSFT 5,876 Reputation points
    2023-04-17T09:14:45.6333333+00:00

    Hi Romas Markovcinas , you can also choose to open a support case with Microsoft Graph, a backend Support Engineer will be able to assist you better. You can raise support ticket from http://aad.portal.azure.com/ or https://admin.microsoft.com/#/support/requests.

    0 comments No comments

  2. Jakob Hohlfeld 0 Reputation points
    2024-11-28T12:14:43.1233333+00:00

    So it seems you are stuck with setting up an app and authenticating your requests to sharepont items via the graph api: https://learn.microsoft.com/en-us/graph/use-the-api

    0 comments No comments

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.