La autenticación CouchDB _session está fallando

My app is AngularJS. In my service I have a couple login functions...

    login: function(tag,pass) {
        return $http.post(this.databaseUrl + "_session/", {"name":tag,"password":pass});
    },

    loginGet: function() {
        return $http.get(this.databaseUrl + "_session");
    },

En mi controlador tengo...

    $scope.init = function() {
        dataFactory.login("mark","myPassword")
        .then(function (response) {
            console.log('dataFactory.login.post response...');
            console.log(response);
            dataFactory.loginGet()
            .then(function (response) {
                console.log("dataFactory.loginGet response...");
                console.log(response);
            });
        });
    };

Here is what I see in console...

enter image description here

Note that the roles returned after the post are correct. They are the roles for "mark", but note the blank name in the returned json. The following get call to _session returns Ok but again the name is blank. All subsequent gets to the database return 401 "Unauthorized" errors so the authentication is failing. Why does it appear to be trying/partially authenticating but not really?!?!

In Couch configuration I have…

httpd section:

  • bind_address = 0.0.0.0
  • enable_cors = true

cors section:

  • credentials = false
  • origins = *

couch_httpd_auth section:

  • allow_persistent_cookies = true
  • authentication_db = _users
  • require_valid_user = false;

The security dialog for this database looks like...

enter image description here

The only way I can get around the 401 errors is to clear the Members names/roles boxes on this dialog. Which is no solution at all.

¿Puedes ver lo que estoy haciendo mal?

Thanks a lot for your help. I've been trying and failing on this for days :-/

preguntado el 11 de septiembre de 13 a las 20:09

So are all the CouchDB experts on vacation or have I said something wrong and/or dumb? :-/ -

1 Respuestas

Answering my own question again. So for future CouchDB authentication searchers, the following authentication method is working in my AngularJS app...

    authenticate: function(user,pass) {
        return $http({
            method: "POST",
            url: this.databaseUrl + "_session",
            headers: {"Content-Type": "application/x-www-form-urlencoded"},
            data: "name=" + user + "&password=" + pass
        });
    },

Respondido el 18 de Septiembre de 13 a las 13:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.