previous帖子 - 1 ,的 2
我现在拥有的一切:AngularJS应用有两个控制器。第一部作品使用CouchDB文件和第二执行登录请求 example.com/demo/_session
。
当我打开应用程序,我不能做使用CouchDB编辑(第一控制器),因为一些动作,我仅限于登录的用户。在第二个控制器我在 $ HTTP
发送简单的POST,它会返回仅HTTP
(所以没有饼干有魔力)AUTH的cookie AuthSession
。势必CouchDB的地址,在理论上,任何请求,从页面到CouchDB的地址,那个cookie中必须包含该cookie也。
但是,这没有发生。没有人呼吁CouchDB的,除了调用 / _会议
带有 AuthSession
的cookie。例如。 example.com/demo/_session
与 AuthSession
和 example.com/demo/records越来越
不是
在学习角和CouchDB的我来到了僵局。
我在做什么错?我并不想隐藏背后的东西定制权威性CouchDB的 - 太复杂,不是一个好办法,我觉得
UPD:获得设置Cookie
头也失败 - 在 HttpPromise.success它不可用(功能(数据,状态,头,配置) )
标题
。我试图得到它像标题(设置Cookie)
- 没有运气。
也许有些不对劲CouchDB中配置?我上传到引擎收录。
解决方案 检查CORS启用( *
在我的事业)检查 CORS /凭证
在配置,它必须是真实的使用 {withCredentials:真正}
在角 $ HTTP
现在它的作品。
Previous posts — 1 , 2
What I have now: AngularJS app with two controllers. First works with CouchDB documents and the second perform sign-in requests to example.com/demo/_session
.
When I open application, I can't do editing with couchdb (in first controller), because some actions I've limited to logged users only. In second controller I'm sending simple POST over $http
, which return Http-only
(so no cookie magic there) auth cookie AuthSession
. That cookie bound to couchdb address and in theory any request from page to couchdb address must contain that cookie also.
But this no happens. No one call to couchdb, except calls to /_session
comes with AuthSession
cookie. E.g. example.com/demo/_session
getting with AuthSession
and example.com/demo/records
not.
In learning Angular and CouchDB I came to deadlock.
What I'm doing wrong? I do not want to hide couchdb behind something with custom auth — too complex and not a good way, I think.
UPD: Getting Set-Cookie
header also fails — it not available in HttpPromise.success(function (data, status, headers, config))
headers
. I'm tried to get it like headers("Set-Cookie")
— no luck.
Maybe something wrong in couchdb configuration? I've uploaded it to pastebin.
解决方案 Check CORS to be enabled (*
in my cause)
Check cors/credentials
in config, it must be true
Use {withCredentials:true}
in Angular $http
Now it works.