@@ -40,7 +40,7 @@ class Connection
40
40
private $ failOnError = false ;
41
41
42
42
/**
43
- * Manually follow location redirects. Used if CURLOPT_FOLLOWLOCATION
43
+ * Manually follow location redirects. Used if FOLLOWLOCATION
44
44
* is unavailable due to open_basedir restriction.
45
45
* @var boolean
46
46
*/
@@ -69,6 +69,20 @@ class Connection
69
69
* as XML. Defaults to false (using JSON).
70
70
*/
71
71
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 ;
72
86
73
87
/**
74
88
* Initializes the connection object.
@@ -118,11 +132,20 @@ public function failOnError($option = true)
118
132
/**
119
133
* Sets the HTTP basic authentication.
120
134
*/
121
- public function authenticate ($ username , $ password )
135
+ public function authenticateBasic ($ username , $ password )
122
136
{
123
137
curl_setopt ($ this ->curl , CURLOPT_USERPWD , "$ username: $ password " );
124
138
}
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
+
126
149
/**
127
150
* Set a default timeout for the request. The client will error if the
128
151
* request takes longer than this to respond.
@@ -183,6 +206,11 @@ private function initializeRequest()
183
206
$ this ->responseHeaders = array ();
184
207
$ this ->lastError = false ;
185
208
$ 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
+ }
186
214
187
215
curl_setopt ($ this ->curl , CURLOPT_POST , false );
188
216
curl_setopt ($ this ->curl , CURLOPT_PUT , false );
@@ -299,7 +327,7 @@ public function get($url, $query = false)
299
327
*/
300
328
public function post ($ url , $ body )
301
329
{
302
- $ this ->addHeader ('Content-Type ' , $ this ->getContentType ());
330
+ // $this->addHeader('Content-Type', $this->getContentType());
303
331
304
332
if (!is_string ($ body )) {
305
333
$ body = json_encode ($ body );
@@ -346,7 +374,7 @@ public function head($url)
346
374
*/
347
375
public function put ($ url , $ body )
348
376
{
349
- $ this ->addHeader ('Content-Type ' , $ this ->getContentType ());
377
+ // $this->addHeader('Content-Type', $this->getContentType());
350
378
351
379
if (!is_string ($ body )) {
352
380
$ body = json_encode ($ body );
0 commit comments