CouchDB使用AngularJS登录:auth cookie仅为/ _session发送 [英] CouchDB sign-in with AngularJS: auth cookie sent for /_session only

查看:131
本文介绍了CouchDB使用AngularJS登录:auth cookie仅为/ _session发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上一篇文章 -







在学习Angular和CouchDB时,我遇到了死锁。



我做错了什么?我不想隐藏couchdb背后的东西与自定义auth - 太复杂,不是一个好的方法,我想。



UPD:获取 Cookie 头也失败 - 它不能在中使用HttpPromise.success(function(data,status,headers,config)) headers 。我试图得到它像 headers(Set-Cookie) - 没有运气。



在couchdb配置中可能出现错误?我已将其上传到pastebin

解决方案


  1. 检查CORS是否启用( * c>在我的原因)

  2. 在配置中检查 cors / credentials li>在 $ http
  3. 中使用 {withCredentials:true}

    现在它工作。


    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.

    解决方案

    1. Check CORS to be enabled (* in my cause)
    2. Check cors/credentials in config, it must be true
    3. Use {withCredentials:true} in Angular $http

    Now it works.

    这篇关于CouchDB使用AngularJS登录:auth cookie仅为/ _session发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆