Tuesday, October 30, 2007

HTTP basic authentication

HTTP basic authentication can be done in old rails versions through this plugin.
class ApplicationController < ActionController::Base
htpasswd :user => 'username', :pass => 'secret'
end
Edge rails has its own HttpAuthentication::Basic module:
class ApplicationController < ActionController::Base
USERNAME, PASSWORD = 'username', 'secret'
before_filter :basic_http_authentication
private
def basic_http_authentication
authenticate_or_request_with_http_basic do |username, password|
username == USERNAME and password == PASSWORD
end
end
end


I haven't tried the edge rails version though.

No comments: