Akylas / OSS-DocumentScanner

Android document document scanning app
https://www.akylas.fr
MIT License
767 stars 28 forks source link

Owncloud WebDAV connection #58

Open jswetzen opened 9 months ago

jswetzen commented 9 months ago

Thanks for a great document scanner, I can finally ditch the proprietary app I've been using and go more open source 💪

I'm unable to connect to my Owncloud or Nextcloud instances (I have both), trying various server addresses. To eliminate problems on the server end, I've connected through Ghost commander by specifying: Server: owncloud.mydomain.com:443 Path: remote.php/webdav

In Document Scanner, I've tried for example these for server address: owncloud.mydomain.com:443/remote.php/webdav https://owncloud.mydomain.com/remote.php/webdav https://owncloud.mydomain.com/remote.php/webdav/ I have also tried putting everything after the domain in the remote folder option.

How am I supposed to put in my server address?

farfromrefug commented 9 months ago

@jswetzen happy to hear you like it! as for the webdav. Yes the first one should work. I add https if you dont set it. i think the error comes from how owncloud expects authentication header https://owncloud.dev/apis/http/webdav/#authentication. Will have to make it configurable. For now i only support basic auth. Will try to fix that as soon as possible

jswetzen commented 8 months ago

@farfromrefug Thanks for the clarification! I took a look at the code and it seems like a straightforward thing to fix (really nice code base BTW). Wanted to take a stab at it myself, just the web app part, but it's been a while since I've worked with nodejs. npm install gives dependency problems, is there something else I need to setup first? I'm running nodejs v20.11.0.

farfromrefug commented 8 months ago

@jswetzen great if you want to take a look at it. Running the project is not that straight forward though :s First thing is the part about tesseract/opencv as described here https://github.com/Akylas/OSS-DocumentScanner/tree/master#building I dont commit those libs are they are huge. So you would need to build it yourself :s After that you should use yarn and there is a little change to make to the package.json because i use local resolutions for fast dev. I can guide you through all that if you are willing to get a stab at it. I guess i can even share with you the prebuilt libs. Might even be a good idea to spend a little time adding a script to download those files from somewhere. If you are willing we can chat on discord

jotoeri commented 7 months ago

Hi both,

i was fiddling around the last three hours with this to get it syncing to my Nextcloud. Seems to me like the problem is okhttp not sending the authorization at first, but only after receiving a 401 [1]. To me, the returned error was at some point this 401 which told me that no authorization header (neither Basic nor Bearer) was included.

As such, i found a workaround for now by exporting the DocumentScanner-config, editing it to add the Authorization header and re-importing it. This way of manually setting the header leads to an always sent header and thus the first request being authorized. @farfromrefug Maybe that idea also helps to fix the issue? :)

For Nextcloud, my configuration is now as follows:

remoteURL: https://<Domain>/remote.php/dav/files/<Username>/
username: <Username>
headers: {
  Authorization: Basic <Base64Hash of User:Password>
}
remoteFolder: <myFolder>/

Cheers! Jonas

[1] https://stackoverflow.com/a/36056355/14998011

farfromrefug commented 7 months ago

@jotoeri this is strange. Normally this is what the app should do for nextcloud. Will need to have a look. I implemented that feature specifically with Nextlcoud cause i have an instance.

For eveyone to understand my issue with webdav now is that not all webdav instances uses the same "basic" authentication. I am ok using others but i need to find a way to "discover" which authentication to use on a per user basis. And for now i could not find anything. If anyone can help there that would be awesome

jotoeri commented 7 months ago

Hm, to specify a bit more: The test works, and i saw a new app-password on the nextcloud afterwards. So the initial connection is fine. Just the actual sync requests afterwards are not authenticated anymore - as i said, i assume the existing valid authentication is just not passed anymore on the sync request.

farfromrefug commented 7 months ago

@jotoeri what do you mean you saw a new app-password on the nextcloud afterwards ? So you uderstand when you enter your info and save them i simply generate the header using this https://github.com/Akylas/OSS-DocumentScanner/blob/master/app/webdav/auth/basic.ts. Then i store the header and use that for any request. That way i dont have to store your password which is safer

jotoeri commented 7 months ago

Ah, sorry maybe i mixed that up now. In the settings->security i saw some entries named okhttp. But that list shows created app-passwords as well as just sessions with the normal password. So might have been just your usual login sessions, which i saw there. Sorry for the confusion. 🙈

farfromrefug commented 7 months ago

@jotoeri no problem! i dont see that in my nextcloud instance (28.0.1). It does not seem to show me "sessions" like you see. I use self hosted instance, that may be why...

jotoeri commented 7 months ago

Hm, i also have it self-hosted on 27.1.x iirc. Its in the personal settings -> security and at least in german it's called devices & sessions. I don't think they removed that on 28. ;)

Maybe i can give you more information next week, for now i'm away on the weekend. ;)

cboehm-it commented 7 months ago

@farfromrefug Maybe it's worth looking into other implementation handling the auth detection or even use a library for that? 🤔 https://github.com/perry-mitchell/webdav-client

farfromrefug commented 7 months ago

@cboehm-it it is actually the source i got my implementation from ;) Had to clean a lot of things to get it working here though. I think i know how i am going to do it. Have to be a choice when filling the server. i dont like that cause i think most users dont know what authentication to use , but might be the only choice https://github.com/zhanghai/MaterialFiles is implementing webdav. Waiting a bit to see how he decides to do it UX wise. Love his work

Himra commented 6 months ago

Hello everyone,

I am absolutely delighted with this app.

The only thing I'm still missing is a clean Nextcloud connection.

I first created an account for the app in Nextcloud according to these instructions:

When using a third-party WebDAV client (including your operating system’s built-in client), you should use an application password for login rather than your regular password. In addition improved security, this increases performance significantly https://github.com/nextcloud/server/issues/32729#issuecomment-1556667151. To configure an application password, log into the Nextcloud Web interface, click on the avatar in the top right and choose Personal settings. Then choose Security in the left sidebar and scroll to the very bottom. There you can create an app password (which can also be revoked in the future without changing your main user password).

as described here: https://docs.nextcloud.com/server/latest/user_manual/en/files/access_webdav.html

The connection test was positive, but when I save the settings in the app, the following error message appears:

Invalid response 403: Permission denied to create directory

Can anyone help me with this?

Greetings Himra

Himra commented 6 months ago

Oh, after reopening the app, everything worked after all. Thanks for the great app.

farfromrefug commented 6 months ago

@Himra so it did not work straight away after setting webdav up? You had to restart to have it working? Might be a bug there

Himra commented 5 months ago

I have tested everything again with version v1.5.9 Build 66 and everything has worked so far except for the deletion.

The deletion is not passed on cleanly to Nextcloud. It has to be deleted manually in the OOS-D app and in Nextcloud at the same time to avoid error messages.

Deleting in the OOS-D app alone leads to an error message during the next synchronization and the folder also reappears.

Deleting only in Nextcloud causes errors in the OOS-D app.

I have checked the permissions in Nextcloud as far as I can.

farfromrefug commented 5 months ago

@Himra thanks for the testing. Will retest it all!

Himra commented 5 months ago

Hello @farfromrefug, thank you for the quick response. Now I have another question: Is there a possibility or is it planned to synchronize only the result of the scan i.e. the image.jpg via WEBDAV and not the whole directory? Of course with a different file name, e.g. timestamp.

farfromrefug commented 5 months ago

@Himra no not planed really as not easy. Also the image.jpg might not always be the true result. For example in image.jpg some filters are not applied (bw, sepia...) What s bothering you? the size? Or maybe you just want to have a folder with all your scanned document in jpg format? If so then we would need some kind of auto export image to a specific folder with a filename template

farfromrefug commented 2 months ago

@Himra it is now implemented in latest!