Js Client Connection via webDav 401 Error

Again in a little more detail :).
Hi,
first of all some information:
I’m trying to use js and webdav to output the contents of my nc folders as json.
I’ve been trying to do this for some time and have started a few attempts to get rid of the error message.

I have adjusted the trusted address in Docker :

docker exec --user www-data [someContainerName] php occ config:system:set trusted_domains 1 --value=localhost:1234


Since I have it running on Apache, I also tried to adjust the headers in apache2.conf and at sites enable. In the end :

Header always set Access-Control-Allow-Origin “*”
Header always set Access-Control-Allow-Credentials true
Header always set Access-Control-Allow-Methods “OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT”.
Header always set Access-Control-Allow-Headers “accept, content-type”.
inserted.

My Code:

import { createClient, parseXML } from "webdav";
const client = createClient("http://localhost:8080/", {
    auth: {
      username: "test@mail.de",
      password: "12345",
    },
  });
 const handle = async () => {
    const testItems = await client.getDirectoryContents(
      "/remote.php/dav/files/test@mail.de/Documents/?formt=json",
      {
        method: "PROPFIND",
        headers: {
          Accept: "text/plain",
          Depth: "0",
        },
        responseType: "text",
      }
    );
    const DAVResult = await parseXML(testItems.data);
    return DAVResult;
  };

The NC container is 100% requested, every time I reload my self-built client side I get this output in the Dockerlog:

…OPTIONS /remote.php/dav/files/test%40mail.com/Documents/%3Fformt%3Djson/ HTTP/1.1" 401 2222 “http://localhost:1234/” "Mozilla/5.0…

Can someone help me just get the output :?

Someone with an hint :question:

This forum is mostly about SOHO users and system administration, keep calm and hope some of the devs take a look at the issue… until then review the docs: Nextcloud developer documentation — Nextcloud latest Developer Manual latest documentation

1 Like

Just out of the blue: Can you verify that the browser is in fact starting the request you try to build up?

PS: You can use triple backticks on its own line before and after the code to make it verbatim. That makes it easier to read.

ok, thank you.

Hi, yes it is.
I have set up a simple docker container with nextcloud and just start this request.
Additionally to the pending i get also an 401 respond.

I do not have an Reverse Proxy in between, so i dont get the problem with cors here…

Your error message looks a bit strange, to be honest. Is the fontend really requesting the URL /remote.php/dav/files/test%404 Not Found?
Are you sure, your trusted domains setting is correct, the poor 1234 seems wrong to me (or is it just dummy data?).

Again out of the blue: you need to urlencode the @ in the URL, am I wrong? Also, I am not sure, what this webdav import is. Does to really need the complete URL or just the path?

I will probably not be able to help here anymore, as this is too far from my region of experience.

1 Like

That URL is the respond in the docker nextcloud container

So, there is no way off getting access via webDav using JS ?
Ive tried several lib.
“webdav/web”;“webdav-fs”;“nextcloud-link”;
None of them worked.