I'm trying to get basic http authentication working on my Rails app. I'm offering a simple REST interface served by a Rails server, only xml/json output.
Every method needs authentication, so I put the authenticate filter in 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
Even with having the method return true, I'm receiving a 401 from the server:
$ 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.
If I'm explicitly returning true, yet getting served a 401.