aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source/actioncontroller_basics/http_auth.txt
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-10-21 18:33:40 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-10-21 18:33:40 +0100
commita03e2b356c66ddc8809fa2b23a2a7d652f173b8b (patch)
treeab8552913475bf94a78e4cbfbae804b2ecd9eca2 /railties/doc/guides/source/actioncontroller_basics/http_auth.txt
parent18542c9e00209679bdaacf64075819fb887ec856 (diff)
downloadrails-a03e2b356c66ddc8809fa2b23a2a7d652f173b8b.tar.gz
rails-a03e2b356c66ddc8809fa2b23a2a7d652f173b8b.tar.bz2
rails-a03e2b356c66ddc8809fa2b23a2a7d652f173b8b.zip
Merge with docrails. Also add a rake task to generate guides in your rails application :
rake doc:guides The rake task will generate guides inside doc/guides directory of your application. Open index.html to browse.
Diffstat (limited to 'railties/doc/guides/source/actioncontroller_basics/http_auth.txt')
-rw-r--r--railties/doc/guides/source/actioncontroller_basics/http_auth.txt24
1 files changed, 24 insertions, 0 deletions
diff --git a/railties/doc/guides/source/actioncontroller_basics/http_auth.txt b/railties/doc/guides/source/actioncontroller_basics/http_auth.txt
new file mode 100644
index 0000000000..7df0e635bf
--- /dev/null
+++ b/railties/doc/guides/source/actioncontroller_basics/http_auth.txt
@@ -0,0 +1,24 @@
+== HTTP Basic Authentication ==
+
+Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, we will create an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, link:http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic/ControllerMethods.html#M000610[authenticate_or_request_with_http_basic].
+
+[source, ruby]
+-------------------------------------
+class AdminController < ApplicationController
+
+ USERNAME, PASSWORD = "humbaba", "f59a4805511bf4bb61978445a5380c6c"
+
+ before_filter :authenticate
+
+private
+
+ def authenticate
+ authenticate_or_request_with_http_basic do |username, password|
+ username == USERNAME && Digest::MD5.hexdigest(password) == PASSWORD
+ end
+ end
+
+end
+-------------------------------------
+
+With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication.