I have been at this for weeks and need some direction. I am not using MongoDB or Phoenix, etc. I am using php (Laravel) and the core of my data is JSON. I want to save data right from javascript. So user's data is saving locally in pouchdb, one database per user solution, and synced to a remote pouchdb on a couchdb Bitnami AWS (Amazon Web Server). However, I need authentication to reference that remote pouchdb. There is proxy authentication. I use Curl on Windows to confirm it works so I must have configured it correctly:
curl -X GET "http://127.0.0.1:5984/userdb-7374657665" -H "X-Auth-CouchDB-UserName:steve" -H "X-Auth-CouchDB-Roles:users" -H "X-Auth-CouchDB-Token:a615eaf122de48804df2e554ec63cb6b3014eb4d" -H "Content-Type: application/json; charset=utf-8"
I didn't find this in the API documentation and I understand it can't work due to how security controlled in javascript. The person who posted this referred to "Rails or Phoenix":
remoteDb = new PouchDB("http://localhost:5984/userdb-7374657665", {
skipSetup: true, //Database is created when user is created
ajax: {
headers: {
'X-Auth-CouchDB-UserName':'steve',
'X-Auth-CouchDB-Roles':'users',
'X-Auth-CouchDB-Token':'a615eaf122de48804df2e554ec63cb6b3014eb4d',
'Content-Type':'application/json; charset=utf-8'
}
}
})
.on('error', function (err) {
console.log('error', err);
});
Note I used php to get the database name that was created when the user is created: $user_db = "userdb-" . bin2hex($user_name);
I also figured out the Token using php:
$hash = hash_hmac("sha1", $user_name, $secret);