a-schild / nextcloud-java-api

Java api library to access nextcloud features from java applications
GNU General Public License v3.0
72 stars 50 forks source link

401 on creating shares with ShareType.PUBLIC_LINK #63

Closed iroCheese closed 3 years ago

iroCheese commented 3 years ago

Hello,

firstly thank you for creating this library!

I am using version 11.5.1 as a maven dependency and have the following problem: When I create a share for a folder with ShareType.EMAIL everything works as expected thus I am pretty sure that authentication is working correctly. However, when I try to create a share with ShareType.PUBLIC_LINK I get a response with status code 401.

My code looks as follows:

nc = new NextcloudConnector(...);

if (!nc.folderExists("Testfolder")) {
    nc.createFolder("Testfolder");
}

Share share = nc.doShare(
    "Testfolder",
    ShareType.PUBLIC_LINK,
    null, // I've also tried empty String
    false,
    "password",
    new SharePermissions(1)
);

While looking through the source code of this lib, I noticed that there is no check for empty Strings or null values for shareWith in the FilesharingConnector method

doShareAsync(
            String path,
            ShareType shareType,
            String shareWithUserOrGroupIdOrEmail,
            Boolean publicUpload,
            String password,
            SharePermissions permissions)
    {
    //...
    // line 190
    postParams.add(new BasicNameValuePair("shareWith", shareWithUserOrGroupIdOrEmail));

This results in the request URL containing the param ...&shareWith=&... with an empty value. I'm not sure if that's actually causing the issue but I could imagine that nextcloud recognizes this as an invalid attempt to access some resource that the user is not allowed to.

It would be great if someone could look into this, or give me a hint of what I'm doing wrong.

a-schild commented 3 years ago

The public link sharing works in our test cases. Please have a look at the unit tests

public void t03_testDoShare2() {
public void t03_testDoShare3() {

Perhaps your NC instance is not allowed to create public shares?

iroCheese commented 3 years ago

Thanks for your response! Apparently the null value in shareWithUserOrGroupId didn't work. I probably also changed something else while testing the empty String and thus thought it didn't work either. However it works now so this ticket can be closed. Thanks for the help

a-schild commented 3 years ago

Thanks for the followup