security - CouchDB 访问被拒绝重定向

标签 security authentication redirect couchdb access-denied

当我输入安全数据库的 URL 时,它会在页面上显示以下消息:

{"error":"unauthorized","reason":"You are not authorized to access this db."}

尽管这条消息肯定能说明问题,但我更愿意将用户重定向到不同的页面,例如登录页面。我尝试更改沙发配置中的 authentication_redirect 选项,但没有成功。我该怎么做呢?

最佳答案

身份验证重定向仅在客户端明确接受时才有效 text/html内容类型(例如发送 Accept: text/html header ):

GET /db HTTP/1.1
Accept: text/html
Host: localhost:5984

在这种情况下,CouchDB 将发送 HTTP 302响应而不是 HTTP 401重定向到您的身份验证表单,指定为 authentication_redirect配置选项:
HTTP/1.1 302 Moved Temporarily
Cache-Control: must-revalidate
Content-Length: 78
Content-Type: text/plain; charset=utf-8
Date: Tue, 24 Sep 2013 01:32:40 GMT
Location: http://localhost:5984/_utils/session.html?return=%2Fdb&reason=You%20are%20not%20authorized%20to%20access%20this%20db.
Server: CouchDB/1.4.0 (Erlang OTP/R16B01)

{"error":"unauthorized","reason":"You are not authorized to access this db."}

Othewise CouchDB 不知道请求是由人类从浏览器发送的还是由应用程序库发送的。在最后一种情况下,重定向到 HTML 表单而不是引发 HTTP 错误不是合适的解决方案。

关于security - CouchDB 访问被拒绝重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18966385/

相关文章:

javascript - window.location.href 的奇怪 JavaScript 行为和程序流程

security - 为什么 Magento 每个 session 使用 2 个 cookie?

azure - Web API 身份验证最佳实践

php - PHP 中的 JWT(JSON Web token ),无需使用第 3 方库。怎么签?

php - 在 php 中发送 SOAP 身份验证 header 的问题

php - 如何使用 php 从 url 和 301 重定向获取变量?

security - 加密 Web.Config 中的连接字符串 - 为什么?

linux - lfd (csf) - 防止来自某些用户的 SSH 登录警报

c# - 不影响 TortoiseSVN 凭据的 SharpSVN 身份验证

javascript - MVC3 - Javascript 中的动态 URL 重定向