Hunt_Jon
(Hunt Jon)
April 22, 2009, 1:47pm
1
I'm trying to HTTP Basic Authentication mentioned at
I'm trying to understand the document.
#
# On shared hosts, Apache sometimes doesn't pass authentication headers to
# FCGI instances. If your environment matches this description and you cannot
# authenticate, try this rule in your Apache setup:
#
# RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
module Basic
extend self
module ControllerMethods
def authenticate_or_request_with_http_basic(realm = "Application", &login_procedure)
authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm)
end
def authenticate_with_http_basic(&login_procedure)
HttpAuthentication::Basic.authenticate(self, &login_procedure)
end
def request_http_basic_authentication(realm = "Application")
HttpAuthentication::Basic.authentication_request(self, realm)
end
The RailsCasts sample is:
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "foo" && password == "bar"
end
end
But I would like to change "realm" as well. It looks possible in the
documentation. But I don't understand how to do it because my
understanding of block in Ruby isn't good.
Can anybody give me a sample that uses "realm"?
John
Try:
authenticate_or_request_with_http_basic('YourRealm') do |username,
password>
username == "foo" && password == "bar"
end
Dmitry
Hunt_Jon
(Hunt Jon)
April 22, 2009, 1:51pm
3
Thanks. That's how I can pass the first argument. Now I understand.
Thanks.
John
11155
(-- --)
May 21, 2012, 2:01pm
4
Does the code.....
http_basic_authenticate_with :name=>"foo" :password=>"bar"
will this work?