Permalink
Browse files

Small cleanup

darcs-hash:20070327090602-4fc50-248081b6b83b1a66014b3b3866c8f54e47db4ef4.gz
  • Loading branch information...
1 parent 0186ca1 commit df5ff5b351026c3ffb9e6edd432d57292426b981 @chneukirchen committed Mar 27, 2007
@@ -3,7 +3,7 @@ module Auth
class AbstractHandler
attr_accessor :realm
-
+
def initialize(app, &authenticator)
@app, @authenticator = app, authenticator
end
@@ -19,7 +19,7 @@ def unauthorized(www_authenticate = challenge)
def bad_request
[ 400, { 'Content-Type' => 'text/html' }, ['<h1>400 Bad Request</h1>'] ]
end
-
+
end
end
-end
+end
@@ -15,7 +15,7 @@ def provided?
def parts
@parts ||= @env[authorization_key].split(' ', 2)
end
-
+
def scheme
@scheme ||= parts.first.downcase.to_sym
end
@@ -34,6 +34,6 @@ def authorization_key
end
end
-
+
end
-end
+end
@@ -4,20 +4,20 @@
module Rack
module Auth
class Basic < AbstractHandler
-
+
def call(env)
auth = Basic::Request.new(env)
-
+
return unauthorized unless auth.provided?
-
+
return bad_request unless auth.basic?
-
+
if valid?(auth)
env['REMOTE_USER'] = auth.username
-
+
return @app.call(env)
end
-
+
unauthorized
end
@@ -29,14 +29,14 @@ def challenge
end
def valid?(auth)
- @authenticator.call *auth.credentials
+ @authenticator.call(*auth.credentials)
end
class Request < Auth::AbstractRequest
def basic?
:basic == scheme
end
-
+
def credentials
@credentials ||= Base64.decode64(params).split(/:/, 2)
end
@@ -48,4 +48,4 @@ def username
end
end
-end
+end
@@ -10,9 +10,14 @@ module Digest
class MD5 < AbstractHandler
attr_accessor :opaque
-
+
attr_writer :passwords_hashed
-
+
+ def initialize(app)
+ super
+ @passwords_hashed = nil
+ end
+
def passwords_hashed?
!!@passwords_hashed
end
@@ -52,11 +57,11 @@ def params(hash = {})
params['nonce'] = Nonce.new.to_s
params['opaque'] = H(opaque)
params['qop'] = QOP
-
+
hash.each { |k, v| params[k] = v }
end
end
-
+
def challenge(hash = {})
"Digest #{params(hash)}"
end
@@ -72,19 +77,19 @@ def valid_qop?(auth)
def valid_opaque?(auth)
H(opaque) == auth.opaque
end
-
+
def valid_nonce?(auth)
auth.nonce.valid?
end
-
+
def valid_digest?(auth)
digest(auth, @authenticator.call(auth.username)) == auth.response
- end
+ end
def md5(data)
::Digest::MD5.hexdigest(data)
end
-
+
alias :H :md5
def KD(secret, data)
@@ -107,4 +112,4 @@ def digest(auth, password)
end
end
end
-end
+end
@@ -11,7 +11,7 @@ class << self
end
def self.parse(string)
- new *Base64.decode64(string).split(' ', 2)
+ new(*Base64.decode64(string).split(' ', 2))
end
def initialize(timestamp = Time.now, given_digest = nil)
@@ -41,4 +41,4 @@ def fresh?
end
end
end
-end
+end
@@ -20,23 +20,23 @@ def self.dequote(str) # From WEBrick::HTTPUtils
def self.split_header_value(str) # From WEBrick::HTTPUtils
str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+)(?:,\s*|\Z)/n).collect{ |v| v[0] }
end
-
+
def initialize
super
-
+
yield self if block_given?
end
-
+
def [](k)
super k.to_s
end
-
+
def []=(k, v)
super k.to_s, v.to_s
end
UNQUOTED = ['qop', 'nc', 'stale']
-
+
def to_s
inject([]) do |parts, (k, v)|
parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v))
@@ -48,7 +48,7 @@ def quote(str) # From WEBrick::HTTPUtils
'"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
end
- end
+ end
end
end
end
@@ -18,7 +18,7 @@ def digest?
def correct_uri?
@env['PATH_INFO'] == uri
end
-
+
def nonce
@nonce ||= Nonce.parse(params['nonce'])
end
@@ -37,4 +37,4 @@ def method_missing(sym)
end
end
end
-end
+end

0 comments on commit df5ff5b

Please sign in to comment.