Skip to content

Instantly share code, notes, and snippets.

@nabeken
Created April 29, 2010 14:33
Show Gist options
  • Save nabeken/383682 to your computer and use it in GitHub Desktop.
Save nabeken/383682 to your computer and use it in GitHub Desktop.
helpers do
def protected!
response = callcc do |cont|
auth = Rack::Auth::Digest::MD5.new(cont, "Administrator only") do |username|
"password" # username is ignored, or Password is always 'password' in this example.
end
auth.opaque = $$.to_s
auth.call(request.env)
end
throw(:halt, response) if response.first == 401
end
end
# Example:
#
# get '/admin/?' do
# protected!
# something to do...
# end
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment