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

[BUG] OneDriveGraphApi.ShareItem with Organization scope does not work as expected #41

Open
DemiDOS opened this issue Sep 19, 2023 · 2 comments
Assignees

Comments

@DemiDOS
Copy link

DemiDOS commented Sep 19, 2023

Description
I get the message Access Denied for my corporate account in browser when I use the link generated by the API method OneDriveGraphApi.ShareItem with Organization scope.

To Reproduce
Steps to reproduce the behavior:

  1. Upload a file and generate link to file using API:
    var oneDriveGraphApi = new OneDriveGraphApi(_oneDriveApiInfo.ClientId);
    await oneDriveGraphApi.AuthenticateUsingRefreshToken(_oneDriveApiInfo.RefreshToken);
    var oneDriveFile = await oneDriveGraphApi.UploadFileToAppFolder(filePath);
    var oneDrivePermission = await oneDriveGraphApi.ShareItem(oneDriveFile, OneDriveLinkType.View, OneDriveSharingScope.Organization);
  2. Check the file on OneDrive. The file was uploaded and shared via link, but the link does not work.
  3. If anonymous access is disabled in organization, there is an issue with access to file via link.

Expected behavior
Uploaded file should be accessible via link for everyone inside organization.

Versions:

  • OS: Windows 10
  • OneDriveApi: 2.4.0
  • .NET 6.0
@DemiDOS
Copy link
Author

DemiDOS commented Sep 19, 2023

Quick look into problem:
request (https://graph.microsoft.com/v1.0/me/drive/items/***/createLink) contains empty body. I guess, serialization of OneDriveRequestShare instance always create empty string and does not respect provided values.

@frankashley
Copy link

frankashley commented Dec 11, 2024

I think the issue is the move to System.Text.Json. The serialization is using the base type. I ended up with this helper function that needed to be used in two places. Two places I was having problems with these enums: NameConflictBehavior and OneDriveLinkType. I don't know why EnumMember Attribute wasn't good enough.

    private string SerializeEnumStringAsValueToJson<T>(T obj) where T : OneDriveItemBase
    {
        var options = new JsonSerializerOptions
        {
            Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
        };
        return JsonSerializer.Serialize(obj, obj.GetType(), options);
    }

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

3 participants