Skip to content
This repository has been archived by the owner. It is now read-only.

Add support for token based api authentication #6

Open
wants to merge 4 commits into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -24,6 +24,7 @@ class Loggly {
public $subdomain = '';
public $username = '';
public $password = '';
public $apiToken = '';
public $inputs = array();

public function __construct() {}
@@ -47,7 +48,13 @@ public function makeRequest($path, $params = null, $method = 'GET') {
}

# set HTTP headers
curl_setopt($curl, CURLOPT_USERPWD, $this->username . ':' . $this->password);
$headers = [];
if($this->username || $this->password){
curl_setopt($curl, CURLOPT_USERPWD, $this->username . ':' . $this->password);
}
if($this->apiToken){
$headers[] = 'Authorization: bearer ' . $this->apiToken;
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

@@ -72,7 +79,11 @@ public function makeRequest($path, $params = null, $method = 'GET') {

# satisfy content length header requirement for PUT
if ($method === 'PUT') {
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($qs)));
$headers[] = 'Content-Length: ' . strlen($qs);
}

if(!empty($headers)){
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}

$result = curl_exec($curl);
@@ -126,7 +137,7 @@ public function disableDiscovery($inputId) {

public function search($q, $params = null) {
$params['q'] = $q;
return $this->makeRequest('/api/search', $params);
return $this->makeRequest('/apiv2/events/iterate', $params);
}

public function facet($q, $facet = 'date', $params = null) {
@@ -21,10 +21,20 @@ The first step is to instantiate a new instance of the Loggly class:

$loggly->subdomain = '<loggly subdomain>';

Authenticate using username & password
========================================


$loggly->username = 'demo';

$loggly->password = '42ftw';

Authenticate using [API Token](https://www.loggly.com/docs/token-based-api-authentication/)
==============================


$loggly->apiToken = 'c1f1e7e4-61e7-4b19-83f4-a26dd61dca3c';


Input and Device Methods
========================
@@ -157,4 +167,4 @@ Support
=======
Have questions?

Contact support@loggly.com (please include your subdomain)
Contact support@loggly.com (please include your subdomain)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.