I have a couchDB database named "guestbook". Initially, I utilized the following code to add a user to the "_users" database:
$scope.submit = function(){
var url = "https://sub.iriscouch.com/_users/org.couchdb.user:" + $scope.name;
console.log(url);
$http({
url: url,
method: "PUT",
data: {name : $scope.name,
password: $scope.pass,
roles: [],
type: "user"
},
withCredentials: true,
headers: {"Authorization": auth_hash(adminUsername, adminPass)}
})
.success(function(data, status, headers, config){
console.log(headers);
console.log(config);
});
}
After successfully adding the user to _users, I used Futon to include that user as a member in the "_security" document of my "guestbook".
Next, when attempting to use the username and password (added as a member to the "guestbook" _security) for retrieving all documents from the "guestbook" database, I encountered an authentication error. Refer to the code below:
$scope.login = function(){
var url = "https://sub.iriscouch.com/guestbook/_all_docs";
$http({
url: url,
method: 'GET',
params: {
include_docs: true,
},
withCredentials: true,
headers: {"Authorization": auth_hash($scope.uname, $scope.upass)}
})
.success(function(data, status, headers, config){
$scope.book = data.rows;
console.log($scope.book);
});
}
function auth_hash(username, password)
{
return "Basic" +btoa(username + ":" + password);
}
However, whenever trying to access "_all_docs", I consistently receive a 401 unauthorized error. The username used for accessing has been properly added as a member in the _security documents of the guestbook database.
If anyone can assist me in identifying what might be incorrect in my approach, it would be greatly appreciated.