#-- # Copyright (C) 2006 Dimitrij Denissenko # Please read LICENSE document for more information. #++ require 'base64' module Retrospectiva module Extension module HTTPAuthentication def self.included(base) #:nodoc: base.send(:include, InstanceMethods) end module InstanceMethods protected def before_authenticate unless session[:user_id].is_a?(Integer) request_keys = [ 'REDIRECT_REDIRECT_X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'HTTP_AUTHORIZATION'] if auth_key = request_keys.find {|key| request.env.has_key?(key) } method, data = request.env[auth_key].to_s.split(" ", 2) credentials = Base64.decode64(data).to_s.split(":")[0..1] User.current = User.authenticate(:login => credentials[0], :password => credentials[1]) session[:user_id] = User.current.id if User.current end end end end end end end ActionController::Base.send(:include, Retrospectiva::Extension::HTTPAuthentication)