jak*_*ent 4 security couchdb couchapp
我通过Couchapp部署了我的应用程序,这意味着整个应用程序都是从数据库中提供的.我不希望Couchdb数据库中的数据公开可用,因此我在为数据服务之前指定了用户必须具有的读者角色.但是,当我去申请时,我能得到的是:
{"error":"unauthorized","reason":"You are not authorized to access this db."}
Run Code Online (Sandbox Code Playgroud)
因为它甚至无法提供使用jquery.couch.js的登录页面.
关于如何提供应用内登录的任何想法(即,登录不使用Futon为需要数据读取访问权限的用户)?
此时,解决方案需要一些工作.(社区中有压力要改进这一点,但我会解释目前的答案,而不是描述提案或蒸发器.)
制作一个"欢迎垫"数据库,具有以下功能:
_security.admins = {"names":["jtsnake"], "roles":[]}_security.readers = {"names":[], "roles":[]}}有一个具有.validate_doc_update功能的设计文档.除管理员外不允许更改:
function(newDoc, oldDoc, userCtx, secObj) {
// _design/welcome_mat .validate_doc_update
if(! userCtx.name)
throw {"unauthorized": "Please log in to change the welcome mat"};
if(userCtx.roles.indexOf("_admin") === -1)
throw {"forbidden": "Only the admin can change the welcome mat"};
log("Allowing welcome mat update by: " + userCtx.name);
}
Run Code Online (Sandbox Code Playgroud)最后,将您的公共内容(例如欢迎屏幕,登录屏幕等)放在此数据库中.一旦用户登录,私有数据就可以进入私有数据库.
| 归档时间: |
|
| 查看次数: |
1125 次 |
| 最近记录: |