Ruby on Rails :: How to add HTTP basic authentication to your staging app in Heroku
First you set up your staging app following the Heroku’s guide forĀ Managing Multiple Environments for an App
Then edit the config/environments/staging.rb:
#config/environments/staging.rb
MyApp::Application.configure do
# Basic authentication
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "My App") do |u, p|
[u, p] == [ENV['HTTP_USER'], ENV['HTTP_PASSWORD']]
end
...
And finally set the config vars:
heroku config:add HTTP_USER='foo' HTTP_PASSWORD='bar' -a myapp-staging