1

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");
    },

In my controller I have...

    $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.

Can you see what I'm doing wrong?

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

1
  • So are all the CouchDB experts on vacation or have I said something wrong and/or dumb? :-/
    – Locohost
    Sep 14, 2013 at 14:18

1 Answer 1

3

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
        });
    },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.