Couchdb Can';无法使数据库身份验证正常工作
我已经尝试了许多配置,但未能通过Karma/Jasmine单元测试。你知道我错过了什么吗 运行CouchDb 1.6.1。Jasmine单元测试正在IntelliJ IDEA内部运行Couchdb Can';无法使数据库身份验证正常工作,couchdb,pouchdb,Couchdb,Pouchdb,我已经尝试了许多配置,但未能通过Karma/Jasmine单元测试。你知道我错过了什么吗 运行CouchDb 1.6.1。Jasmine单元测试正在IntelliJ IDEA内部运行 describe("CouchDb Auth") it("Test login", function (done) { var auth = { username: 'demo', password: 'omed' } var url = 'htt
describe("CouchDb Auth")
it("Test login", function (done) {
var auth = {
username: 'demo',
password: 'omed'
}
var url = 'http://127.0.0.1:5984/demo';
var ajaxOpts = {
headers: {
// 'Access-Control-Allow-Credentials': 'true',
'Authorization': 'Basic ' + window.btoa(auth.username + ':' + auth.password),
}
};
var db = new PouchDB(url, {skipSetup: true});
db.login(auth.username, auth.password, ajaxOpts)
.then(function(res) {
console.log(res);
done();
})
.catch(function(err) {
console.log(err);
done('Failed to login');
});
});
});
local.ini
文件:1.6.1
[couchdb]
;max_document_size = 4294967296 ; bytes
uuid = 3fe8f6afb42b8fde93b8b66818b3476c
[httpd]
bind_address = 0.0.0.0
enable_cors = true
; Uncomment next line to trigger basic-auth popup on unauthorized requests.
WWW-Authenticate = Basic realm="administrator"
; WWW-Authenticate = Other realm="app"
[cors]
; You can’t set origins: * and credentials = true at the same time.
credentials = true
; List of origins separated by a comma, * means accept all
; Origins must include the scheme: http://example.com
origins = http://localhost:9876
; List of accepted headers separated by a comma
headers = accept, authorization, content-type, origin, referer, cache-control, x-requested-with, x-csrf-token
; List of accepted methods
methods = GET, PUT, POST, HEAD, DELETE
[couch_httpd_auth]
secret = somesecretstuff
require_valid_user = true
[log]
level = debug
[ssl]
;cert_file = /full/path/to/server_cert.pem
;key_file = /full/path/to/server_key.pem
;password = somepassword
; set to true to validate peer certificates
verify_ssl_certificates = false
; Path to file containing PEM encoded CA certificates (trusted
; certificates used for verifying a peer certificate). May be omitted if
; you do not want to verify the peer.
;cacert_file = /full/path/to/cacertf
; The verification fun (optional) if not specified, the default
; verification fun will be used.
;verify_fun = {Module, VerifyFun}
; maximum peer certificate depth
ssl_certificate_max_depth = 1
[vhosts]
[update_notification]
[admins]
;admin = mysecretpassword
; demo = omed
demo = -pbkdf2-606718f546624acae3a7ed561540352921281e7c,a1d619524376dfbd0f8f6547856d74eb,10
PockDB身份验证实际上设计为使用cookie身份验证,而不是HTTP身份验证(即
授权
头)。调用db.login()
应该足够好了,因为它会为您设置cookie
如果您不确定失败的原因,我建议您在自己的浏览器中针对自己的CouchDB运行PockDB身份验证测试套件,这样您就可以尝试找出问题是否出在您的Nginx层、CouchDB配置、PockDB身份验证配置等方面。要做到这一点,只需:
git clone https://github.com/nolanlawson/pouchdb-authentication.git
cd pouchdb-authentication
npm install
npm run dev
然后在浏览器中打开。它将尝试使用localhost:5984进行身份验证。HTTP身份验证 因此,我们应该这样做
var ajaxOpts = {
auth: {
username:'...',
password:'...'
}
};
在phonegap上工作,没有cookies。谢谢将运行您的单元测试。我刚刚重新安装了CouchDb服务器。我正在编写小的增量单元测试,但您的测试套件听起来更智能。再次感谢!希望有一天我能亲自和你握手。我基于你的示例编写了这段代码,它在第一次调用时使用了额外的基本身份验证,以避免弹出痛苦。是的。。都做了。这很可能是服务器配置问题。
var ajaxOpts = {
auth: {
username:'...',
password:'...'
}
};