Class: Corelogic::Authenticator

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/corelogic/authenticator.rb

Constant Summary collapse

OAUTH_URL =
'https://api-prod.corelogic.com/oauth/token'.freeze

Instance Method Summary collapse

Instance Method Details

#call(connection, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/corelogic/authenticator.rb', line 14

def call(connection, options = {})
  options = options.dup
  options[:grant_type] ||= 'client_credentials'
  force = options.delete(:force) || false
  return connection if !force && connection.authenticated?

  response = HTTP.basic_auth(credentials).post(OAUTH_URL, params: options)
  token = Corelogic::ResponseParser.perform(response)[:access_token]
  connection.bearer_token = token
  connection
end