lib/wolf_core/application/salesforce_oauth_service.rb



module WolfCore
  class SalesforceOauthService < WolfCore::ApplicationService
    def process
      response = http_post(
        url: ENV['SALESFORCE_OAUTH_URL'],
        headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
        body: {
          grant_type: ENV['SALESFORCE_OAUTH_GRANT_TYPE'],
          username: ENV['SALESFORCE_OAUTH_USERNAME'],
          password: ENV['SALESFORCE_OAUTH_PASSWORD'],
          client_id: ENV['SALESFORCE_OAUTH_CLIENT_ID'],
          client_secret: ENV['SALESFORCE_OAUTH_CLIENT_SECRET'],
        }
      )
      if response.code == 200
        access_token = JSON.parse(response.body)['access_token']
        puts "salesforce access token is #{access_token}"
        Result.success(data: { access_token: access_token })
      else
        Result.failure(error: { message: response.message, code: response.code, body: response.body })
      end
    end
  end
end