Class: Rack::Auth::Basic

Inherits:
AbstractHandler show all
Defined in:
rack/rack/auth/basic.rb

Overview

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

Defined Under Namespace

Classes: Request

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

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

Instance Attribute Details

- (void) realm Originally defined in class AbstractHandler

Returns the value of attribute realm

Instance Method Details

- (void) call(env)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'rack/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