2009-02-04 21:26:08 +01:00
|
|
|
module Rack
|
|
|
|
module Auth
|
|
|
|
# Rack::Auth::AbstractHandler implements common authentication functionality.
|
|
|
|
#
|
|
|
|
# +realm+ should be set for all handlers.
|
|
|
|
|
|
|
|
class AbstractHandler
|
|
|
|
|
|
|
|
attr_accessor :realm
|
|
|
|
|
2009-03-16 15:55:30 +01:00
|
|
|
def initialize(app, realm=nil, &authenticator)
|
|
|
|
@app, @realm, @authenticator = app, realm, authenticator
|
2009-02-04 21:26:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def unauthorized(www_authenticate = challenge)
|
2009-02-28 02:23:00 +01:00
|
|
|
return [ 401,
|
|
|
|
{ 'Content-Type' => 'text/plain',
|
|
|
|
'Content-Length' => '0',
|
|
|
|
'WWW-Authenticate' => www_authenticate.to_s },
|
|
|
|
[]
|
|
|
|
]
|
2009-02-04 21:26:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def bad_request
|
2009-02-28 02:23:00 +01:00
|
|
|
return [ 400,
|
|
|
|
{ 'Content-Type' => 'text/plain',
|
|
|
|
'Content-Length' => '0' },
|
|
|
|
[]
|
|
|
|
]
|
2009-02-04 21:26:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|