OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
293 stars 143 forks source link

Improper handling 302 Redirects when downloading file content? #205

Closed gerarde closed 1 month ago

gerarde commented 7 years ago

I'm writing a C# web app (ASP.NET Core 1.0) which uses the OneDrive C# SDK to access a OneDrive for Business account. It has code to upload/download files using the C# SDK.

The problem is that code to download a (which has been working for months) has mysteriously stopped working.

Notes:

I know this isn't an issue with the SDK, but have no idea where I can get help from Microsoft. I do have an MSDN subscription, and am willing to use a support incident to figure this out, but nobody in the support center can seem to figure out how to route my call. I've spent hours talking to SharePoint Online/OneDrive For Business support to no avail.

Any assistance would be much appreciated... thanks!

image

gerarde commented 7 years ago

Turns out the issue may have been related to our custom IAuthenticationProvider and the fact that it was appending an Authorization header (with Bearer token) to SPO's _layouts/15/download.aspx endpoint which authenticates with a guestaccesstoken.

frankguns commented 7 years ago

Hi Gerarde,

Can you give some more details about how you solved this issue as I am facing exactly the same problem?

Thanks

E3Solutions commented 7 years ago

We are having the same issue. Do you have some example code of what you did to get it working?

Thanks

gerarde commented 7 years ago

What seems to be working for us providing an HttpProvider which specifies AllowAutoRedirect=true when initializing the OneDriveClient:

return new OneDriveClient($"https://{Settings.OneDriveTenant}-my.sharepoint.com/_api/v2.0", new AuthenticationProvider(GetAccessToken), new HttpProvider(new HttpClientHandler { AllowAutoRedirect = true }, true));

Our testing suggests it works with our particular uses of the library, but I'm not certain whether this causes any side effects.

Are other people using custom AuthenticationProviders? Because our AuthenticationProvider does the insertion of the Authorization HTTP header, I thought this might have been an issue specific to us.

E3Solutions commented 7 years ago

Works! Thank you, much appreciated!

burnsy88 commented 7 years ago

Worked for us too!! Here is the code we used:

  var adalAuthProvider = new AdalAuthenticationProvider(
                    this.AadClientId,
                    this.AadReturnUrl);

            this.oneDriveClient = new OneDriveClient(this.AadTargetUrl + "/_api/v2.0", adalAuthProvider, new HttpProvider(new HttpClientHandler { AllowAutoRedirect = true }, true));
            authTask = adalAuthProvider.AuthenticateUserAsync(this.AadTargetUrl);

            try
            {
                await authTask;
            }
gerarde commented 7 years ago

Reopening this since it looks like it's not just us -- it looks like the library (or the upstream Microsoft.Graph libs) is incompatible with a recent deployment of SPO.

Troubleshooting advice:

Question for all: Does anyone know how to find a list of updates for O365/SPO/OneDrive and when they were deployed (i.e., release notes?)? MS Tech Support was completely unhelpful in helping to troubleshoot this problem.

burnsy88 commented 7 years ago

Here's a link to the release notes for the OneDrive rollout they did on 12/7.

[https://support.office.com/en-us/article/New-OneDrive-sync-client-release-notes-845dcf18-f921-435e-bf28-4e24b95e5fc0?ui=en-US&rs=en-US&ad=US]

Shadow0ps commented 7 years ago

The notes for Graph changes are available here: https://graph.microsoft.io/en-us/changelog#

prakashguru commented 7 years ago

My application is using 1.x sdk and it is affected by this problem. I am not sure whether 2.x sdk also has the issues.

Gerard Escalante, But setting the "AllowAutoRedirect = true" may fail some other calls which requires authorization header.

baywet commented 1 month ago

Thank you for reaching out and for your patience. This SDK is being officially deprecated. See #259 for more information