Class: Verifalia::Security::UsernamePasswordAuthenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/verifalia/security/username_password_authenticator.rb

Overview

Allows to authenticate to Verifalia with a username and password pair.

Instance Method Summary collapse

Constructor Details

#initialize(username, password = nil) ⇒ UsernamePasswordAuthenticator

Returns a new instance of UsernamePasswordAuthenticator.



36
37
38
39
40
41
42
43
# File 'lib/verifalia/security/username_password_authenticator.rb', line 36

def initialize(username, password = nil)
  if username.nil? || username.strip.length == 0
    raise ArgumentError, 'username is nil or empty: please visit https://verifalia.com/client-area to set up a new user, if you don\'t have one.'
  end

  @username = username
  @password = password || ''
end

Instance Method Details

#authenticate(connection, request) ⇒ Object



45
46
47
48
# File 'lib/verifalia/security/username_password_authenticator.rb', line 45

def authenticate(connection, request)
  header = Faraday::Utils.basic_header_from(@username, @password)
  request.headers[Faraday::Request::Authorization::KEY] = header
end