Created
June 29, 2015 15:57
-
-
Save shankardevy/535f48fb4583425049c3 to your computer and use it in GitHub Desktop.
Sinatra app for testing digest auth
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
# sinatra app | |
# config.ru | |
# To start the server, run | |
# $ rackup config.ru | |
# visit localhost:9292/digest | |
require 'sinatra/base' | |
class Public < Sinatra::Base | |
get '/' do | |
"public" | |
end | |
end | |
class ProtectedBasic < Sinatra::Base | |
use Rack::Auth::Basic, "Protected Area" do |username, password| | |
username == 'foo' && password == 'bar' | |
end | |
get '/' do | |
"secret" | |
end | |
get '/another' do | |
"another secret" | |
end | |
end | |
class ProtectedDigest < Sinatra::Base | |
get '/' do | |
"secret" | |
end | |
get '/another' do | |
"another secret" | |
end | |
def self.new(*) | |
app = Rack::Auth::Digest::MD5.new(super) do |username| | |
{'foo' => 'bar'}[username] | |
end | |
app.realm = 'Protected Area' | |
app.opaque = 'secretkey' | |
app | |
end | |
end | |
run Rack::URLMap.new({ | |
"/" => Public, | |
"/basic" => ProtectedBasic, | |
"/digest" => ProtectedDigest | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment