Reputation: 1702
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...
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:
cors section:
couch_httpd_auth section:
The security dialog for this database looks like...
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 :-/
Upvotes: 1
Views: 1080
Reputation: 1702
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
});
},
Upvotes: 3