forwardemail / caldav-adapter

CalDAV server for Node.js and Koa. Modernized and maintained for @forwardemail
https://forwardemail.net
MIT License
27 stars 9 forks source link

how to run? #2

Closed lixaotec closed 4 years ago

lixaotec commented 4 years ago

Dear @sedenardi

Congratulations for the amazing work.

Im not very experienced with koa, so couldnt make neither example or server.js to work.

how to run (easy step by step)

thanks

lixaotec commented 4 years ago

seems the problem is happening with koa.ts

const rootRegexp = pathToRegexp(path.join(rootRoute, '/:params')); const calendarRegex: CalRegex = { keys: [] }; calendarRegex.regexp = pathToRegexp(path.join(calendarRoute, '/:principalId/:calendarId/:eventId'), calendarRegex.keys); const principalRegex: CalRegex = { keys: [] }; principalRegex.regexp = pathToRegexp(path.join(principalRoute, '/:principalId'), principalRegex.keys);

pathToRegexp dont like * ? at routes

sedenardi commented 4 years ago

Can you give an example of the URL you're sending? You have to make sure all your URLs are encoded before being sent to this middleware.

lixaotec commented 4 years ago

I´m trying to use it with iOS 12.4.6 (iphone 5s).

localhost:5232/user/exampleCal1

(ive changed in json user@co to just user.)

When i run the project, at execution time, node seems not to like the * at pathToRegex parameters. i´m stuck at that point.

Thanks for your reply.

lixaotec commented 4 years ago

Also Ive noticed an behavior at the first comuniction iOS -> caldav adapter it seems to fail when the first response ask for Auth. It appears, iOS is not expecting the WWW-Authenticate... as it simply fails

lixaotec commented 4 years ago

TCP server accepting connection on port: 5555 START << From client to proxy PROPFIND /user/exampleCal1/ HTTP/1.1 Host: 192.168.100.11:5555 Content-Type: text/xml Depth: 0 Brief: t Accept: / Connection: keep-alive Prefer: return=minimal User-Agent: iOS/12.4.6 (16G183) accountsd/1.0 Content-Length: 181 Accept-Language: Accept-Encoding: gzip, deflate

<?xml version="1.0" encoding="UTF-8"?> </A:prop> </A:propfind>

From proxy to remote PROPFIND /user/exampleCal1/ HTTP/1.1 Host: 192.168.100.11:5555 Content-Type: text/xml Depth: 0 Brief: t Connection: keep-alive Prefer: return=minimal User-Agent: iOS/12.4.6 (16G183) accountsd/1.0 Content-Length: 181 Accept-Language: Accept-Encoding: gzip, deflate

<?xml version="1.0" encoding="UTF-8"?> </A:prop> </A:propfind>

<< From remote to proxy HTTP/1.1 401 Unauthorized Vary: Accept-Encoding WWW-Authenticate: Basic realm="localhost/caldav" Content-Type: text/plain; charset=utf-8 Content-Length: 12 Date: Fri, 05 Jun 2020 06:59:52 GMT Connection: keep-alive

Unauthorized

From proxy to client HTTP/1.1 401 Unauthorized Vary: Accept-Encoding WWW-Authenticate: Basic realm="localhost/caldav" Content-Type: text/plain; charset=utf-8 Content-Length: 12 Date: Fri, 05 Jun 2020 06:59:52 GMT Connection: keep-alive

Unauthorized

sedenardi commented 4 years ago

localhost:5232/user/exampleCal1

(ive changed in json user@co to just user.)

You have to use the full username in the URL you're connecting to. So once the server is running, use this as the server:

/caldav/p/user@co

The caldav portion is defined by the caldavRoot option, so you can segment requests on your server. The /p/ means you're connecting to all the calendars for the principal. This is how iOS and MacOS need to connect to CalDAV servers.

I've updated the README with that information.

lixaotec commented 4 years ago

Did a resfresh to your code... after npm i I get this

npm run watch

caldav-adapter@4.0.1 watch C:\node-caldav-adapter-master nodemon -e js --ignore node_modules/ --inspect example/server.js

[nodemon] 2.0.4 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): . [nodemon] watching extensions: js [nodemon] starting node --inspect example/server.js Debugger listening on ws://127.0.0.1:9229/1db2aeb7-773c-4d3e-9e72-612c52027804 For help, see: https://nodejs.org/en/docs/inspector C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:47 throw new TypeError("Missing parameter name at " + i); ^

TypeError: Missing parameter name at 1 at lexer (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:47:23) at parse (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:97:18) at stringToRegexp (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:329:27) at Object.pathToRegexp (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:403:12) at Object.default_1 [as koa] (C:\node-caldav-adapter-master\lib\koa.js:25:41) at Object. (C:\node-caldav-adapter-master\example\server.js:14:17) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) [nodemon] app crashed - waiting for file changes before starting...

sedenardi commented 4 years ago

Have you changed anything in the example/server.js file?

lixaotec commented 4 years ago

nope

lixaotec commented 4 years ago

just build from source again. my node is v12.16.3 I read this regardin path.join() "Join all arguments together and normalize the resulting path. Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown." Could be that?

lixaotec commented 4 years ago

Think i got as I am running in windows rootRoute gets with path.resolve C:\caldav

sedenardi commented 4 years ago

Ahh, koa.ts should be using path.join rather than path.resolve, since Windows machines use backslashes.

To confirm this is the issue, can you change line 47 of koa.ts, run npm i, and confirm that works?

lixaotec commented 4 years ago

sure, i´m working on it

lixaotec commented 4 years ago

another issue now: backslash still got \ , instead of /

\caldav C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:113 throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type); ^

TypeError: Unexpected MODIFIER at 15, expected END at mustConsume (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:113:15) at parse (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:172:9) at stringToRegexp (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:329:27) at Object.pathToRegexp (C:\node-caldav-adapter-master\node_modules\path-to-regexp\dist\index.js:403:12) at Object.default_1 [as koa] (C:\node-caldav-adapter-master\lib\koa.js:26:41) at Object. (C:\node-caldav-adapter-master\example\server.js:14:17) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) [nodemon] app crashed - waiting for file changes before starting...

lixaotec commented 4 years ago

perhaps all path.join is working unexpectly with windows env...

lixaotec commented 4 years ago

im trying use path.posix.join

lixaotec commented 4 years ago

It did solve path issues!!

And now we´re on the other trouble with auth..

START << From client to proxy PROPFIND /caldav/p/user/ HTTP/1.1 Host: 192.168.100.11:5555 Content-Type: text/xml Depth: 0 Brief: t Accept: / Connection: keep-alive Prefer: return=minimal User-Agent: iOS/12.4.6 (16G183) accountsd/1.0 Content-Length: 181 Accept-Language: pt-br Accept-Encoding: gzip, deflate

START << From client to proxy <?xml version="1.0" encoding="UTF-8"?> </A:prop> </A:propfind>

From proxy to remote PROPFIND /caldav/p/user/ HTTP/1.1 Host: 192.168.100.11:5555 Content-Type: text/xml Depth: 0 Brief: t Accept: / Connection: keep-alive Prefer: return=minimal User-Agent: iOS/12.4.6 (16G183) accountsd/1.0 Content-Length: 181 Accept-Language: pt-br Accept-Encoding: gzip, deflate

From proxy to remote <?xml version="1.0" encoding="UTF-8"?> </A:prop> </A:propfind>

<< From remote to proxy HTTP/1.1 401 Unauthorized Vary: Accept-Encoding WWW-Authenticate: Basic realm="localhost/caldav" Content-Type: text/plain; charset=utf-8 Content-Length: 12 Date: Fri, 05 Jun 2020 19:12:56 GMT Connection: keep-alive

Unauthorized

From proxy to client HTTP/1.1 401 Unauthorized Vary: Accept-Encoding WWW-Authenticate: Basic realm="localhost/caldav" Content-Type: text/plain; charset=utf-8 Content-Length: 12 Date: Fri, 05 Jun 2020 19:12:56 GMT Connection: keep-alive

Unauthorized << From remote to proxy HTTP/1.1 400 Bad Request Connection: close

From proxy to client HTTP/1.1 400 Bad Request Connection: close

lixaotec commented 4 years ago

just removed @ex.co from json , so to avoid any possible encoding issue

sedenardi commented 4 years ago

im trying use path.posix.join

Great. I don't have a windows machine to test on so thanks for bringing this to my attention. I've changed the code to use path.posix instead of just path. I'll push that change shortly.

As for the auth issues, what are the server settings you're using? Server, User Name, Password?

@ex.co being in the username isn't an issue, as it gets URL encoded automatically by clients and decoded automatically by the server.

lixaotec commented 4 years ago

Glad to contribute. And thank for the work you´ve done with this project.

i´m using the default settings. Also had tried @ex.co.. in fact no differences, But auth wont accomplish.

localhost:3001, user@ex.co, pass

I think this step at auth wont working because ios wont send it at the first step const creds = basicAuth(ctx);

trying to figure out

sedenardi commented 4 years ago

Are you using the full url http://localhost:3001/caldav/p/user@ex.co in the iOS or MacOS settings?

lixaotec commented 4 years ago

iOS .. and yes for the path. Just tried a bunch of variations.

sedenardi commented 4 years ago

And I assume you've confirmed that your phone can access your computer's localhost? I've run into this issue before and had to use ngrok or a similar service.

lixaotec commented 4 years ago

sure. I ve tried directly .. and with a proxy to capture the packages. I´m pretty sure its something to do with the fact of ios isnt sending credentials at first, as ssl is disabled. and the workflow is expecting another message.

I am looking into this reference: https://wiki.wocommunity.org/display/~probert/CalDAV+and+CardDAV+handshake

lixaotec commented 4 years ago

or perhaps im missing something with realm (dont know how it works)

sedenardi commented 4 years ago

Ahh yeah you may have to use an HTTPS connection. I'm not sure if that's an iOS restriction or not.

lixaotec commented 4 years ago

hum.. how to set koa to respond that?

sedenardi commented 4 years ago

That's sort of outside the scope of this module, but there are many ways to do it. You can use ngrok to create an https tunnel to your localhost for development purposes, or create a self-signed HTTPS cert for your machine.

lixaotec commented 4 years ago

Just manage to make koa listen at https with a simply self signed cert.

And its all working now!

Thank you very much for the attention! If you wish i may pr this https piece.

Hope to work with you to improve the tool, and share knowledge with you.

sedenardi commented 4 years ago

No problem.