Class: RestCore::AuthBasic

Inherits:
Object
  • Object
show all
Includes:
Middleware
Defined in:
lib/rest-core/middleware/auth_basic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.membersObject



4
# File 'lib/rest-core/middleware/auth_basic.rb', line 4

def self.members; [:username, :password]; end

Instance Method Details

#auth_basic_header(env) ⇒ Object



24
25
26
27
# File 'lib/rest-core/middleware/auth_basic.rb', line 24

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

#call(env, &k) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rest-core/middleware/auth_basic.rb', line 7

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