Sha256: 3ba5825766d0bc072007d44866867a59da579ab6faa4ad8be45551e2f0ad756c

Contents?: true

Size: 810 Bytes

Versions: 16

Compression:

Stored size: 810 Bytes

Contents

require 'rest-core/middleware'

class RestCore::AuthBasic
  def self.members; [:username, :password]; end
  include RestCore::Middleware

  def call env, &k
    if username(env)
      if password(env)
        app.call(env.merge(REQUEST_HEADERS =>
          auth_basic_header(env).merge(env[REQUEST_HEADERS])), &k)
      else
        app.call(log(env, "AuthBasic: username provided: #{username(env)}," \
                          " but password is missing."), &k)
      end
    elsif password(env)
      app.call(log(env, "AuthBasic: password provided: #{password(env)}," \
                        " but username is missing."), &k)
    else
      app.call(env, &k)
    end
  end

  def auth_basic_header env
    {'Authorization' =>
       "Basic #{["#{username(env)}:#{password(env)}"].pack('m0')}"}
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rest-core-3.6.0 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.92 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.91 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.9 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.8 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.7 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.6 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.5 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.4 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.3 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.2 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.1 lib/rest-core/middleware/auth_basic.rb
rest-core-3.5.0 lib/rest-core/middleware/auth_basic.rb
rest-core-3.4.1 lib/rest-core/middleware/auth_basic.rb
rest-core-3.4.0 lib/rest-core/middleware/auth_basic.rb
rest-core-3.3.3 lib/rest-core/middleware/auth_basic.rb