From 99072de7dc01b9455e0dfb56f97f8d96f5d42092 Mon Sep 17 00:00:00 2001 From: fodor0205 Date: Sun, 7 Apr 2024 23:35:52 +0200 Subject: [PATCH] Remove old unused oauth test --- testing/lion/EpiCurl.php | 132 ---------------- testing/lion/EpiOAuth.php | 294 ----------------------------------- testing/lion/OsmOAuth.php | 47 ------ testing/lion/login_oauth.php | 27 ---- 4 files changed, 500 deletions(-) delete mode 100644 testing/lion/EpiCurl.php delete mode 100644 testing/lion/EpiOAuth.php delete mode 100644 testing/lion/OsmOAuth.php delete mode 100644 testing/lion/login_oauth.php diff --git a/testing/lion/EpiCurl.php b/testing/lion/EpiCurl.php deleted file mode 100644 index 1265b34..0000000 --- a/testing/lion/EpiCurl.php +++ /dev/null @@ -1,132 +0,0 @@ -mc = curl_multi_init(); - $this->properties = array( - 'code' => CURLINFO_HTTP_CODE, - 'time' => CURLINFO_TOTAL_TIME, - 'length'=> CURLINFO_CONTENT_LENGTH_DOWNLOAD, - 'type' => CURLINFO_CONTENT_TYPE - ); - } - - public function addCurl($ch) - { - $key = (string)$ch; - $this->requests[$key] = $ch; - - $res = curl_multi_add_handle($this->mc, $ch); - - // (1) - if($res === CURLM_OK || $res === CURLM_CALL_MULTI_PERFORM) - { - do { - $mrc = curl_multi_exec($this->mc, $active); - } while ($mrc === CURLM_CALL_MULTI_PERFORM); - - return new EpiCurlManager($key); - } - else - { - return $res; - } - } - - public function getResult($key = null) - { - if($key != null) - { - if(isset($this->responses[$key])) - { - return $this->responses[$key]; - } - - $running = null; - do - { - $resp = curl_multi_exec($this->mc, $runningCurrent); - if($running !== null && $runningCurrent != $running) - { - $this->storeResponses($key); - if(isset($this->responses[$key])) - { - return $this->responses[$key]; - } - } - $running = $runningCurrent; - }while($runningCurrent > 0); - } - - return false; - } - - private function storeResponses() - { - while($done = curl_multi_info_read($this->mc)) - { - $key = (string)$done['handle']; - $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']); - foreach($this->properties as $name => $const) - { - $this->responses[$key][$name] = curl_getinfo($done['handle'], $const); - curl_multi_remove_handle($this->mc, $done['handle']); - } - } - } - - static function getInstance() - { - if(self::$inst == null) - { - self::$singleton = 1; - self::$inst = new EpiCurl(); - } - - return self::$inst; - } -} - -class EpiCurlManager -{ - private $key; - private $epiCurl; - - function __construct($key) - { - $this->key = $key; - $this->epiCurl = EpiCurl::getInstance(); - } - - function __get($name) - { - $responses = $this->epiCurl->getResult($this->key); - if (isset($responses[$name])) { - return $responses[$name]; - } else { - return null; - } - } -} - -/* - * Credits: - * - (1) Alistair pointed out that curl_multi_add_handle can return CURLM_CALL_MULTI_PERFORM on success. - */ -?> diff --git a/testing/lion/EpiOAuth.php b/testing/lion/EpiOAuth.php deleted file mode 100644 index 1f254bf..0000000 --- a/testing/lion/EpiOAuth.php +++ /dev/null @@ -1,294 +0,0 @@ -consumerKey = $consumerKey; - $this->consumerSecret = $consumerSecret; - $this->signatureMethod = $signatureMethod; - $this->curl = EpiCurl::getInstance(); - } - - public function getAccessToken() - { - $resp = $this->httpRequest('GET', $this->accessTokenUrl); - return new EpiOAuthResponse($resp); - } - - /* - * Returns an osm.org URL where the user browser must be redirected for accepting authorization - * Includes a request-token. False if error. - */ - public function getAuthorizationUrl() - { - $retval = "{$this->authorizeUrl}?"; - - $token = $this->getRequestToken(); - if($token->oauth_token) { - return $this->authorizeUrl . '?oauth_token=' . $token->oauth_token; - } else { - return false; - } - } - - /* - * Calls osm.org with HTTP GET for a token that must be added to query - * when redirecting the user for authorization - */ - public function getRequestToken() - { - $resp = $this->httpRequest('GET', $this->requestTokenUrl); - return new EpiOAuthResponse($resp); - } - - public function httpRequest($method = null, $url = null, $params = null) - { - if(empty($method) || empty($url)) - return false; - - // FIXME: PUT can be removed probably, NOTES feature may need it - if ($method=='PUT') { - //harry's fudge. Take 'data' param out of the params list - $put_data = $params['data']; - unset($params['data']); - print "put_data:" . $put_data; - } - - if(empty($params['oauth_signature'])) - $params = $this->prepareParameters($method, $url, $params); - - switch($method) - { - case 'GET': - return $this->httpGet($url, $params); - break; - case 'POST': - return $this->httpPost($url, $params); - break; - case 'PUT': - return $this->httpPut($url, $params, $put_data); - break; - } - } - - public function setToken($token = null, $secret = null) - { - $params = func_get_args(); //FIXME: unused? - $this->token = $token; - $this->tokenSecret = $secret; - } - - public function encode($string) - { - return rawurlencode(utf8_encode($string)); - } - - protected function addOAuthHeaders(&$ch, $url, $oauthHeaders) - { - $_h = array('Expect:'); - $urlParts = parse_url($url); - $oauth = 'Authorization: OAuth realm="' . $urlParts['path'] . '",'; - foreach($oauthHeaders as $name => $value) - { - $oauth .= "{$name}=\"{$value}\","; //lose the final ',' - } - $_h[] = substr($oauth, 0, -1); - - curl_setopt($ch, CURLOPT_HTTPHEADER, $_h); - } - - protected function generateNonce() - { - if(isset($this->nonce)) // for unit testing - return $this->nonce; - - return md5(uniqid(rand(), true)); - } - - protected function generateSignature($method = null, $url = null, $params = null) - { - if(empty($method) || empty($url)) - return false; - - - // concatenating - $concatenatedParams = ''; - foreach($params as $k => $v) - { - $v = $this->encode($v); - $concatenatedParams .= "{$k}={$v}&"; - } - $concatenatedParams = $this->encode(substr($concatenatedParams, 0, -1)); - - // normalize url - $normalizedUrl = $this->encode($this->normalizeUrl($url)); - // $method = $this->encode($method); // don't need this but why not? - - $signatureBaseString = "{$method}&{$normalizedUrl}&{$concatenatedParams}"; - return $this->signString($signatureBaseString); - } - - protected function httpGet($url, $params = null) - { - if(count($params['request']) > 0) - { - $url .= '?'; - foreach($params['request'] as $k => $v) - { - $url .= "{$k}={$v}&"; - } - $url = substr($url, 0, -1); - } - $ch = curl_init($url); - $this->addOAuthHeaders($ch, $url, $params['oauth']); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $resp = $this->curl->addCurl($ch); - - return $resp; - } - - protected function httpPost($url, $params = null) - { - $ch = curl_init($url); - $this->addOAuthHeaders($ch, $url, $params['oauth']); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params['request'])); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $resp = $this->curl->addCurl($ch); - return $resp; - } - - //Harry added this one. - protected function httpPut($url, $params = null, $put_data) - { - $ch = curl_init($url); - $this->addOAuthHeaders($ch, $url, $params['oauth']); - curl_setopt($ch, CURLOPT_PUT, 1); - curl_setopt($ch, CURLOPT_VERBOSE, 1); - - $fh = fopen('php://memory','w+'); - fwrite($fh, $put_data); - rewind($fh); - - curl_setopt($ch, CURLOPT_PUT, true); - curl_setopt($ch, CURLOPT_INFILE, $fh); - curl_setopt($ch, CURLOPT_INFILESIZE, strlen($put_data) ); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - //curl_setopt($ch, CURLOPT_POSTFIELDS, $put_data ); // http_build_query($params['request']) . "&xml=" . urlencode($put_data) ); - //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $resp = $this->curl->addCurl($ch); - return $resp; - } - - protected function normalizeUrl($url = null) - { - $urlParts = parse_url($url); - $scheme = strtolower($urlParts['scheme']); - $host = strtolower($urlParts['host']); - - $port=0; - if (isset($urlParts['port'])) $port = intval($urlParts['port']); - - $retval = "{$scheme}://{$host}"; - if($port > 0 && ($scheme === 'http' && $port !== 80) || ($scheme === 'https' && $port !== 443)) - { - $retval .= ":{$port}"; - } - $retval .= $urlParts['path']; - if(!empty($urlParts['query'])) - { - $retval .= "?{$urlParts['query']}"; - } - - return $retval; - } - - /** - * Extends the $params array you want send to the OAtuh server - * with oauth's required many parameters - * adds necessary esacping, encoding, signing. - * - * @returns Array with two keys: 'request': array from $params, 'oauth': array of oauth values - */ - protected function prepareParameters($method = null, $url = null, $params = null) - { - if(empty($method) || empty($url)) - return false; - - $oauth['oauth_consumer_key'] = $this->consumerKey; - $oauth['oauth_token'] = $this->token; - $oauth['oauth_nonce'] = $this->generateNonce(); - $oauth['oauth_timestamp'] = !isset($this->timestamp) ? time() : $this->timestamp; // for unit test - $oauth['oauth_signature_method'] = $this->signatureMethod; - $oauth['oauth_version'] = $this->version; - - // encoding - array_walk($oauth, array($this, 'encode')); - if(is_array($params)) - array_walk($params, array($this, 'encode')); - - $encodedParams = array_merge($oauth, (array)$params); - - // sorting - ksort($encodedParams); - - // signing - $oauth['oauth_signature'] = $this->encode($this->generateSignature($method, $url, $encodedParams)); - return array('request' => $params, 'oauth' => $oauth); - } - - protected function signString($string = null) - { - $retval = false; - switch($this->signatureMethod) - { - case 'HMAC-SHA1': - $key = $this->encode($this->consumerSecret) . '&' . $this->encode($this->tokenSecret); - $retval = base64_encode(hash_hmac('sha1', $string, $key, true)); - break; - } - - return $retval; - } - - } - -class EpiOAuthResponse -{ - private $__resp; - - public function __construct($resp) - { - //print "RESPONSE CODE '" . $resp->code . "'
\n"; - $this->__resp = $resp; - } - - public function __get($name) - { - if($this->__resp->code < 200 || $this->__resp->code > 299) { - print "get($name) fail due to earlier response code '" . $this->__resp->code . "'
\n"; - return false; - } - - parse_str($this->__resp->data, $result); - foreach($result as $k => $v) - { - $this->$k = $v; - } - - return $result[$name]; - } -} diff --git a/testing/lion/OsmOAuth.php b/testing/lion/OsmOAuth.php deleted file mode 100644 index 72a2641..0000000 --- a/testing/lion/OsmOAuth.php +++ /dev/null @@ -1,47 +0,0 @@ -apiUrl . '/' . $parts; - $parts = implode('_', $parts); - $url = $this->apiUrl . '/' . preg_replace('/[A-Z]|[0-9]+/e', "'/'.strtolower('\\0')", $parts) ; - - if(!empty($params)) - $args = array_shift($params); - -print "
>>URL:" . $url ."
"; - - //Invoke 'httpRequest' function in the parent EpiOAuth class passing the bits n bobs extracted above - //Result is an EpiCurl response object. Note this doesn't contain response data immediately because the request itself hasn't been sent, only queued - return call_user_func( array($this, 'httpRequest') , $method, $url, $args); - - }*/ - - public function __construct($consumerKey = null, $consumerSecret = null, $oauthToken = null, $oauthTokenSecret = null) - { - parent::__construct($consumerKey, $consumerSecret, self::OSMOAUTH_SIGNATURE_METHOD); - $this->setToken($oauthToken, $oauthTokenSecret); - } -} - diff --git a/testing/lion/login_oauth.php b/testing/lion/login_oauth.php deleted file mode 100644 index c170086..0000000 --- a/testing/lion/login_oauth.php +++ /dev/null @@ -1,27 +0,0 @@ -\n"; - $osmObj = new OsmOAuth($consumer_key, $consumer_secret); - - print "Getting an access token for '$callbackToken'...
\n"; - $osmObj->setToken($callbackToken); - $token = $osmObj->getAccessToken(); - var_dump($token); - - print "Storing access token for your session
\n"; - $_SESSION['tok'] = $token->oauth_token; - $_SESSION['sec'] = $token->oauth_token_secret; -} else { - echo("Valami hiba történhetett az azonosítás során."); -} -