class Egalite::Auth::Basic

Public Class Methods

authorize(req,realm) { |username,password| ... } click to toggle source
# File lib/egalite/auth/basic.rb, line 5
def self.authorize(req,realm)
  auth = req.authorization
  return unauthorized(realm) if auth.blank?
  (method,credentials) = auth.split(' ', 2)
  return bad_request if method.downcase != "basic"
  (username,password) = credentials.unpack("m*").first.split(/:/,2)
  return unauthorized(realm) unless yield(username,password)
  true
end
bad_request() click to toggle source
# File lib/egalite/auth/basic.rb, line 22
def self.bad_request
  return [ 400,
    { 'Content-Type' => 'text/plain',
      'Content-Length' => '0' },
    []
  ]
end
unauthorized(realm) click to toggle source
# File lib/egalite/auth/basic.rb, line 14
def self.unauthorized(realm)
  return [ 401,
    { 'Content-Type' => 'text/plain',
      'Content-Length' => '0',
      'WWW-Authenticate' => 'Basic realm="%s"' % realm },
    []
  ]
end