我试图让我的Rails应用程序工作的基本http身份验证。我提供了一个由Rails服务器提供的简单REST接口,只有xml/json输出。Rails 2.x http基本身份验证
每一个方法需要进行认证的,所以我把在ApplicationController中的身份验证过滤器:
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |u, p|
true
end
end
end
即使具有方法返回true,我从服务器接收401:
$ curl http://127.0.0.1:3000/myresource/1.xml -i
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
WWW-Authenticate: Basic realm="Application"
X-Runtime: 1
Content-Type: text/html; charset=utf-8
Content-Length: 27
Server: WEBrick/1.3.1 (Ruby/1.9.1/2010-01-10)
Date: Thu, 03 Jun 2010 02:43:55 GMT
Connection: Keep-Alive
HTTP Basic: Access denied.
如果我明确返回true,但获得服务401.
是否有反正我可以在用户不提供登录名/密码对的情况下显示一个XML生成器视图?我想给出一个描述性的错误信息。 – randombits 2010-06-03 03:01:23