Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cookie authentication for CouchDB access #852

Closed
wants to merge 3 commits into from

Conversation

MidnightLightning
Copy link

Use the _session CouchDB endpoint to ensure we have an authenticated session before trying to manipulate data.

Fixes #846

@MidnightLightning
Copy link
Author

Ping! Any feedback on this request? As it stands now, if you want to save content to a CouchDB back-end, the database used has to be public, because StackEdit doesn't authenticate properly to it.

@willprice
Copy link

Any news on this, would be great to be able to use private couchdb instances.

@iainbryson
Copy link

Is this still a going concern?

One thing confuses me about the implementation: it seems to be authing with the session on every request, not waiting for the expiry to re-request it. If that's correct, why would this be preferred over basic auth?

@MidnightLightning
Copy link
Author

I abandoned StackEdit because this issue wasn't resolved, so not sure if it's been fixed through another channel in the interim.

This solution does request a new session at the beginning of each batch action out of simplicity. If we wanted more long-running sessions, a check would have to be made (one additional network request to GET /_session) at the beginning of the batch, and additional hooks made to watch for changes to settings.couchdbUrl to see if the given username/password changed since we last made a session.

Using basic authentication (sending an Authorization: Basic <base64-encoded-username:password> with every request) could work, and I believe I didn't do that at the time since there were quirks with different browsers and jQuery versions getting that to work when the credentials were part of the URL (translating the http:https://username:[email protected] into an Authorization: Basic header). If the StackEdit preferences were modified to have three fields (URL, username, password) for CouchDB configuration, that would be easier, or if jQuery's cross-browser handling of those sorts of URLs has improved in the last year that might be a better option.

@iainbryson
Copy link

Thanks @MidnightLightning !

@ssaavedra
Copy link

Why is this not merged yet?

The withCredentials part is paramount in each request (and/or a correct handling of username and password).

@MidnightLightning
Copy link
Author

Resolved the merge conflicts by merging from upstream and re-running Gulp build task.

@ssaavedra
Copy link

Please, cherry-pick my commit at ssaavedra@046d02b because otherwise this is still broken in Firefox (because passing username:password in the host seems not to be standardized).

@MidnightLightning
Copy link
Author

All right @ssaavedra; done now, though I did rename the function to make it more clear what it does, and not have two things named couchdbUrl with one a function (on the helper object) and one a string (on the settings object).

@ssaavedra
Copy link

ssaavedra commented Sep 28, 2016 via email

@benweet benweet closed this Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants