使用CouchDB的PouchDB和Cookie身份验证实际上并未登录用户 [英] PouchDB and Cookie Authentication with CouchDB not actually logging in the user

查看:150
本文介绍了使用CouchDB的PouchDB和Cookie身份验证实际上并未登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点应用程序,该应用程序将CouchDB用于数据库并在客户端上使用PouchDB。要登录,将请求发送到节点服务器,该节点服务器在将cookie发送回客户端之前,先使用CouchDB实例对用户的凭据进行身份验证。问题是,重新启动浏览器并登录后,当Pouch尝试连接到数据库时,CouchDB发送401 Unauthorized响应,浏览器显示其默认登录弹出窗口。即使AuthSession cookie在浏览器中,也会发生这种情况。

I have a node app that uses CouchDB for the database and PouchDB on the client. To log in, a request is sent to the node server, which authenticates the user's credentials with the CouchDB instance, before sending a cookie back to the client. The issue is, after restarting the browser and logging in, CouchDB sends a 401 Unauthorized response when Pouch tries to connect to the DB, and the browser brings up its default login popup. This happens even though the AuthSession cookie is in the browser.

Chrome中的完整错误是:加载资源失败:服务器响应状态为401(未经授权)http:// localhost: 5984 / user /?_ nonce = rItPZR1fgbHrwn0a

The full error in Chrome is: Failed to load resource: the server responded with a status of 401 (Unauthorized) http://localhost:5984/user/?_nonce=rItPZR1fgbHrwn0a

在Chrome弹出框中输入用户凭据并刷新页面后,将其加载为正常。转到列出的页面并输入用户凭据将提供有关用户的各种元数据。

After entering the user credentials in the Chrome pop-up box and refreshing the page, it loads as normal. Going to the page listed and entering the user credentials gives various metadata about the user.

我认为发生这种情况是因为PouchDB实际上并不使用节点服务器发送的AuthSession令牌,而是CouchDB在用户使用后为其分配的cookie。提示为401。有什么方法可以解决此问题?

I assume this is happening because PouchDB doesn't actually use the AuthSession token sent by the node server, but the cookie that is given to it by CouchDB after the user is prompted with a 401. Is there any way to get around this?

预先感谢。

推荐答案

实际上,只要在客户端上设置了cookie,PouchDB就会自动获取身份验证。我有一个插件可以证明这一点: https://github.com/nolanlawson/pouchdb-authentication 。您可以使用此插件直接与您的CouchDB对话,它肯定可以工作。也许您的Node代理没有在PouchDB和CouchDB之间传递cookie?

Actually, as long as the cookie is getting set on the client, authentication should automatically be picked up by PouchDB. I have a plugin that demonstrates this: https://github.com/nolanlawson/pouchdb-authentication. You can use this plugin to talk directly to your CouchDB and it will definitely work. Maybe your Node proxy is not passing the cookie between PouchDB and CouchDB?

这篇关于使用CouchDB的PouchDB和Cookie身份验证实际上并未登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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