Class: Rack::Client::Auth::Basic

Inherits:
Object
  • Object
show all
Includes:
DualBand
Defined in:
lib/rack/client/auth/basic.rb

Defined Under Namespace

Classes: Challenge

Instance Method Summary collapse

Methods included from DualBand

#call

Constructor Details

#initialize(app, username, password) ⇒ Basic

Returns a new instance of Basic.



7
8
9
# File 'lib/rack/client/auth/basic.rb', line 7

def initialize(app, username, password)
  @app, @username, @password = app, username, password
end

Instance Method Details

#async_call(env, &b) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rack/client/auth/basic.rb', line 23

def async_call(env, &b)
  @app.call(env) do |response_parts|
    request   = Rack::Request.new(env)
    response  = Response.new(*response_parts)
    challenge = Basic::Challenge.new(request, response)

    if challenge.required? && (challenge.unspecified? || challenge.basic?)
      authorized_call(env, &b)
    else
      yield response.finish
    end
  end
end

#auth_headerObject



41
42
43
# File 'lib/rack/client/auth/basic.rb', line 41

def auth_header
  {'HTTP_AUTHORIZATION' => "Basic #{}"}
end

#authorized_call(env, &b) ⇒ Object



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

def authorized_call(env, &b)
  @app.call(env.merge(auth_header), &b)
end

#encoded_loginObject



45
46
47
# File 'lib/rack/client/auth/basic.rb', line 45

def 
  ["#{@username}:#{@password}"].pack("m*")
end

#sync_call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rack/client/auth/basic.rb', line 11

def sync_call(env)
  request   = Rack::Request.new(env)
  response  = Response.new(*@app.call(env))
  challenge = Basic::Challenge.new(request, response)

  if challenge.required? && (challenge.unspecified? || challenge.basic?)
    return authorized_call(env)
  end

  response.finish
end