Class: Rack::Client::Auth::Basic
- Inherits:
-
Object
- Object
- Rack::Client::Auth::Basic
- Includes:
- DualBand
- Defined in:
- lib/rack/client/middleware/auth/basic.rb
Defined Under Namespace
Classes: Challenge
Instance Method Summary collapse
- #async_call(env, &b) ⇒ Object
- #auth_header ⇒ Object
- #authorized_call(env, &b) ⇒ Object
- #encoded_login ⇒ Object
-
#initialize(app, username, password, force = false) ⇒ Basic
constructor
A new instance of Basic.
- #sync_call(env) ⇒ Object
Methods included from DualBand
Constructor Details
#initialize(app, username, password, force = false) ⇒ Basic
Returns a new instance of Basic.
7 8 9 |
# File 'lib/rack/client/middleware/auth/basic.rb', line 7 def initialize(app, username, password, force = false) @app, @username, @password, @force = app, username, password, force end |
Instance Method Details
#async_call(env, &b) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/client/middleware/auth/basic.rb', line 25 def async_call(env, &b) return (env, &b) if @force @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?) (env, &b) else yield response.finish end end end |
#auth_header ⇒ Object
45 46 47 |
# File 'lib/rack/client/middleware/auth/basic.rb', line 45 def auth_header {'HTTP_AUTHORIZATION' => "Basic #{encoded_login}"} end |
#authorized_call(env, &b) ⇒ Object
41 42 43 |
# File 'lib/rack/client/middleware/auth/basic.rb', line 41 def (env, &b) @app.call(env.merge(auth_header), &b) end |
#encoded_login ⇒ Object
49 50 51 |
# File 'lib/rack/client/middleware/auth/basic.rb', line 49 def encoded_login ["#{@username}:#{@password}"].pack("m*").chomp end |
#sync_call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rack/client/middleware/auth/basic.rb', line 11 def sync_call(env) return (env) if @force 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 (env) end response.finish end |