Fix CORS Errors When Microsoft Graph Accesses SharePoint Files
Question details
The user needs to resolve a CORS (Cross-Origin Resource Sharing) error occurring when a web application attempts to fetch SharePoint documents via the Microsoft Graph API.

- Product
- Microsoft Graph API and SharePoint
- Device & OS
- not provided
- Scenario
- A web application authenticates through single sign-on to obtain an access token, then uses it to request SharePoint documents from Microsoft Graph.
- Observed behavior
- The Microsoft Graph requests fail with a CORS error because the Access-Control-Allow-Origin header is missing in the response.
Ensure you have administrative access to your Microsoft Entra ID (Azure AD) application registration and a clear understanding of your application's current authentication flow.
Route Microsoft Graph Requests Through a Trusted Backend
The most secure and reliable way to avoid browser CORS issues is to handle Graph API calls on a backend server rather than directly in client-side browser code.
Directly calling Microsoft Graph from a browser using single-page applications (SPAs) can trigger CORS errors if origins are misaligned or if specific Graph endpoints do not natively support cross-origin requests. By acting as a proxy, your backend server can securely hold secrets, handle tokens, and completely bypass browser CORS limitations.
Configure your front-end web application to send data requests to your own backend API endpoints instead of calling Microsoft Graph directly.
On your backend server, implement an appropriate authentication flow (such as the On-Behalf-Of flow or Client Credentials) to acquire a valid Microsoft Graph access token.
Make the HTTP GET or POST request to the Microsoft Graph SharePoint endpoint (e.g., https://graph.microsoft.com/v1.0/sites/) from your backend server environment.
Receive the response on your server and forward the fetched SharePoint documents or JSON data back to your client-side application.

Verify Azure AD App Registration and Redirect URIs
If you must call Graph directly from the browser (e.g., using MSAL.js), ensure your application's origin is explicitly authorized in Microsoft Entra ID.
Consult Microsoft Q&A for Complex Architecture Issues
Persistent CORS issues on specific SharePoint API endpoints often require deeper investigation into tenant-specific conditional access policies by Microsoft specialists.
Looking for a Reliable and Free Office Suite? Try WPS Office
While managing complex developer APIs and CORS errors in SharePoint can be highly technical, handling your everyday office documents shouldn't be. WPS Office offers a lightweight, completely free alternative to Microsoft Office. Enjoy a familiar interface and seamless document management without the heavy enterprise overhead.
- 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
- 2. Install the application: Run the downloaded installer and follow the on-screen prompts to set up WPS Office on your device.
- 3. Open your documents: Launch WPS Office to easily open, edit, and save your existing Microsoft Office files with perfect formatting.

Frequently Asked Questions
Why am I getting a CORS error only on specific Microsoft Graph endpoints?
Not all Microsoft Graph endpoints natively support CORS for cross-origin browser requests. While many general directory and mail endpoints do, certain specific SharePoint or legacy endpoints may lack the Access-Control-Allow-Origin header. In these cases, routing your request through a backend proxy server is required.
Can I fix CORS errors by changing my SharePoint site settings?
Generally, no. Microsoft Graph CORS headers are managed by the Microsoft Graph API infrastructure, not by individual SharePoint site administrators. The solution relies on correctly registering your application in Azure AD or using a server-side backend to make the API calls.
Does MSAL.js handle CORS automatically?
MSAL.js securely handles the authentication flow and acquires tokens across origins, but it does not prevent CORS errors on the actual resource APIs (like Microsoft Graph) if the endpoint itself rejects cross-origin requests or if the application's origin isn't properly registered.
What does the 'missing Access-Control-Allow-Origin header' error mean?
This error means the destination server (Microsoft Graph) did not return an HTTP header explicitly telling your browser that it is allowed to read the response. Modern browsers block these responses by default to protect user data from unauthorized scripts running on untrusted domains.




