Created
June 12, 2017 23:25
-
-
Save totem3/b3babdb7c0bd49a7ed8f70d18fa9b257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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