class Rack::Auth::Basic - rack-1.6.2 Documentation

# class Rack::Auth::Basic

Rack::Auth::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.

See also: `example/protectedlobster.rb`

### Public Instance Methods

call(env) click to toggle source

    # 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

### Private Instance Methods

challenge() click to toggle source

    # File lib/rack/auth/basic.rb, line 34
    def challenge
      'Basic realm="%s"' % realm
    end

valid?(auth) click to toggle source

    # File lib/rack/auth/basic.rb, line 38
    def valid?(auth)
      @authenticator.call(*auth.credentials)
    end