Created
October 5, 2009 06:32
-
-
Save baroquebobcat/201935 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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