Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between http_basic_authenticate_with AND authenticate_or_request_with_http_basic?

Tags:

What is the difference between

http_basic_authenticate_with() 

and

authenticate_or_request_with_http_basic() 

methods?

Thanks for your full explanation.

like image 731
Douglas Avatar asked Mar 27 '13 15:03

Douglas


1 Answers

From what I can understand from the docs, http_basic_authenticate_with acts as a before filter which accepts a name and password such as

http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index 

Whereas authenticate_or_request_with_http_basic accepts a block allowing for you to insert some code to determine whether they should be authenticated (documentation). E.g.

before_filter :authenticate  def authenticate   authenticate_or_request_with_http_basic('Administration') do |username, password|     ActiveSupport::SecurityUtils.secure_compare(username, "admin") &&     ActiveSupport::SecurityUtils.secure_compare(password, "password")   end end 
like image 89
chrisbulmer Avatar answered Oct 12 '22 20:10

chrisbulmer