Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created October 5, 2009 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baroquebobcat/201935 to your computer and use it in GitHub Desktop.
Save baroquebobcat/201935 to your computer and use it in GitHub Desktop.
# I doubt this even works, I just was looking at Rack::Auth::Digest::MD5
# and realized that you can't use it with the Rack::Builder dsl because it
# needs things set after it has been initialized.
# This bothered me, so I blocked this out.
# Doing it this way rather than passing a self block allows it to
# continue to act like Rack::Auth::Basic does.
# My main annoyance was that the interfaces differ in ways that seem to
# make little sense to me.
module Rack::Auth::UsableDigestMD5
def self.new protected_app,options,&block
app = Rack::Auth::Digest::MD5.new protected_app,block
app.opaque = options[:opaque]
app.realm = options[:realm]
app.passwords_hashed = options[:passwords_hashed]
end
end
#Usage
#
use Rack::Auth::UsableDigestMD5, :opaque=>'something-secret',
:realm=>'My Castle',
:passwords_hashed=> true do |username|
'password' if 'Fred' == username
end
# another way to build the interface, but it breaks the shared behavior
#
# passing self to init block, instead of having options,
# and making the authenticator a method
#
# again, this code probably doesn't work as is
# Usage
use Rack::Auth::DigestWithMD5ThatHasADifferentInterface do |auth|
auth.opaque = 'secret'
auth.realm = 'My Castle'
auth.passwords_hashed = true
auth.authenticator do |username|
'password' if 'Fred' == username
end
end
# Mods
class Rack::Auth::DigestWithMD5ThatHasADifferentInterface
def initialize
yield self
end
def authenticator &block=nil
if block
@authenticator = block
else
@authenticator
end
end
# ... same as Rack::Auth::Digest::MD5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment