Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 http_basic_authenticate_with only in production environment?

is there a way to only use

http_basic_authenticate_with :name => 'user', :password => 'secret'

when the server is running on production mode?

like image 471
Cojones Avatar asked Jan 05 '12 11:01

Cojones


3 Answers

Yes, try:

class ApplicationController < ActionController::Base
  before_filter :authenticate

  def authenticate
    if Rails.env.production?
      authenticate_or_request_with_http_basic do |username, password|
        username == "user" && password == "%$§$§"
      end 
    end
  end
end
like image 85
Tim Brandes Avatar answered Nov 10 '22 09:11

Tim Brandes


Just add this to your example

http_basic_authenticate_with :name => 'user', :password => 'secret' if Rails.env.production?
like image 33
bokor Avatar answered Nov 10 '22 10:11

bokor


authenticate_or_request_with_http_basic do |username, password|
  username == "user" && password == "secret"
end if Rails.env.production?
like image 27
amiuhle Avatar answered Nov 10 '22 11:11

amiuhle