Example #1
0
 /**
  * Populates $_{SERVER,GET,POST} and whatever environment-variables needed to test everything..
  *
  * @param string $method GET or POST
  * @param string $uri What URI is the request to (eg http://example.com/foo?bar=baz)
  * @param string $post_data What should the post-data be
  * @param string $auth_header What to set the Authorization header to
  */
 public static function buildRequest($method, $uri, $post_data = '', $auth_header = '')
 {
     self::resetRequestVars();
     $method = strtoupper($method);
     $parts = parse_url($uri);
     $scheme = $parts['scheme'];
     $port = isset($parts['port']) && $parts['port'] ? $parts['port'] : ($scheme === 'https' ? '443' : '80');
     $host = $parts['host'];
     $path = isset($parts['path']) ? $parts['path'] : NULL;
     $query = isset($parts['query']) ? $parts['query'] : NULL;
     if ($scheme == 'https') {
         $_SERVER['HTTPS'] = 'on';
     }
     $_SERVER['REQUEST_METHOD'] = $method;
     $_SERVER['HTTP_HOST'] = $host;
     $_SERVER['SERVER_NAME'] = $host;
     $_SERVER['SERVER_PORT'] = $port;
     $_SERVER['SCRIPT_NAME'] = $path;
     $_SERVER['REQUEST_URI'] = $path . '?' . $query;
     $_SERVER['QUERY_STRING'] = $query . '';
     parse_str($query, $_GET);
     if ($method == 'POST') {
         $_SERVER['HTTP_CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
         $_POST = parse_str($post_data);
         \OAuth\Request::$POST_INPUT = 'data:application/x-www-form-urlencoded,' . $post_data;
     }
     if ($auth_header != '') {
         $_SERVER['HTTP_AUTHORIZATION'] = $auth_header;
     }
 }
Example #2
0
 public function testUnsetParameter()
 {
     $request = new \OAuth\Request('', '');
     $this->assertEquals(NULL, $request->getParameter('test'));
     $request->setParameter('test', 'foo');
     $this->assertEquals('foo', $request->getParameter('test'));
     $request->unsetParameter('test');
     $this->assertEquals(NULL, $request->getParameter('test'), 'Failed to unset parameter');
 }
Example #3
0
 /**
  * Build the LTI request using LTI params passed in as arguments
  *
  * @param string $url
  * @param string $method
  * @param array $params
  *
  * @return string
  */
 public function buildRequestUrl($url, $method, $params)
 {
     $params['lti_version'] = $this->getVersion();
     $request = new OAuth\Request($this->consumer, $url, $method, $params);
     return $request->signRequest($this->signatureMethod);
 }
Example #4
0
 /**
  * Initializes and makes the OAuth Request
  * 
  * @param  string $url    	API URL
  * @param  string $method 	HTTP method
  * @param  array  $params 	Request parameters
  * @return API response
  */
 protected function oAuthRequest($url, $method, $params)
 {
     $url = $this->buildRequestUrl($url);
     $request = new OAuth\Request($this->consumerCred, $this->accessToken, $method, $url, $params);
     $request->sign($this->consumerCred, $this->accessToken);
     if ($this->httpEngine) {
         return $this->httpCall($request);
     } else {
         return $this->curlCall($request);
     }
 }