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  

Then try http://localhost:3000/products/1/who_bought.atom using the credentials test1/1234 or test2/1234.

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