Class: Ape::Authent

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/ape/authent.rb

Instance Method Summary collapse

Methods included from Util

included

Constructor Details

#initialize(username, password, scheme = nil) ⇒ Authent

Returns a new instance of Authent.



11
12
13
14
# File 'lib/ape/authent.rb', line 11

def initialize(username, password, scheme=nil)
  @username = username
  @password = password      
end

Instance Method Details

#add_to(req, authentication = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ape/authent.rb', line 16

def add_to(req, authentication = nil)
  return unless @username && @password
  if (authentication)
    if authentication.strip.downcase.include? 'basic'
      req.basic_auth @username, @password
    else
      @auth_plugin ||= load_plugin(authentication)
      @auth_plugin.add_credentials(req, authentication, @username, @password)
    end
  else
    req.basic_auth @username, @password
  end
end

#load_plugin(authentication) ⇒ Object



30
31
32
33
# File 'lib/ape/authent.rb', line 30

def load_plugin(authentication)
  plugin = Authent.resolve_plugin(authentication, 'auth', 'credentials', true)
  plugin || (raise AuthenticationError, "Unknown authentication method: #{authentication}")
end