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 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Add support for token based api authentication https://www.loggly.com…

  • Loading branch information
rineez-livares committed Nov 21, 2017
commit d93b6f74382e7bf41017fa64387cd356c5127781
@@ -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);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.