You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Mark Deibert <ma...@gmail.com> on 2013/10/02 00:57:24 UTC

_session authentication to CouchDB from AngularJS

I've been searching and reading articles for a full 2 weeks of evenings
after work. No matter what I'm finding/trying, I cannot get CouchDB
_session/cookie authentication to work. I can get the first part to work, I
can setup and send the initial POST to _session with a valid user/pass and
I get a positive response from Couch. In Chrome console I see the
AuthSession cookie comes back in the response. But sadly, from here, I get
401 "not authorized" on all subsequent GET, PUT, whatever.

I think on the entire surface of the earth there is only me and maybe 4 or
5 other guys that are trying to use CouchDB with AngularJS because I can't
get this resolved no matter where I post.

Is anyone in this group using AngluarJS with CouchDB? If yes, are you using
AuthSession cookie authentication? If yes, pleeeeeeeeeeeeeeese help! :-/
I've gotten almost no where for 2 weeks now.

Thank, thank you, thank you, thank you for any advice you can provide.

Re: _session authentication to CouchDB from AngularJS

Posted by Alexander Shorin <kx...@gmail.com>.
Hi Mark,

To use Cookie auth you need to make two actions:
1. POST /_session with user's credentials and get the AuthSession cookie
http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session

2. Make any other request with the received cookie. Example:
http://docs.couchdb.org/en/latest/api/server/authn.html#get--_session

For AngularjS side you need to access $cookies object to get/set the
cookie and $cookiesStore to keep it for a long time within your app
http://docs.angularjs.org/api/ngCookies

Also take a look on this blog post:
https://www.twilio.com/blog/2013/08/votr-part-4-angularjs-and-authentication-with-couchdb.html
They uses similar idea, but with their own methods as I see in the
code examples.

Hope this helps.

--
,,,^..^,,,


On Wed, Oct 2, 2013 at 2:57 AM, Mark Deibert <ma...@gmail.com> wrote:
> I've been searching and reading articles for a full 2 weeks of evenings
> after work. No matter what I'm finding/trying, I cannot get CouchDB
> _session/cookie authentication to work. I can get the first part to work, I
> can setup and send the initial POST to _session with a valid user/pass and
> I get a positive response from Couch. In Chrome console I see the
> AuthSession cookie comes back in the response. But sadly, from here, I get
> 401 "not authorized" on all subsequent GET, PUT, whatever.
>
> I think on the entire surface of the earth there is only me and maybe 4 or
> 5 other guys that are trying to use CouchDB with AngularJS because I can't
> get this resolved no matter where I post.
>
> Is anyone in this group using AngluarJS with CouchDB? If yes, are you using
> AuthSession cookie authentication? If yes, pleeeeeeeeeeeeeeese help! :-/
> I've gotten almost no where for 2 weeks now.
>
> Thank, thank you, thank you, thank you for any advice you can provide.