Hunt_J
April 22, 2009, 3:48pm
1
I’m trying to HTTP Basic Authentication mentioned at
http://railscasts.com/episodes/82-http-basic-authentication
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
Hunt_J
April 22, 2009, 3:50pm
2
Try:
authenticate_or_request_with_http_basic(‘YourRealm’) do |username,
password|
username == “foo” && password == “bar”
end
Dmitry
Hunt_J
April 22, 2009, 3:51pm
3
Thanks. That’s how I can pass the first argument. Now I understand.
Thanks.
John
On Wed, Apr 22, 2009 at 10:49 PM, Dmitry S.
Does the code…
http_basic_authenticate_with :name=>“foo” :password=>“bar”
will this work?