chneukirchen / rack-mirror

OUTDATED mirror of Rack's darcs repository, use github.com/chneukirchen/rack

This URL has Read+Write access

chneukirchen (author)
Sun May 25 07:32:00 -0700 2008
commit  c3d6e4a3dc6bc367529d11515bdf1e7eb2a93912
tree    66e82a15b33ab34834fe4e16e8075e9e5bb915d4
parent  5a117d0b45b4ed2785a714eaa060e8c66512c4c3
rack-mirror / lib / rack / auth / basic.rb
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 1 require 'rack/auth/abstract/handler'
2 require 'rack/auth/abstract/request'
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 3
4 module Rack
5 module Auth
9191ff31 » tim 2007-04-03 Some initial documentation ... 6 # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617.
7 #
c5b420a5 » chneukirchen 2007-05-16 Small docfixes 8 # Initialize with the Rack application that you want protecting,
9191ff31 » tim 2007-04-03 Some initial documentation ... 9 # and a block that checks if a username and password pair are valid.
10 #
c5b420a5 » chneukirchen 2007-05-16 Small docfixes 11 # See also: <tt>example/protectedlobster.rb</tt>
9191ff31 » tim 2007-04-03 Some initial documentation ... 12
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 13 class Basic < AbstractHandler
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 14
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 15 def call(env)
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 16 auth = Basic::Request.new(env)
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 17
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 18 return unauthorized unless auth.provided?
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 19
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 20 return bad_request unless auth.basic?
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 21
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 22 if valid?(auth)
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 23 env['REMOTE_USER'] = auth.username
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 24
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 25 return @app.call(env)
26 end
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 27
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 28 unauthorized
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 29 end
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 30
31
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 32 private
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 33
34 def challenge
35 'Basic realm="%s"' % realm
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 36 end
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 37
38 def valid?(auth)
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 39 @authenticator.call(*auth.credentials)
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 40 end
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 41
42 class Request < Auth::AbstractRequest
43 def basic?
44 :basic == scheme
45 end
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 46
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 47 def credentials
e6b65296 » chneukirchen 2007-12-31 Remove uses of base64 for R... 48 @credentials ||= params.unpack("m*").first.split(/:/, 2)
0186ca16 » tim 2007-03-26 Adding Rack::Auth::Digest::... 49 end
50
51 def username
52 credentials.first
53 end
54 end
55
dce7dc06 » tim 2007-03-04 Adding Rack::Auth::Basic 56 end
57 end
df5ff5b3 » chneukirchen 2007-03-27 Small cleanup 58 end