Sha256: 5aec9949f05fe87eb2bdde59fa4b7d74939767e352d4756c505e0f0e3e00ccf8

Contents?: true

Size: 821 Bytes

Versions: 10

Compression:

Stored size: 821 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('m').tr("\n",'')}"}
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rest-core-3.3.2 lib/rest-core/middleware/auth_basic.rb
rest-core-3.3.1 lib/rest-core/middleware/auth_basic.rb
rest-core-3.3.0 lib/rest-core/middleware/auth_basic.rb
rest-core-3.2.0 lib/rest-core/middleware/auth_basic.rb
rest-core-3.1.1 lib/rest-core/middleware/auth_basic.rb
rest-core-3.1.0 lib/rest-core/middleware/auth_basic.rb
rest-core-3.0.0 lib/rest-core/middleware/auth_basic.rb
rest-core-2.1.2 lib/rest-core/middleware/auth_basic.rb
rest-core-2.1.1 lib/rest-core/middleware/auth_basic.rb
rest-core-2.1.0 lib/rest-core/middleware/auth_basic.rb