Skip to content

Instantly share code, notes, and snippets.

@totem3
Created June 12, 2017 23:25
Show Gist options
  • Save totem3/b3babdb7c0bd49a7ed8f70d18fa9b257 to your computer and use it in GitHub Desktop.
Save totem3/b3babdb7c0bd49a7ed8f70d18fa9b257 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment