Access a Shared OneDrive for Business Folder with the JavaScript API
Question details
The user wants to retrieve files from a publicly shared OneDrive for Business folder using a JavaScript API.

- Product
- OneDrive for Business and Microsoft Graph API
- Device & OS
- not provided
- Scenario
- A read-only folder is shared through a link that anyone can open in a browser.
- Observed behavior
- The folder opens anonymously in a browser, but a request to a SharePoint or OneDrive API endpoint returns an unauthenticated error.
Confirm that you have the complete sharing link and identify whether you can register an application in the folder owner's Microsoft Entra tenant. A working anonymous browser link does not by itself provide an API access token.
Authenticate a Microsoft Graph request to the shared folder
Use this approach when you can register an application and obtain permissions to access the folder.
OneDrive for Business is backed by SharePoint Online. An anonymous sharing page and a Microsoft Graph or SharePoint API endpoint can have different authentication requirements.
A sharing link alone is not a substitute for an access token. The signed-in user or application must also have the required access, and tenant policies can restrict shared-link access.
In the Microsoft Entra admin center, open Identity > Applications > App registrations and select New registration. Configure a redirect URI for your JavaScript application.
In the app registration, open API permissions > Add a permission > Microsoft Graph. Select the delegated permissions appropriate for shared files, such as Files.Read.Shared, and obtain any required consent.
Use the Microsoft Authentication Library for JavaScript (MSAL.js) to sign in a user who can access the folder and request a Microsoft Graph access token for the configured scopes.
Convert the sharing URL to a Graph sharing token: UTF-8 encode it, apply URL-safe Base64 encoding without padding, and prefix it with u!. Send a GET request to https://graph.microsoft.com/v1.0/shares/{sharing-token}/driveItem/children with the access token in the Authorization: Bearer header.

Use the sharing link in a browser or an anonymous file service
Use this option if you only have the public link and cannot obtain an API token.
Work with downloaded Office files in WPS Office
WPS Office is a free, lightweight alternative for opening and editing Office files after you download them from a shared folder. Its familiar interface and format compatibility make it easy to move between office suites; it does not resolve OneDrive API authentication.

Frequently Asked Questions
Why does the folder open in a browser but fail through the API?
The anonymous sharing page and the API endpoint have different access requirements. Microsoft Graph requests generally require an access token even when a sharing link opens without a browser sign-in.
Can I call Microsoft Graph with only the public folder link?
A sharing link can identify the shared item, but it does not replace a Graph access token. If you cannot register an app or obtain a token, use the link in a browser or ask the owner for a supported anonymous endpoint.
Can my JavaScript app access the folder without a user signing in?
App-only access is possible when an administrator grants the application appropriate permissions. Use a secure backend to obtain and use the app-only token; do not expose a client secret in browser code.
Where do I configure permissions for the registered app?
In the Microsoft Entra admin center, open Identity > Applications > App registrations, select the app, and then open API permissions > Add a permission > Microsoft Graph. Choose permissions appropriate to delegated or app-only access and obtain required consent.




