javascript - 使用 AngularJS : auth cookie sent for/_session only 登录 CouchDB

标签 javascript angularjs authentication cookies couchdb

以前的帖子 — 1 , 2

我现在拥有的是:带有两个 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 使用 AuthSessionexample.com/demo/records 不是。

request

got http cookie

no cookies for bad kids?

在学习 Angular 和 CouchDB 时,我陷入了僵局。

我做错了什么?我不想将 couchdb 隐藏在带有自定义身份验证的东西后面——我认为这太复杂而且不是一个好方法。

更新:获取 Set-Cookie header 也失败了——它在 HttpPromise.success(function (data, status, headers, config)) headers 中不可用。我试图像 headers("Set-Cookie") 那样获取它——没有运气。

也许 couchdb 配置有问题?我有 uploaded it to pastebin .

最佳答案

  1. 检查要启用的 CORS(* 在我的原因中)
  2. 检查配置中的cors/credentials,必须为真
  3. 在 Angular $http 中使用 {withCredentials:true}

现在可以了。

关于javascript - 使用 AngularJS : auth cookie sent for/_session only 登录 CouchDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34314372/

相关文章:

javascript - 面板内的 Sencha touch 2 列表

javascript - React-Strap 的日期选择器

javascript - 如何获取给定表单详细信息的嵌套 json 对象?

asp.net - 静态文件的 IIS 500.0 AuthenticateRequest 错误

javascript - 是否可以使用Javascript自动登录链接

javascript - typescript 中的绑定(bind)函数和 this

javascript - 如果指定了绝对位置和 overflow-x hidden,则无法滚动到元素

javascript - AngularJS HTTP GET 请求不起作用

c# - Asp.NET 登录控件 : Dealing with brackets in passwords

javascript - 从 JavaScript 数组中删除元素