digital-blueprint / webapppassword

Nextcloud app to generate temporary app passwords and allow webdav access for SPAs
https://github.com/digital-blueprint/webapppassword
GNU Affero General Public License v3.0
19 stars 6 forks source link

500 on request #223

Open timowevel1 opened 2 months ago

timowevel1 commented 2 months ago

Hello,

I think its rather an error with the way I use it, but I cannot figure it out.

With postman I tried to test with

GET https://domain/index.php/apps/webapppassword/api/v1/shares?path=/Assessments/Max%20Mustermann/11.09.2024/8ed25dc5-d4f6-4a3f-9e51-05024ccb38e3.mp4

Authorization with Basic

Nextcloud 28.0.5

Header OCS-APIRequest to true

image

As return in the body it returns me the HTML code of nextcloud `<!DOCTYPE html>

Nextcloud

Nextcloud

Internal Server Error

The server was unable to complete your request.

If this happens again, please send the technical details below to the server administrator.

More details can be found in the server log.

Technical details

  • Remote Address: 91.0.47.62
  • Request ID: XpJQ1rBdGwrb9ek1etW4
` When I embed that into my application it returns me a cors error Access to fetch at 'https://domain/index.php/apps/webapppassword/api/v1/shares?path=/Assessments/Max%20Mustermann/11.09.2024/8ed25dc5-d4f6-4a3f-9e51-05024ccb38e3.mp4' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. Code: `const fetchVideoShareLink = async (path) => { // Extract the part starting from "/Assessments" const cleanPath = path.substring(path.indexOf("/Assessments")); console.log(cleanPath) const response = await fetch(`https://xxx/index.php/apps/webapppassword/api/v1/shares?path=${cleanPath}`, { method: 'GET', headers: { 'Authorization': `Basic ${btoa('username:password')}`, // Replace 'username' and 'password' with actual credentials 'OCS-APIRequest': 'true', }, }); console.log(response) if (response.ok) { const data = await response.json(); if (data.ocs && data.ocs.data && data.ocs.data.length > 0) { return data.ocs.data[0].url; // Return the share URL } else { throw new Error('No share link found.'); } } else { throw new Error('Error fetching share link.'); } };` Any idea what I am doing wrong?
timowevel1 commented 2 months ago

Okay, I updated from 0.5 to 0.10. Now it says `<?xml version="1.0"?>

failure 404 Could not create share ` If I use webapppassword. `https://xxxx/index.php/apps/webapppassword/api/v1/shares?path=/Assessments/Max%20Mustermann/11.09.2024/8ed25dc5-d4f6-4a3f-9e51-05024ccb38e3.mp4` If I use the legacy API, it returns the right response. `https://xxx/ocs/v2.php/apps/files_sharing/api/v1/shares?path=/Assessments/Max%20Mustermann/11.09.2024/8ed25dc5-d4f6-4a3f-9e51-05024ccb38e3.mp4` ` ok 200 OK 2 3 admin admin 17 1 1 1726238422 BCRiffnPHtzXEfp admin admin /Assessments/Max Mustermann/11.09.2024/8ed25dc5-d4f6-4a3f-9e51-05024ccb38e3.mp4 file 27 video/mp4 home::admin 1 177 177 176 /8ed25dc5-d4f6-4a3f-9e51-05024ccb38e3.mp4 218475 1726238377 (Shared link) https://xxxx/s/BCRiffnPHtzXEfp 0 0 ` The cors error still persists, but I am testing in postman
pbek commented 2 months ago

@DanRiess, @aleixq?

DanRiess commented 2 months ago

Hey, sorry for the late reply. Webapppasswords share api wrapper works with POST requests only. Try the following:

const result = await fetch(`${this.server}/index.php/apps/webapppassword/api/v1/shares`, {
    method: 'POST',
    headers: {
        Authorization: `Bearer ${this.token}`,
        // Authorization: `Basic ${btoa('user:password')}`,
        'Content-Type': 'application/json',
        'OCS-APIRequest': 'true',
    },
    body: JSON.stringify({
        path: pathToYourFile,
        shareType: 3, // check out nextcloud docs for a list of supported share types. The most common one is 3.
        password: shareFilePassword,
        expireDate: expireDate ? expireDate.toISOString() : null,
    }),
})