我现在拥有的是:带有两个 Controller 的 AngularJS 应用程序。首先处理 CouchDB 文档,然后对 example.com/demo/_session
执行登录请求。
当我打开应用程序时,我无法使用 couchdb 进行编辑(在第一个 Controller 中),因为某些操作我仅限于登录用户。在第二个 Controller 中,我通过 $http
发送简单的 POST,它返回 Http-only
(所以那里没有 cookie 魔法)auth cookie AuthSession
。该 cookie 绑定(bind)到 couchdb 地址,理论上从页面到 couchdb 地址的任何请求也必须包含该 cookie。
但这没有发生。没有人调用 couchdb,除了调用 /_session
带有 AuthSession
cookie。例如。 example.com/demo/_session
使用 AuthSession
和 example.com/demo/records
不是。
在学习 Angular 和 CouchDB 时,我陷入了僵局。
我做错了什么?我不想将 couchdb 隐藏在带有自定义身份验证的东西后面——我认为这太复杂而且不是一个好方法。
更新:获取 Set-Cookie
header 也失败了——它在 HttpPromise.success(function (data, status, headers, config))
headers 中不可用
。我试图像 headers("Set-Cookie")
那样获取它——没有运气。
也许 couchdb 配置有问题?我有 uploaded it to pastebin .
最佳答案
- 检查要启用的 CORS(
*
在我的原因中) - 检查配置中的
cors/credentials
,必须为真 - 在 Angular
$http
中使用{withCredentials:true}
现在可以了。
关于javascript - 使用 AngularJS : auth cookie sent for/_session only 登录 CouchDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34314372/