Sha256: ba908d7d80d457418424739b29d8ec18a0b6eb3a444d6d8dc967f15232dd396c

Contents?: true

Size: 827 Bytes

Versions: 5

Compression:

Stored size: 827 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

5 entries across 5 versions & 1 rubygems

Version Path
rest-core-2.0.4 lib/rest-core/middleware/auth_basic.rb
rest-core-2.0.3 lib/rest-core/middleware/auth_basic.rb
rest-core-2.0.2 lib/rest-core/middleware/auth_basic.rb
rest-core-2.0.1 lib/rest-core/middleware/auth_basic.rb
rest-core-2.0.0 lib/rest-core/middleware/auth_basic.rb