Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Created June 29, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/535f48fb4583425049c3 to your computer and use it in GitHub Desktop.
Save shankardevy/535f48fb4583425049c3 to your computer and use it in GitHub Desktop.
Sinatra app for testing digest auth
# 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