class JunglePath::Rack::BasicCredentials::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 Class Methods

new(app, realm=nil, issue_challenge=true, &authenticator) click to toggle source
Calls superclass method
# File lib/jungle_path/rack/basic_credentials.rb, line 18
def initialize(app, realm=nil, issue_challenge=true, &authenticator)
  @issue_challenge = issue_challenge
  super(app, realm, &authenticator)
end

Public Instance Methods

call(env) click to toggle source
# File lib/jungle_path/rack/basic_credentials.rb, line 23
def call(env)
  #puts "realm: #{realm}."

  auth = Basic::Request.new(env)

  if @issue_challenge
    return unauthorized unless auth.provided?
    return bad_request unless auth.basic?
  end

  if auth.provided? and auth.basic?
    env['REMOTE_USER'] = auth.username
    env['REMOTE_PASSWORD'] = auth.password
  else
    env['REMOTE_USER'] = nil
    env['REMOTE_PASSWORD'] = nil
  end

  @app.call(env)
end

Private Instance Methods

challenge() click to toggle source
# File lib/jungle_path/rack/basic_credentials.rb, line 46
def challenge
  'Basic realm="%s"' % realm
end