public function testGetSbs_TwitterPostExample()
 {
     $params = array('include_entities' => 'true', 'status' => 'Hello Ladies + Gentlemen, a signed OAuth request!', 'oauth_consumer_key' => 'xvz1evFS4wEEPTGEFPHBog', 'oauth_nonce' => 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => 1318622958, 'oauth_token' => '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb', 'oauth_version' => '1.0');
     $result = oauth_get_sbs('POST', 'https://api.twitter.com/1/statuses/update.json', $params);
     $expected = 'POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521';
     self::assertEquals($expected, $result);
 }
Exemple #2
0
 public static function getSBS($method, $uri, $request_parameters = array())
 {
     if (function_exists('oauth_get_sbs')) {
         return oauth_get_sbs($method, $uri, $request_parameters);
     } else {
         return ar_error::raiseError('OAuth PECL extension not installed.', ar_exceptions::CONFIGURATION_ERROR);
     }
 }
Exemple #3
0
 public function testStringBody()
 {
     $testUrl = 'http://requestb.in/sy5fv3sy';
     $url = "{$testUrl}?foo=bar";
     $body = '{"grade":{"id":491378983,"points":10.00,"letterGrade":"A","comments":"OAuth 1.0 PUT Test"}}';
     $consumerKey = 'xvz1evFS4wEEPTGEFPHBog';
     $consumerSecret = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw';
     $token = '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb';
     $tokenSecret = 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE';
     $oauth = $this->getMock('OAuth', array('execCurl'), array($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1));
     // $oauth = new OAuth($consumerKey, $consumerSecret);
     $oauth->setToken($token, $tokenSecret);
     $oauth->setNonce('kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg');
     $oauth->setTimestamp(1318622958);
     $oauth->enableDebug();
     $expectSbs = 'PUT&http%3A%2F%2Frequestb.in%2Fsy5fv3sy&foo%3Dbar%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0';
     $expectAuthHeader = 'Authorization: OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",oauth_signature_method="HMAC-SHA1",oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",oauth_timestamp="1318622958",oauth_version="1.0",oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",oauth_signature="H7IxAZE8AnSwNt4PCSRGdzIdmnk%3D"';
     $expectSignature = 'H7IxAZE8AnSwNt4PCSRGdzIdmnk=';
     $signParams = array();
     self::assertEquals('PUT&http%3A%2F%2Frequestb.in%2Fsy5fv3sy&foo%3Dbar', oauth_get_sbs('PUT', $url, $signParams));
     self::assertEquals($expectSignature, $oauth->generateSignature('PUT', $url, $signParams));
     $oauth->expects(self::once())->method('execCurl')->with($url, $this->expectedCurlOptions($oauth, 'PUT', array($expectAuthHeader, 'Expect:'), $body))->will(self::returnValue(array('OK', array('http_code' => '200'))));
     $result = $oauth->fetch($url, $body, 'PUT');
 }
Exemple #4
0
 public function get($key, $default = '')
 {
     switch ($key) {
         case 'version':
             return isset($this->version) ? $this->version : $default;
         case 'method':
             return isset($this->method) ? $this->method : $default;
         case 'scheme':
             return isset($this->scheme) ? $this->scheme : $default;
         case 'username':
             return isset($this->username) ? $this->username : $default;
         case 'password':
             return isset($this->password) ? $this->password : $default;
         case 'hostname':
             return isset($this->hostname) ? $this->hostname : $default;
         case 'port':
             return isset($this->port) ? $this->port : $default;
         case 'path':
             return isset($this->path) ? $this->path : $default;
         case 'query':
             return isset($this->query) ? $this->query : $default;
         case 'fragment':
             return isset($this->fragment) ? $this->fragment : $default;
         case 'request':
             // @FIXME: this work should probably be cached
             $request = '';
             if ($this->scheme) {
                 $request .= $this->scheme . "://";
             }
             if ($this->username && $this->password) {
                 $request .= $this->username . ":" . $this->password . '@';
             }
             $request .= $this->hostname;
             if ($this->port) {
                 $request .= ":" . $this->port . "/";
             }
             $request .= $this->path;
             if ($this->query) {
                 $request .= "?" . $this->query;
             }
             if ($this->fragment) {
                 $request .= "#" . $this->fragment;
             }
             return !empty($request) ? $request : $default;
         case 'queryvars':
             // can add variables to scope, so keep these braces to block out scope
             parse_str($this->get('query'), $queryvars);
             return $queryvars;
         case 'postdata':
             return $this->_post;
         case 'sbs':
             if (empty($this->method)) {
                 return false;
             }
             $sbs = oauth_get_sbs($this->method, $this->get('request'), $this->_post);
             return $sbs;
         default:
             break;
     }
 }
Exemple #5
0
 protected function oauth_get_sbs($http_method, $uri, $request_parameters = null)
 {
     return oauth_get_sbs($http_method, $uri, $request_parameters);
 }
Exemple #6
0
<?php

var_dump(oauth_get_sbs('GET', 'http://example.com/', array('z' => 'y', 'a' => 'b')));
Exemple #7
0
<?php

echo "-- only two parameters --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/'), "\n";
echo "-- using empty array --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', array()), "\n";
echo "-- using string instead of array --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', ''), "\n";
echo "-- using numeric keys masked as a string --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', array('1' => 'hello')), "\n";
echo "-- using string keys --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', array('test' => 'hello')), "\n";
echo "-- using same var in url and params --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/?test=hi', array('test' => 'hello')), "\n";
echo "-- using null inside params --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', array('test' => null)), "\n";
echo "-- putting oauth_signature inside by mistake --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', array('oauth_signature' => 'hello world')), "\n";
echo "-- merging url query and extra params --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/script?arg1=1', array('arg2' => '2')), "\n";