123456789_123456789_123456789_123456789_123456789_

Class: Rack::Auth::Basic

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Rack::Auth::AbstractHandler
Defined in: lib/rack/auth/basic.rb

Overview

Basic implements HTTP Basic Authentication, as per RFC 2617.

Initialize with the ::Rack application that you want protecting, and a block that checks if a username and password pair are valid.

Class Method Summary

AbstractHandler - Inherited

Instance Attribute Summary

AbstractHandler - Inherited

Instance Method Summary

Constructor Details

This class inherits a constructor from Rack::Auth::AbstractHandler

Instance Method Details

#call(env)

[ GitHub ]

  
# File 'lib/rack/auth/basic.rb', line 15

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

#challenge (private)

[ GitHub ]

  
# File 'lib/rack/auth/basic.rb', line 34

def challenge
  'Basic realm="%s"' % realm
end

#valid?(auth) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rack/auth/basic.rb', line 38

def valid?(auth)
  @authenticator.call(*auth.credentials)
end