Sha256: c87257a14e841ee2b0dcd7fea4067e175da90a2e6fc8655627e1a5495efceca5

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

== 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, consider 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, `authenticate_or_request_with_http_basic`.

[source, ruby]
-------------------------------------
class AdminController < ApplicationController

  USERNAME, PASSWORD = "humbaba", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"

  before_filter :authenticate

private

  def authenticate
    authenticate_or_request_with_http_basic do |username, password|
      username == USERNAME && Digest::SHA1.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.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-2.2.3 doc/guides/source/actioncontroller_basics/http_auth.txt
rails-2.2.2 doc/guides/source/actioncontroller_basics/http_auth.txt