首页 > 解决方案 > cochdb 权限角色始终“未授权”

问题描述

我尝试使用 CouchDB 进行用户/角色身份验证(基于会话),但是一旦我在数据库中输入角色,所有用户和角色都可以访问数据库 -> 未经授权。

获取会话:

发布 http://myhost:1234/ _session

它返回(userCtx 对象):

{
    "ok": true,
    "name": "some_user_name",
    "roles": [
        "developers"
    ]
}

然后我将角色添加到数据库中:

把 http://myhost:1234/database/ _security

{
    "admins": {
        "names": [],
        "roles": []
    },
    "members": {
        "names": [],
        "roles": [
            "developers"
        ]
    }
}

它返回{"ok":true},我也可以在 fauxton 中看到权限。

当我现在尝试使用

获取http://myhost:1234/database/_all_docs

它返回:

{
    "error": "unauthorized",
    "reason": "You are not authorized to access this db."
}

标签: authenticationpermissionscouchdbfauxton

解决方案


如果您使用的是 Postman,请在标题中添加以下键值

"Content-Type": "application/json",
  Accept: "application/json",
  Authorization: "Basic " + btoa("YOUR_ADMIN_USER:YOUR_PASSWORD")

推荐阅读