Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing Special.AppRoot-Folders of other onedrive users #180

Open
DamirLisak opened this issue Oct 16, 2016 · 13 comments
Open

Accessing Special.AppRoot-Folders of other onedrive users #180

DamirLisak opened this issue Oct 16, 2016 · 13 comments

Comments

@DamirLisak
Copy link
Contributor

DamirLisak commented Oct 16, 2016

Since the change to to Graph.Core (Version 2.0.2) the access to a shared folder of another onedrive user doesn't work anymore.

I wan't to access the folder over
var request = _OneDriveClient.Drives[OneDriveID]
.Items[OneFolderRequestID]
.Request()
.Expand("children");

but the request ends in a Microsoft.Graph.Exception:
at Microsoft.Graph.HttpProvider.d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.d__321.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.ItemRequest.<GetAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at HandballReporter.shared.ViewModel.DivisionViewModel.d__53.MoveNext()

When I'm authenticated with the user who owns this shared folder, the request works without any problems.

According to the One-Drive-documentation at https://dev.onedrive.com/misc/working-with-links.htm the IDriveItemsCollectionRequestBuilder builds the correct RequestURL:
https://api.onedrive.com:443/v1.0/drives/123456789.../items/123456789...!54321

Also I'm not possible to download or upload files to a shared folder of another user in this way.

Three months ago I'have opened another issue (147) which concerns the access to shared contents also. Generally, it seems that the access to shared contents doesn't work properly.

@cdmayer : Please take some time to investigate and fixe this bugs, or can I somehow help you ?

@cdmayer
Copy link
Contributor

cdmayer commented Oct 17, 2016

I am unable to repro your issue. Using v2.0.2, I executed this query:

var expandValue = "thumbnails,children";
folder = await this.oneDriveClient.Drives[$"{userId}"].Items[$"{userId}!{itemId}"]
    .Request().Expand(expandValue).GetAsync();

That returned the expected set of files. Are you sure that you have the correct userId and itemId? Are you sure you have permissions to that item?

About #147, you are right is still outstanding. Will be fixed in the next version of the SDK, which should be out this week.

@DamirLisak
Copy link
Contributor Author

DamirLisak commented Oct 19, 2016

Yes, I'm sure that I use the correct userId and ItemId (the ItemId is a combination of the DriveID + "!" + ItemID). Also, I have permissions to the folder because I'm able to open it over the IOneDriveSharesCollectionRequestBuilder:

var request = _OneDriveClient
                                        .Shares[encodedUrl]
                                        .Items[ItemId]
                                        .Request()
                                        .Expand("children");

This Folder is a Subfolder of a WindowsUWP-Application, which I have created before with the account of User A:

// 1. Open AppRoot-Folder to get it's ItemID
var request= _OneDriveClient.Drive.**Special.AppRoot**.Request().Expand("children")
var odAppRootItem = await request.GetAsync();

// 2. Create Subfolder
var odFolderToCreate = new Item { Folder = new Folder(), Name = OneDriveFolderName };
var odDivisionFolder = await _OneDriveClient
                                      .Drive
                                      .Items[odAppRootItem.Id]
                                      .Children
                                      .Request()
                                      .AddAsync(odFolderToCreate);

// 3. Give permission to the new subfolder
var permissionResult =  _OneDriveClient.Drive
                                       .Items[odDivisionFolder.Id]
                                       .CreateLink("edit")
                                       .Request()
                                       .PostAsync()

After that I logon with the account of User B over the WebUrl which I retrieved previously with permissionResult**.Link.WebUrl**.

// 1. I resolve the WebUrl to the OneDriveID of User A with the workaround of issue #147 :+1: 
                string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(OnedriveSharingUrl));
                string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/', '_').Replace('+', '-');
                var request = _OneDriveClient.Shares[encodedUrl + "/root"].Request().Expand("children");
                var share = await request.GetAsync();
                string[] split = share.Id.Split('!');
...

// 2. I wan't to open it with the resolved OneDriveID (which is excatly the same), and this doesn't work. Also I can't up- and download files in this subfolder.

Maybe, it has something to do with the Special.AppRoot???

@DamirLisak
Copy link
Contributor Author

DamirLisak commented Oct 22, 2016

I investigated the problem and I found out that it has nothing to do with the Special.AppRoot-Folder but with the Microsoft.Graph.Core-Library.
First I thought the problem has something to do with the old Version 1.1.1 of Microsoft.Graph.Core which is referenced by the onedrive-sdk. So I forked the project from github and switched to Microsoft.Graph.Core 1.2.1. I replaced the Base-Classes BaseGetMethodRequestBuilder and BasePostMethodRequestBuilder with BaseFunctionMethodRequestBuilder, BaseActionMethodRequestBuilder because they were renamed (fyi: the dependencies-information on nuGet is wrong that the package Microsoft.OneDriveSDK supports Microsoft.Graph.Core >= 1.1.1).
After that I had the same problems, because I run into the same Exception which is Raised in the Microsoft.Graph.BaseRequest.SendAsync()-Method.
Then I created a shared folder which is directly under my Drive-Root-Folder. I logged on with the account of User B and I run into the same problem.

Then I tested to download a file from this folder with IOneDriveSharesCollectionRequestBuilder and the Pathname:

var pathRequest = _OneDriveClient
                                .Shares[encodedUrl]
                                .Root
                                .ItemWithPath(SyncXMLFilename)
                                .Content
                                .Request();
                   var odSyncXStream = await pathRequest.GetAsync();

Here I also get a Microsoft.Graph.ServiceException when the GetAsync()-method is invoked in the ItemContentRequest-Class where it invokes the SendStreamRequestAsync()-Method in line 53.

The interesting thing is that I'm able to open and download files from my Application-Folder through a Web-Browser with same Request-URL which generates the sdk-Request-Interfaces!! (https://api.onedrive.com:443/v1.0/shares/u!..encodedUrl../root:/..filename..:/content).
Also if I'm logged on with User B on the onedrive.live.com-Website, I' able to down- and upload files on the shared Folder of the Application-Folder of user A.

@cdmayer : Can you please tell me why the Microsoft.Graph.Core-Library doesn't allow this scenario?

@DamirLisak DamirLisak changed the title Accessing shared content via /drives.../items... Accessing Special.AppRoot-Folders of other onedrive users Oct 22, 2016
@DamirLisak
Copy link
Contributor Author

Hello Chris,

are the code-snippets, which I posted two days ago, enough for you, to reproduce this issue – or do you need my complete code?

-Damir

Von: Chris Mayer [mailto:notifications@github.com]
Gesendet: Montag, 17. Oktober 2016 23:31
An: OneDrive/onedrive-sdk-csharp onedrive-sdk-csharp@noreply.github.com
Cc: Damir Lisak damir.lisak@live.de; Author author@noreply.github.com
Betreff: Re: [OneDrive/onedrive-sdk-csharp] Accessing shared content via /drives.../items... (#180)

I am unable to repro your issue. Using v2.0.2, I executed this query:

var expandValue = "thumbnails,children";

folder = await this.oneDriveClient.Drives[$"{userId}"].Items[$"{userId}!{itemId}"]

.Request().Expand(expandValue).GetAsync();

That returned the expected set of files. Are you sure that you have the correct userId and itemId? Are you sure you have permissions to that item?

About #147#147, you are right is still outstanding. Will be fixed in the next version of the SDK, which should be out this week.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/180#issuecomment-254340252, or mute the threadhttps://github.com/notifications/unsubscribe-auth/APhnzC724hJuiZHIHCpBamVbHUeXYsNzks5q0-kAgaJpZM4KX5nd.

@cdmayer
Copy link
Contributor

cdmayer commented Oct 25, 2016

Hello Damir, Thank you for pointing out the discrepency in dependencies. I will update that shortly.

I was unable to reproduce your issue. I used the exact same request chain (pointing at a shared folder) and was able to successfully get a file stream. I am not sure what issue you're running into. Can you try to gather more information about circumstances where the issue can be reproduced?

@DamirLisak
Copy link
Contributor Author

DamirLisak commented Oct 27, 2016

Hi Chris,

thank you for your help.

I really don’t know what else I can tell you.

I have a Windows-UWP-Application.

I create the OneDrive-Client on this way:

            _Scopes = new string[] { "onedrive.readwrite", "wl.signin", "onedrive.appfolder" };

            _msaAuthProvider = new MsaAuthenticationProvider(
                 _MyClientId,
                "https://login.live.com/oauth20_desktop.srf",
                _Scopes,
                null,
                new CredentialVault(_MyClientId));
            await _msaAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync();
            await _msaAuthProvider.AuthenticateUserAsync();

            _OneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", _msaAuthProvider);

The Client-ID is a string with 16 characters which I have from the Application-Registration-Portal at https://apps.dev.microsoft.com/#/appList.

The first user who creates the shared folder has an account at the microsoft domain „..@.live.de“.
The second user who wan’t to acccess the shared folder has an account at „..@outlook.de“.

If this informations doesn’t help you, I can send you my Visual-Studio-Project and explain you how you can reproduce the issue.

-Damir

Von: Chris Mayer [mailto:notifications@github.com]
Gesendet: Dienstag, 25. Oktober 2016 21:04
An: OneDrive/onedrive-sdk-csharp onedrive-sdk-csharp@noreply.github.com
Cc: Damir Lisak damir.lisak@live.de; Author author@noreply.github.com
Betreff: Re: [OneDrive/onedrive-sdk-csharp] Accessing Special.AppRoot-Folders of other onedrive users (#180)

Hello Damir, Thank you for pointing out the discrepency in dependencies. I will update that shortly.

I was unable to reproduce your issue. I used the exact same request chain (pointing at a shared folder) and was able to successfully get a file stream. I am not sure what issue you're running into. Can you try to gather more information about circumstances where the issue can be reproduced?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/180#issuecomment-256143579, or mute the threadhttps://github.com/notifications/unsubscribe-auth/APhnzM4_FWjmsdjW9M9TLtLjkBRsG3l-ks5q3lKGgaJpZM4KX5nd.

@cdmayer
Copy link
Contributor

cdmayer commented Oct 27, 2016

  • Can you do more basic operations? For example, client.Drive.Request().GetAsync()? Does that return successfully?
  • How are you acquiring the sharing token (encodedUrl in your code above)?
  • What is the ServiceException that you're getting? What is the error code? Any stack information?
  • Have you tried downloading the Graph source code and building a Debug library so you can step through the calls? https://github.com/microsoftgraph/msgraph-sdk-dotnet

@DamirLisak
Copy link
Contributor Author

Yes I did that. I described it a few days ago at microsoftgraph/msgraph-sdk-dotnet#59
I thought you have read that, because github referenced it automatically.
I hope this helps.
If not, I can provide you my VS-project or show it with skype if you want.

Von: Chris Mayer [mailto:notifications@github.com]
Gesendet: Donnerstag, 27. Oktober 2016 21:18
An: OneDrive/onedrive-sdk-csharp onedrive-sdk-csharp@noreply.github.com
Cc: Damir Lisak damir.lisak@live.de; Author author@noreply.github.com
Betreff: Re: [OneDrive/onedrive-sdk-csharp] Accessing Special.AppRoot-Folders of other onedrive users (#180)

  • Can you do more basic operations? For example, client.Drive.Request().GetAsync()? Does that return successfully?
  • How are you acquiring the sharing token (encodedUrl in your code above)?
  • What is the ServiceException that you're getting? What is the error code? Any stack information?
  • Have you tried downloading the Graph source code and building a Debug library so you can step through the calls? https://github.com/microsoftgraph/msgraph-sdk-dotnet


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/180#issuecomment-256742126, or mute the threadhttps://github.com/notifications/unsubscribe-auth/APhnzEG_muVCO3sUAZl0Ci8QwvnNbWovks5q4PjigaJpZM4KX5nd.

@DamirLisak
Copy link
Contributor Author

DamirLisak commented Nov 3, 2016

Hi Chris,
I think it has something to do with the the MsaAuthenticationProvider.
The access to a shared folder of another account worked in my application in August when I used the Version 1.0.0 of onedrive-sdk-csharp (with graph.core 1.1.0). Since you merged the V2-Branch to the trunk on 11.August I had to change my code and use the MsaAuthenticationProvider. After that it doesn't work anymore.
I think it has to do something with the AccessToken which is set in the http-Header in the method MsaAuthenticationProvider.AuthenticateRequestAsync() in line 209:
request.Headers.Authorization = new AuthenticationHeaderValue(tokenTypeString, authResult.AccessToken);

I use CredentialVault-Class to cache the session, so that the user doesn't have to log on again after he has closed and started the UWP-Application:

 _msaAuthProvider = new MsaAuthenticationProvider(
                     _MyClientId,
                    "https://login.live.com/oauth20_desktop.srf",
                    _Scopes,
                    null,
                    new CredentialVault(_MyClientId));
                await _msaAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync();
                await _msaAuthProvider.AuthenticateUserAsync();

                _OneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", _msaAuthProvider);

In your examples/documentation you use "https://api.onedrive.com/v1.0" and "https://login.live.com/oauth20_desktop.srf" is that right or must be used other url's for my scenario?

There must be a problem in the combination Cached Sessions + Http-Redirection + Onedrive-API-Version.

Please help me!

@DamirLisak
Copy link
Contributor Author

DamirLisak commented Nov 5, 2016

I have found out the problem, and this is definitively a bug.
I opened https://onedrive.live.com in the browser. I clicked "Add people" and entered the e-Mail-Address of the other user B. After this I started my App an logged on with user B and I was able to download the file.
At https://dev.onedrive.com/items/invite.htm is described, that "Using the invite action is more secure than creating a sharing link, because the permissions are only valid for the recipient and cannot be used by others.".
The interesting thing here is,

  1. that creating sharing links over the api works only, when other users want to access the folder over a browser but not with the api. I think this is a general problem in the onedrive api.
  2. As you can remember ( @cdmayer ) at my first issuehttps://github.com/OneDrive/onedrive-sdk-csharp/issues/147 I asked you when will be the Invitation-Action https://dev.onedrive.com/items/invite.htm implemented?

So long as one of those points are not fixed, a sharing scenario for Applications using onedrive-sdk-csharp is not possible.

@DamirLisak
Copy link
Contributor Author

A small apostil:
At https://dev.onedrive.com/items/invite.htm is another sentence "Note: This functionality is a preview and should only be used for evaluating and testing. Some details of this API are expected to be changed before this functionality is finally released."
One the one hand developers shouldn't use the invitaion-action but on the other hand microsoft provides this functionality in the wbebbrowser at https://onedrive.live.com !?

@DamirLisak
Copy link
Contributor Author

I have implemented the Invitation-Logic and commited to the Invitation-Branch.
DamirLisak@5abcf67
I'm now able to invite other user's and Access the shared Folder.
But there must be a Problem in the OneDrive-API. I set the "sendInvitation"-Property to true but the OneDrive-api doesn't send a E-Mail to the invited user.
@cdmayer : Do you know why?

@DamirLisak
Copy link
Contributor Author

I know now why:
The last paragraph "Known Issues" in the api-documentation says:
"Email invitations will not be sent when using invite from OneDrive Personal."
I hope microsoft will fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants