Skip to content

CORS issue when accessing shared DriveItems content #388

@snebjorn

Description

@snebjorn

Bug Report

Prerequisites

  • Can you reproduce the problem?
  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

Requests to

GET /shares/{shareIdOrUrl}/driveItem/content

https://docs.microsoft.com/en-us/graph/api/shares-get?view=graph-rest-1.0&tabs=http

Will result in a redirect that will fail with a CORS error

this.graphClient.api(`/shares/${encodeShareableLink}/driveItem/content`).get();

This is the error:

Access to fetch at 'https://{my org}.sharepoint.com/sites/{my site}/_layouts/15/download.aspx?UniqueId={guid}&Translate=false&tempauth={token}&ApiVersion=2.0'
(redirected from 'https://graph.microsoft.com/v1.0/shares/{encoded shareable link}/driveItem/content')
from origin 'https://localhost:5001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Steps to Reproduce

  1. Call GET /shares/{shareIdOrUrl}/driveItem/content from javscript
  2. Watch CORS

Expected behavior:
I expected to be able to either intercept the location header or download the file.

Actual behavior:
A CORS error was thrown

Additional Context

Add any other context about the problem here..

Usage Information

Request ID - Value of the requestId field if you are receiving a Graph API error response

SDK Version - [SDK version you are using]
"@microsoft/microsoft-graph-client": "^2.2.1"

  • Node (Check, if using Node version of SDK)

Node Version - [The version of Node you are using]

  • Browser (Check, if using Browser version of SDK)

Browser Name - [The name of Browser that you are using for SDK]
Chrome

Version - [The version of the browser you are using]
88.0.4324.104
AB#7930

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions