Couchdb Vue.js 身份验证
Couchdb Vue.js authentication
我正在尝试将 node/express 身份验证应用程序移至 vue.js。我能够成功验证获取 200 代码。但是,从 couchdb 返回的响应不包含 "set-cookie" header,其中包含急需的 AuthSession 令牌。我在我的 Vue 组件中使用的代码是:
var reqBody = "name="+user+"&password="+pass;
var reqBodyLength = reqBody.length;
console.log(reqBodyLength);
this.$http.post('http://localhost:5984/_session/', reqBody, {headers: {'Content-Type' : 'application/x-www-form-urlencoded', 'Accept' : 'application/json'}}).then(response => {
console.log("response: " + JSON.stringify(response));
console.log("response.headers: " + JSON.stringify(response.headers));
console.log("response.headers.set-cookie: " + JSON.stringify(response.headers["set-cookie"]));
}, response => {
alert('you unauthorized, fool!')
})
有人在获取 "set-cookie" header 时遇到过问题吗?
谢谢,泰勒
Couch 的 AuthSession
是 HttpOnly cookie,因此无法通过客户端脚本访问。但是该 _session
查询应将 cookie 本身设置为浏览器,因此所有后续请求都将被授权。
顺便说一句,/_session
也接受 JSON 负载,至少在 CouchDB 1.6 中是这样,因此查询不必采用 x-www-form-urlencoded
形式。
我正在尝试将 node/express 身份验证应用程序移至 vue.js。我能够成功验证获取 200 代码。但是,从 couchdb 返回的响应不包含 "set-cookie" header,其中包含急需的 AuthSession 令牌。我在我的 Vue 组件中使用的代码是:
var reqBody = "name="+user+"&password="+pass;
var reqBodyLength = reqBody.length;
console.log(reqBodyLength);
this.$http.post('http://localhost:5984/_session/', reqBody, {headers: {'Content-Type' : 'application/x-www-form-urlencoded', 'Accept' : 'application/json'}}).then(response => {
console.log("response: " + JSON.stringify(response));
console.log("response.headers: " + JSON.stringify(response.headers));
console.log("response.headers.set-cookie: " + JSON.stringify(response.headers["set-cookie"]));
}, response => {
alert('you unauthorized, fool!')
})
有人在获取 "set-cookie" header 时遇到过问题吗?
谢谢,泰勒
Couch 的 AuthSession
是 HttpOnly cookie,因此无法通过客户端脚本访问。但是该 _session
查询应将 cookie 本身设置为浏览器,因此所有后续请求都将被授权。
顺便说一句,/_session
也接受 JSON 负载,至少在 CouchDB 1.6 中是这样,因此查询不必采用 x-www-form-urlencoded
形式。