small medium large xlarge

 

Pt-I-4

Taken from http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html – Simple Digest example

In products_controller.rb:

class ProductsController < ApplicationController
  skip_before_filter :authorize, :only => [:who_bought]
  before_filter :authorize_digest, :only => [:who_bought]
  ...

In application_controller.rb:

require 'digest/md5'
class ApplicationController < ActionController::Base
  REALM = "SuperSecret" 
  USERS = { "test1" => "1234", #plain text password
            "test2" => Digest::MD5.hexdigest(["test2", REALM, "1234"].join(":")) }  #ha1 digest password

...

def authorize_digest
  authenticate_or_request_with_http_digest(REALM) do |username|
    USERS[username]
  end
end  

Page History
  • V11: Cheng Long [almost 2 years ago]
  • V10: Matt Gibson [over 2 years ago]
  • V9: Pierre Sugar [almost 4 years ago]
  • V8: Pierre Sugar [almost 4 years ago]
  • V7: Diego Kurisaki [about 4 years ago]
  • V6: Diego Kurisaki [about 4 years ago]
  • V5: Diego Kurisaki [about 4 years ago]
  • V4: Nick [almost 5 years ago]
  • V3: Nick [almost 5 years ago]
  • V2: Nick [almost 5 years ago]