I want to set up a private staging server on heroku using simple http authentication. Is that possible?
相关问题
- Angular RxJS mergeMap types
- java client program to send digest authentication
- Google Apps Script: testing doPost() with cURL
- How to instantiate Http service in main.ts manuall
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- Django/Heroku: FATAL: too many connections for rol
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- Is a unicode user agent legal inside an HTTP heade
Absolutely. The simplest solution is to just put something in your application controller that uses Rails's built in basic auth support (see here: http://railscasts.com/episodes/82-http-basic-authentication) and just wrap it in a conditional for your
Rails.env
. Note that on Heroku, by default the RAILS_ENV is set to production, but you can change this for your non-production apps usingheroku config
(http://docs.heroku.com/config-vars).You could also consider installing some roadblock-style Rack middleware, but I'd just go with the above.
On Rails4, I got "No such middleware to insert after: Rack::Lock" error. Replace Adam's code to the below:
See: http://www.intridea.com/blog/2013/6/4/tips-and-tricks-for-deploying-rails-4-apps-on-heroku
A cleaner way is to just drop in a couple lines of Rack middleware into your staging environment config, leaving controller logic alone:
This tip courtesy of Ole Morten Amundsen. More info plus Heroku password specification:
http://olemortenamundsen.wordpress.com/2011/04/05/ruby-secure-staging-environment-of-your-public-app-from-users-and-bots/
There is a nice heroku add-on that uses Mozilla Persona for authentication. It's free for low-volume sites (under 10,000 authentications per month):
https://addons.heroku.com/wwwhisper
Very easy to install and configure.
Another way to do it using the application_controller.rb:
and then you need to export your values: for development:
For heroku:
Now when the window prompt you should enter for user/password => test/test.
That's it hope you find it useful.
Updated answer for Rails 5. In your
config/application.rb
or selected environment config:Additionally it's been pointed out in Ole's blog post to use ENV vars. I'd add that defaulting to a random password is a good idea in case the env var is not set: