我在COUCHDB
上使用CLOUDANT
,
只要我在db.allDocs
CLOUDANT
内部将_reader权限设置为未经身份验证的连接,就可以在“测试”数据库上执行COUCHDB INTERFACE
。
这是我的代码:
var remoteDatabase = "https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/test";
var db = new PouchDB(remoteDatabase, {skip_setup: true});
db.logIn('jose', 'password').then(function (batman) {
console.log("I'm jose .");
db.allDocs({include_docs: true});
});
但是,只要我只允许JOSE访问'TEST'数据库,我就会在导航器控制台中遇到此错误:
POST https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/_session // THIS IS OK, it auth well !
I'm josé.
GET https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/test/_all_docs?include_docs=true
[HTTP/2.0 401 Unauthorized 43ms]
即使这样也不行,直接在导航器内部:
https://jose:password@1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/test
在我的cloudant数据库'test'上设置的权限:
Cloudant couchdb permissions on the TEST Db
这是我的_users数据库:
Cloudant上的José用户参数:
Jose parameters on cloudant, he has the reader role
控制台错误消息:
Firefox saying that José has no rights to read while it is not true
Please notice that auth is currently working with the josé user
读者身份验证中缺少下划线,应该是_reader,但是我无法在cloudant _user db中设置它,它返回了错误。
编辑1: 刚刚将jose用户添加到了我的测试数据库中,它现在可以在导航器中使用以下命令进行操作:
https://jose:password@1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/test/_all_docs
但是pouchDb代码仍然无法运行,出现401错误!
编辑2:已解决!
由于此链接,我找到了解决方案:
https://github.com/pouchdb-community/pouchdb-authentication/issues/204 db.logIn函数出问题了。
这是我的新工作代码:
var remoteDatabase = "https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/test";
var db = new PouchDB(remoteDatabase, {skip_setup: true,"auth": {"username":"jose", "password": "password"}});
db.allDocs({include_docs: true});