当我输入安全数据库的 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/