Permission & Access Issues

Access a Shared OneDrive for Business Folder with the JavaScript API

Natalie TaylorNatalie Taylor Nov 14, 2026 868 views

Question details

The user wants to retrieve files from a publicly shared OneDrive for Business folder using a JavaScript API.

Access a Shared OneDrive for Business Folder with the 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.
Before you start

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.

Solution 1Recommended

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.

1
Register an application

In the Microsoft Entra admin center, open Identity > Applications > App registrations and select New registration. Configure a redirect URI for your JavaScript application.

2
Configure Graph permissions

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.

3
Sign in and get a token

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.

4
Request the folder contents

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.

Authenticate a Microsoft Graph request to the shared folder
Using an application without a signed-in user: App-only access still requires an app registration, application permissions, and administrator consent where required. Acquire app-only tokens on a secure backend; do not put a client secret in browser JavaScript.
Free Microsoft Office alternative

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.

Open supported files downloaded from a shared OneDrive folderCompatible with Microsoft Office formats such as DOCX, XLSX, and PPTXUse a familiar interface for documents, spreadsheets, and presentationsMove existing Office files into a lightweight, easy-to-use suite
microsoft office alternative - wps office

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.