require "warden"
class App
def call(env)
env['warden'].authenticate!
[200, {'Content-Type' => 'text/plain'}, ['OK']]
end
end
Warden::Strategies.add(:password) do
def valid?
params["username"] && params["password"]
end
def authenticate!
if params["username"] == "admin" and params["password"] == "admin"
success!("success")
else
fail!
end
end
end
use Rack::Session::Cookie, :secret => "replace this with some secret key"
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = ->(env) {[401, {}, ['Unauthorized']]}
end
run App.new