In Ruby on Rails, what does authenticate_with_http_basic do? -


restful authentication uses authenticate_with_http_basic, search on net can find many pages no description. on official http://api.rubyonrails.org/, can found, except again there no description, no comment, no spec.

what do? seems able use login_name , password http request , can compared login_name , encrypted_password in users table... case, why aren't there 1-line description?

this method allows implement basic http authentication (the kind little dialog box pops asking username , password). it's great way limit access development site or admin area. example:

class admincontroller < applicationcontroller   before_filter :authenticate    def authenticate     authenticate_or_request_with_http_basic('administration') |username, password|       username == 'admin' && password == 'password'     end   end end 

this function either make request basic http authentication username , password, or after has been entered, check if authentication correct. in other words function either call authenticate_with_http_basic or call request_http_basic_authentication. can read more , see more examples here. you'll call authenticate_or_request_with_http_basic instead of calling authenticate_with_http_basic or request_http_basic_authentication, since former function appropriate of latter functions.

p.s: authenticate_with_http_basic not use post variables, uses header information username , password (request.env['http_authorization']). can view more information authorization function here.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -