因此,根据这里的nano文档:https://github.com/dscape/nano#using-cookie-authentication,您可以通过以下内容对用户进行身份验证:(在coffeescript中)
nano = require('nano') 'http://localhost:5984'
nano.auth username, password我很好,我可以得到正确的反应,我有麻烦的是,之后该怎么做。我最初的想法是执行以下操作(通过futon使用管理员的用户名和密码设置):
nano = require('nano') 'http://localhost:5984'
nano.auth username, password
nano.db.create 'test', (err, body) -> #err here is always [Error: you are not a server admin.]如果调试从nano.auth返回的错误、正文和标头,则会得到:
err: null
body: { ok: true, name: null, roles: [ '_admin' ] }
header: { 'set-cookie': [ 'AuthSession=bm9kZV9hZG1pbjo1MzRFMTEwQzoGNe9XUrMu5IKYPK3BP3GQyHeRWQ; Version=1; Path=/; HttpOnly' ],
date: 'Wed, 16 Apr 2014 05:11:40 GMT',
'content-type': 'text/plain; charset=utf-8',
'cache-control': 'must-revalidate',
'status-code': 200,
uri: 'http://127.0.0.1:5984/_session' }在我的测试中,我也尝试过以下似乎也不起作用的方法
nano = require('nano') "#{prefix}://#{security.couchdb.url}"
cookie = ''
nano.auth security.couchdb.admin_user.username, security.couchdb.admin_user.password, (err, response, headers) ->
console.log "Nano_admin Setup"
console.log err
console.log response
console.log headers
cookie = headers['set-cookie']
nano = require('nano')
url: "#{prefix}://#{security.couchdb.url}"
cookie: "AuthSession=#{cookie}"
nano.db.create 'test', (err, body) -> #err here is always [Error: you are not a server admin.]有人能指出我哪里出了错/误解了吗?
发布于 2014-04-16 06:22:10
我想出来了-我现在觉得很傻。请记住,node.js是异步的。
正确的做法:
nano = require('nano') 'http://localhost:5984'
nano.auth username, password, (err, response, headers) ->
nano = require('nano')
url: 'http://localhost:5984'
cookie: headers['set-cookie']
nano.db.create 'test', (err, body) -> https://stackoverflow.com/questions/23100132
复制相似问题