Skip to content

Instantly share code, notes, and snippets.

@gaganawhad
Last active August 29, 2015 14:06
Show Gist options
  • Save gaganawhad/2eac66aec58340f41959 to your computer and use it in GitHub Desktop.
Save gaganawhad/2eac66aec58340f41959 to your computer and use it in GitHub Desktop.
Setting up Rack::Auth::Digest::MD5 middleware in Rails
#References:
# https://github.com/zufrieden/stopwatch/blob/master/config/environments/staging.rb
# http://rubydoc.info/github/rack/rack/Rack/Auth/Digest/MD5
# http://www.sitepoint.com/understanding-http-digest-access-authentication/
# http://levick.tumblr.com/post/65244327897/encrypted-http-basic-auth-in-rails-digest-auth
#"Staging" is the 'realm',
# SecureRandom.base64 is the opaque
# "foo" is the username
# "bar" is the password
# Rails will automatically generate the nonce on each request
# The browser will generate the md5 hash as response for digest auth automatically
config.middleware.insert_before 'Rack::Lock', 'Rack::Auth::Digest::MD5', 'Staging', 'opaque' do |user|
{"foo" => "bar"}[user]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment