针对外部服务器验证 CouchDB 用户
Authenticating a CouchDB user against an external server
我有以下设置:
- 存储用户和处理身份验证的 CouchDB 数据库;每个用户创建一个数据库
- 使用 PouchDB 通过 pouchdb-authentication
进行同步和身份验证的 Web 应用程序
- REST API 服务器,从 Web 应用程序获取请求并访问 CouchDB
现在,REST API 具有 CouchDB 的管理员访问权限,因此当它收到请求时,它需要进行某种形式的身份验证以确保发送者有权访问他声称有权访问的数据库.由于我使用持久会话,网络应用程序始终不知道用户密码(除非我将其存储在本地存储中——这显然是个坏主意)。会话 cookie 是 HttpOnly
,所以我无法访问它。
在这种情况下,验证对 API 请求的最佳方式是什么?
加密您需要的所有内容并将其作为 base64 添加到 cookie session。以下是顺序...
1. WebApp: Send username and password
2. REST: Authenticate this using couch.
3. REST: Encrypt the session along with username password and create cookie, then base64 result.
4. REST: Send cookie to WebApp.
5. WebApp: Alway sends cookie back to REST layer.
6. REST layer has everything it needs to authenticate the user.
在上面,REST 层将状态传递给 WebApp,并从 WebApp 获取所需的状态。客户端无法解密它,所以它是安全的。然后,客户端将此令牌作为 cookie 传递回 REST 层,然后使用它来获取需要进行身份验证的详细信息。
您可以很容易地加密几百个字节而不是 运行 到任何 header 或
cookie 大小限制。不要在加密之前或之后压缩它,之前
出于安全原因以及之后因为加密数据不能很好地压缩。如果有人担心性能,那么就对它进行基准测试,但我已经将它用于比 Rust 慢几个数量级的语言。上面的一个变体是使用 memcached ie...
1. WebApp: Send username and password
2. REST: Authenticate this using couch.
3. REST: Store Couch session in memcahed along with username password and create cookie. The cookie is the key to memcached.
4. REST: Send cookie to WebApp.
5. WebApp: Alway sends cookie back to REST layer.
6. REST: Get details from memcached.
我已经通过 headers 和 cookie 使用了这种技术,它的效果非常好。我假设您正在使用一些东西来防止 XSRF 等。
您可以混合搭配以上内容以满足您的应用需求。
我有以下设置:
- 存储用户和处理身份验证的 CouchDB 数据库;每个用户创建一个数据库
- 使用 PouchDB 通过 pouchdb-authentication 进行同步和身份验证的 Web 应用程序
- REST API 服务器,从 Web 应用程序获取请求并访问 CouchDB
现在,REST API 具有 CouchDB 的管理员访问权限,因此当它收到请求时,它需要进行某种形式的身份验证以确保发送者有权访问他声称有权访问的数据库.由于我使用持久会话,网络应用程序始终不知道用户密码(除非我将其存储在本地存储中——这显然是个坏主意)。会话 cookie 是 HttpOnly
,所以我无法访问它。
在这种情况下,验证对 API 请求的最佳方式是什么?
加密您需要的所有内容并将其作为 base64 添加到 cookie session。以下是顺序...
1. WebApp: Send username and password
2. REST: Authenticate this using couch.
3. REST: Encrypt the session along with username password and create cookie, then base64 result.
4. REST: Send cookie to WebApp.
5. WebApp: Alway sends cookie back to REST layer.
6. REST layer has everything it needs to authenticate the user.
在上面,REST 层将状态传递给 WebApp,并从 WebApp 获取所需的状态。客户端无法解密它,所以它是安全的。然后,客户端将此令牌作为 cookie 传递回 REST 层,然后使用它来获取需要进行身份验证的详细信息。
您可以很容易地加密几百个字节而不是 运行 到任何 header 或 cookie 大小限制。不要在加密之前或之后压缩它,之前 出于安全原因以及之后因为加密数据不能很好地压缩。如果有人担心性能,那么就对它进行基准测试,但我已经将它用于比 Rust 慢几个数量级的语言。上面的一个变体是使用 memcached ie...
1. WebApp: Send username and password
2. REST: Authenticate this using couch.
3. REST: Store Couch session in memcahed along with username password and create cookie. The cookie is the key to memcached.
4. REST: Send cookie to WebApp.
5. WebApp: Alway sends cookie back to REST layer.
6. REST: Get details from memcached.
我已经通过 headers 和 cookie 使用了这种技术,它的效果非常好。我假设您正在使用一些东西来防止 XSRF 等。
您可以混合搭配以上内容以满足您的应用需求。