Skip to content

Commit 43fb566

Browse files
author
Robert Mullins
committed
Update Connection.php
1 parent a9f051e commit 43fb566

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/Bigcommerce/Api/Connection.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Connection
4040
private $failOnError = false;
4141

4242
/**
43-
* Manually follow location redirects. Used if CURLOPT_FOLLOWLOCATION
43+
* Manually follow location redirects. Used if FOLLOWLOCATION
4444
* is unavailable due to open_basedir restriction.
4545
* @var boolean
4646
*/
@@ -69,6 +69,20 @@ class Connection
6969
* as XML. Defaults to false (using JSON).
7070
*/
7171
private $useXml = false;
72+
73+
/**
74+
* oAuth Client ID
75+
*
76+
* @var string
77+
*/
78+
private $client_id;
79+
80+
/**
81+
* oAuth Access Token
82+
*
83+
* @var string
84+
*/
85+
private $oauth_token;
7286

7387
/**
7488
* Initializes the connection object.
@@ -118,11 +132,20 @@ public function failOnError($option = true)
118132
/**
119133
* Sets the HTTP basic authentication.
120134
*/
121-
public function authenticate($username, $password)
135+
public function authenticateBasic($username, $password)
122136
{
123137
curl_setopt($this->curl, CURLOPT_USERPWD, "$username:$password");
124138
}
125-
139+
140+
/**
141+
* Sets the HTTP oAuth autentication.
142+
*/
143+
public function authenticateOauth($client_id, $oauth_token)
144+
{
145+
$this->client_id = $client_id;
146+
$this->oauth_token = $oauth_token;
147+
}
148+
126149
/**
127150
* Set a default timeout for the request. The client will error if the
128151
* request takes longer than this to respond.
@@ -183,6 +206,11 @@ private function initializeRequest()
183206
$this->responseHeaders = array();
184207
$this->lastError = false;
185208
$this->addHeader('Accept', $this->getContentType());
209+
210+
if (isset($this->client_id) && isset($this->oauth_token)) {
211+
$this->addHeader('X-Auth-Client', $this->client_id);
212+
$this->addHeader('X-Auth-Token', $this->oauth_token);
213+
}
186214

187215
curl_setopt($this->curl, CURLOPT_POST, false);
188216
curl_setopt($this->curl, CURLOPT_PUT, false);
@@ -299,7 +327,7 @@ public function get($url, $query = false)
299327
*/
300328
public function post($url, $body)
301329
{
302-
$this->addHeader('Content-Type', $this->getContentType());
330+
//$this->addHeader('Content-Type', $this->getContentType());
303331

304332
if (!is_string($body)) {
305333
$body = json_encode($body);
@@ -346,7 +374,7 @@ public function head($url)
346374
*/
347375
public function put($url, $body)
348376
{
349-
$this->addHeader('Content-Type', $this->getContentType());
377+
//$this->addHeader('Content-Type', $this->getContentType());
350378

351379
if (!is_string($body)) {
352380
$body = json_encode($body);

0 commit comments

Comments
 (0)