Skip to content

Commit

Permalink
Update EpiOAuth.php
Browse files Browse the repository at this point in the history
  • Loading branch information
dlnetworks committed Feb 28, 2014
1 parent d29e428 commit 4ee0153
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions EpiOAuth.php
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php <?php

class EpiOAuth class EpiOAuth
{ {
public $version = '1.0'; public $version = '1.0';
Expand All @@ -12,9 +11,11 @@ class EpiOAuth
protected $consumerSecret; protected $consumerSecret;
protected $token; protected $token;
protected $tokenSecret; protected $tokenSecret;
protected $callback;
protected $signatureMethod; protected $signatureMethod;
protected $debug = false; protected $debug = false;
protected $useSSL = false; protected $useSSL = false;
protected $followLocation = false;
protected $headers = array(); protected $headers = array();
protected $userAgent = 'EpiOAuth (http://github.com/jmathai/twitter-async/tree/)'; protected $userAgent = 'EpiOAuth (http://github.com/jmathai/twitter-async/tree/)';
protected $connectionTimeout = 5; protected $connectionTimeout = 5;
Expand All @@ -30,6 +31,10 @@ public function addHeader($header)


public function getAccessToken($params = null) public function getAccessToken($params = null)
{ {
if (isset($_GET['oauth_verifier']) && !isset($params['oauth_verifier']))
{
$params['oauth_verifier'] = $_GET['oauth_verifier'];
}
$resp = $this->httpRequest('POST', $this->getUrl($this->accessTokenUrl), $params); $resp = $this->httpRequest('POST', $this->getUrl($this->accessTokenUrl), $params);
return new EpiOAuthResponse($resp); return new EpiOAuthResponse($resp);
} }
Expand Down Expand Up @@ -57,6 +62,10 @@ public function getAuthorizationUrl($token = null)


public function getRequestToken($params = null) public function getRequestToken($params = null)
{ {
if (isset($this->callback) && !isset($params['oauth_callback']))
{
$params['oauth_callback'] = $this->callback;
}
$resp = $this->httpRequest('POST', $this->getUrl($this->requestTokenUrl), $params); $resp = $this->httpRequest('POST', $this->getUrl($this->requestTokenUrl), $params);
return new EpiOAuthResponse($resp); return new EpiOAuthResponse($resp);
} }
Expand Down Expand Up @@ -97,6 +106,11 @@ public function setDebug($bool=false)
$this->debug = (bool)$bool; $this->debug = (bool)$bool;
} }


public function setFollowLocation($bool)
{
$this->followLocation = (bool)$bool;
}

public function setTimeout($requestTimeout = null, $connectionTimeout = null) public function setTimeout($requestTimeout = null, $connectionTimeout = null)
{ {
if($requestTimeout !== null) if($requestTimeout !== null)
Expand All @@ -109,7 +123,12 @@ public function setToken($token = null, $secret = null)
{ {
$this->token = $token; $this->token = $token;
$this->tokenSecret = $secret; $this->tokenSecret = $secret;
} }

public function setCallback($callback = null)
{
$this->callback = $callback;
}


public function useSSL($use = false) public function useSSL($use = false)
{ {
Expand Down Expand Up @@ -146,14 +165,23 @@ protected function curlInit($url)
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_ENCODING, '');
if($this->followLocation)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if(isset($_SERVER ['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1') if(isset($_SERVER ['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1')
curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']); curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']);


if($this->useSSL === true) // if the certificate exists then use it, else bypass ssl checks
if(file_exists($cert = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ca-bundle.crt'))
{
curl_setopt($ch, CURLOPT_CAINFO, $cert);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
else
{ {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
} }
return $ch; return $ch;
} }
Expand Down Expand Up @@ -194,12 +222,20 @@ protected function generateSignature($method = null, $url = null, $params = null
return $this->signString($signatureBaseString); return $this->signString($signatureBaseString);
} }


protected function executeCurl($ch)
{
if($this->isAsynchronous)
return $this->curl->addCurl($ch);
else
return $this->curl->addEasyCurl($ch);
}

protected function httpDelete($url, $params) { protected function httpDelete($url, $params) {
$this->addDefaultHeaders($url, $params['oauth']); $this->addDefaultHeaders($url, $params['oauth']);
$ch = $this->curlInit($url); $ch = $this->curlInit($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request'])); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
$resp = $this->curl->addCurl($ch); $resp = $this->executeCurl($ch);
$this->emptyHeaders(); $this->emptyHeaders();
return $resp; return $resp;
} }
Expand All @@ -217,7 +253,7 @@ protected function httpGet($url, $params = null)
} }
$this->addDefaultHeaders($url, $params['oauth']); $this->addDefaultHeaders($url, $params['oauth']);
$ch = $this->curlInit($url); $ch = $this->curlInit($url);
$resp = $this->curl->addCurl($ch); $resp = $this->executeCurl($ch);
$this->emptyHeaders(); $this->emptyHeaders();


return $resp; return $resp;
Expand All @@ -234,7 +270,7 @@ protected function httpPost($url, $params = null, $isMultipart)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']); curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
else else
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request'])); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
$resp = $this->curl->addCurl($ch); $resp = $this->executeCurl($ch);
$this->emptyHeaders(); $this->emptyHeaders();


return $resp; return $resp;
Expand Down

0 comments on commit 4ee0153

Please sign in to comment.