首页 > 解决方案 > CouchDB 无法获取非管理员用户的 cookie 身份验证会话

问题描述

对于管理员用户:

$ curl -X POST localhost:5984/_session -d "username=admin&password=admin"  
{"ok":true,"name":"admin","roles":["_admin"]}  
$ curl -vX GET localhost:5984/_session --cookie AuthSession=YWRtaW...  
{"ok":true,"userCtx":{"name":"admin","roles":["_admin"]},"info":{"authentication_db":"_users","authentication_handlers":["cookie","default"],"authenticated":"cookie"}}

但对于普通用户:

$ curl -vX POST localhost:5984/_session -d "username=user&password=123"
{"ok":true,"name":"user","roles":["users"]}  
$  curl -vX GET localhost:5984/_session --cookie AuthSession=ZGlqbzo...  
{"ok":true,"userCtx":{"name":null,"roles":[]},"info":{"authentication_db":"_users","authentication_handlers":["cookie","default"]}}

当我通过 iron-ajax 元素或简单地从 chrome 执行 XmlHttpRequest 时,也会发生同样的事情。我究竟做错了什么?

CouchDB 版本:2.1.1
配置:

[chttpd]
  bind_address = 0.0.0.0
  port = 5984
  authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
[httpd]
  enable_cors = true
[couch_httpd_auth]
  allow_persistent_cookies = true
  timeout = 60000
[cors]
  credentials = true
  origins = *
  headers = accept, authorization, content-type, origin, referer
  methods = GET, PUT, POST, HEAD, DELETE

标签: couchdbcookie-authentication

解决方案


当我从我的 local.ini 中删除时问题消失了

authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}

因为我使用了不正确的处理程序:couch_httpd_auth在配置中chttpd,当该处理程序仅被编写为与原始couch_httpd模块一起使用时


推荐阅读