ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
OAuthRequest Class Reference
+ Collaboration diagram for OAuthRequest:

Public Member Functions

 __construct ($http_method, $http_url, $parameters=null)
 
 set_parameter ($name, $value, $allow_duplicates=true)
 
 get_parameter ($name)
 
 get_parameters ()
 
 unset_parameter ($name)
 
 get_signable_parameters ()
 The request parameters, sorted and concatenated into a normalized string. More...
 
 get_signature_base_string ()
 Returns the base string of this request. More...
 
 get_normalized_http_method ()
 just uppercases the http method More...
 
 get_normalized_http_url ()
 parses the url and rebuilds it to be scheme://host/path More...
 
 to_url ()
 builds a url usable for a GET request More...
 
 to_postdata ()
 builds the data one would send in a POST request More...
 
 to_header ()
 builds the Authorization: header More...
 
 __toString ()
 
 sign_request ($signature_method, $consumer, $token)
 
 build_signature ($signature_method, $consumer, $token)
 

Static Public Member Functions

static from_request ($http_method=null, $http_url=null, $parameters=null)
 attempt to build up a request from what was passed to the server More...
 
static from_consumer_and_token ($consumer, $token, $http_method, $http_url, $parameters=null)
 pretty much a helper function to set up the request More...
 

Data Fields

 $base_string
 

Static Public Attributes

static $version = '1.0'
 
static $POST_INPUT = 'php://input'
 

Static Private Member Functions

static generate_timestamp ()
 util function: current timestamp More...
 
static generate_nonce ()
 util function: current nonce More...
 

Private Attributes

 $parameters
 
 $http_method
 
 $http_url
 

Detailed Description

Definition at line 206 of file OAuth.php.

Constructor & Destructor Documentation

◆ __construct()

OAuthRequest::__construct (   $http_method,
  $http_url,
  $parameters = null 
)

Definition at line 216 of file OAuth.php.

217  {
218  @$parameters or $parameters = array();
219  $this->parameters = $parameters;
220  $this->http_method = $http_method;
221  $this->http_url = $http_url;
222  }

Member Function Documentation

◆ __toString()

OAuthRequest::__toString ( )

Definition at line 451 of file OAuth.php.

452  {
453  return $this->to_url();
454  }
to_url()
builds a url usable for a GET request
Definition: OAuth.php:410

◆ build_signature()

OAuthRequest::build_signature (   $signature_method,
  $consumer,
  $token 
)

Definition at line 468 of file OAuth.php.

References $token.

469  {
470  $signature = $signature_method->build_signature($this, $consumer, $token);
471  return $signature;
472  }
$token
Definition: xapitoken.php:52

◆ from_consumer_and_token()

static OAuthRequest::from_consumer_and_token (   $consumer,
  $token,
  $http_method,
  $http_url,
  $parameters = null 
)
static

pretty much a helper function to set up the request

Definition at line 284 of file OAuth.php.

References $token, $version, generate_nonce(), generate_timestamp(), and OAuthUtil\parse_parameters().

Referenced by ilLTIConsumerLaunch\signOAuth().

285  {
286  @$parameters or $parameters = array();
287  $defaults = array("oauth_version" => OAuthRequest::$version,
288  "oauth_nonce" => OAuthRequest::generate_nonce(),
289  "oauth_timestamp" => OAuthRequest::generate_timestamp(),
290  "oauth_consumer_key" => $consumer->key);
291  if ($token) {
292  $defaults['oauth_token'] = $token->key;
293  }
294 
295  $parameters = array_merge($defaults, $parameters);
296 
297  // Parse the query-string to find and add GET parameters
298  $parts = parse_url($http_url);
299  if ($parts['query']) {
300  $qparms = OAuthUtil::parse_parameters($parts['query']);
301  $parameters = array_merge($qparms, $parameters);
302  }
303 
304 
305  return new OAuthRequest($http_method, $http_url, $parameters);
306  }
static generate_timestamp()
util function: current timestamp
Definition: OAuth.php:477
static parse_parameters($input)
Definition: OAuth.php:826
static generate_nonce()
util function: current nonce
Definition: OAuth.php:485
$token
Definition: xapitoken.php:52
static $version
Definition: OAuth.php:213
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ from_request()

static OAuthRequest::from_request (   $http_method = null,
  $http_url = null,
  $parameters = null 
)
static

attempt to build up a request from what was passed to the server

Definition at line 228 of file OAuth.php.

References $_POST, $_SERVER, OAuthUtil\get_headers(), OAuthUtil\parse_parameters(), and OAuthUtil\split_header().

Referenced by ilLTIConsumerResultService\checkSignature().

229  {
230  $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
231  ? 'http'
232  : 'https';
233  $port = "";
234  if ($_SERVER['SERVER_PORT'] != "80" && $_SERVER['SERVER_PORT'] != "443" &&
235  strpos(':', $_SERVER['HTTP_HOST']) < 0) {
236  $port = ':' . $_SERVER['SERVER_PORT'] ;
237  }
238  @$http_url or $http_url = $scheme .
239  '://' . $_SERVER['HTTP_HOST'] .
240  $port .
241  $_SERVER['REQUEST_URI'];
242  @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
243 
244  // We weren't handed any parameters, so let's find the ones relevant to
245  // this request.
246  // If you run XML-RPC or similar you should use this to provide your own
247  // parsed parameter-list
248  if (!$parameters) {
249  // Find request headers
250  $request_headers = OAuthUtil::get_headers();
251 
252  // Parse the query-string to find GET parameters
254 
255  $ourpost = $_POST;
256  // Deal with magic_quotes
257  // http://www.php.net/manual/en/security.magicquotes.disabling.php
258  if (get_magic_quotes_gpc()) {
259  $outpost = array();
260  foreach ($_POST as $k => $v) {
261  $v = stripslashes($v);
262  $ourpost[$k] = $v;
263  }
264  }
265  // Add POST Parameters if they exist
266  $parameters = array_merge($parameters, $ourpost);
267 
268  // We have a Authorization-header with OAuth data. Parse the header
269  // and add those overriding any duplicates from GET or POST
270  if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
271  $header_parameters = OAuthUtil::split_header(
272  $request_headers['Authorization']
273  );
274  $parameters = array_merge($parameters, $header_parameters);
275  }
276  }
277 
278  return new OAuthRequest($http_method, $http_url, $parameters);
279  }
static parse_parameters($input)
Definition: OAuth.php:826
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
static get_headers()
Definition: OAuth.php:797
$_POST["username"]
static split_header($header, $only_allow_oauth_parameters=true)
Definition: OAuth.php:774
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_nonce()

static OAuthRequest::generate_nonce ( )
staticprivate

util function: current nonce

Definition at line 485 of file OAuth.php.

Referenced by from_consumer_and_token().

486  {
487  $mt = microtime();
488  $rand = mt_rand();
489 
490  return md5($mt . $rand); // md5s look nicer than numbers
491  }
+ Here is the caller graph for this function:

◆ generate_timestamp()

static OAuthRequest::generate_timestamp ( )
staticprivate

util function: current timestamp

Definition at line 477 of file OAuth.php.

Referenced by from_consumer_and_token().

478  {
479  return time();
480  }
+ Here is the caller graph for this function:

◆ get_normalized_http_method()

OAuthRequest::get_normalized_http_method ( )

just uppercases the http method

Definition at line 380 of file OAuth.php.

381  {
382  return strtoupper($this->http_method);
383  }

◆ get_normalized_http_url()

OAuthRequest::get_normalized_http_url ( )

parses the url and rebuilds it to be scheme://host/path

Definition at line 389 of file OAuth.php.

390  {
391  $parts = parse_url($this->http_url);
392 
393  $port = @$parts['port'];
394  $scheme = $parts['scheme'];
395  $host = $parts['host'];
396  $path = @$parts['path'];
397 
398  $port or $port = ($scheme == 'https') ? '443' : '80';
399 
400  if (($scheme == 'https' && $port != '443')
401  || ($scheme == 'http' && $port != '80')) {
402  $host = "$host:$port";
403  }
404  return "$scheme://$host$path";
405  }

◆ get_parameter()

OAuthRequest::get_parameter (   $name)

Definition at line 324 of file OAuth.php.

References $name.

325  {
326  return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
327  }
if($format !==null) $name
Definition: metadata.php:230

◆ get_parameters()

OAuthRequest::get_parameters ( )

Definition at line 329 of file OAuth.php.

330  {
331  return $this->parameters;
332  }

◆ get_signable_parameters()

OAuthRequest::get_signable_parameters ( )

The request parameters, sorted and concatenated into a normalized string.

Returns
string

Definition at line 343 of file OAuth.php.

References OAuthUtil\build_http_query().

344  {
345  // Grab all parameters
346  $params = $this->parameters;
347 
348  // Remove oauth_signature if present
349  // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
350  if (isset($params['oauth_signature'])) {
351  unset($params['oauth_signature']);
352  }
353 
354  return OAuthUtil::build_http_query($params);
355  }
static build_http_query($params)
Definition: OAuth.php:860
+ Here is the call graph for this function:

◆ get_signature_base_string()

OAuthRequest::get_signature_base_string ( )

Returns the base string of this request.

The base string defined as the method, the url and the parameters (normalized), each urlencoded and the concated with &.

Definition at line 364 of file OAuth.php.

References OAuthUtil\urlencode_rfc3986().

365  {
366  $parts = array(
368  $this->get_normalized_http_url(),
369  $this->get_signable_parameters()
370  );
371 
372  $parts = OAuthUtil::urlencode_rfc3986($parts);
373 
374  return implode('&', $parts);
375  }
static urlencode_rfc3986($input)
Definition: OAuth.php:747
get_normalized_http_method()
just uppercases the http method
Definition: OAuth.php:380
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
Definition: OAuth.php:343
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:389
+ Here is the call graph for this function:

◆ set_parameter()

OAuthRequest::set_parameter (   $name,
  $value,
  $allow_duplicates = true 
)

Definition at line 308 of file OAuth.php.

References $name.

309  {
310  if ($allow_duplicates && isset($this->parameters[$name])) {
311  // We have already added parameter(s) with this name, so add to the list
312  if (is_scalar($this->parameters[$name])) {
313  // This is the first duplicate, so transform scalar (string)
314  // into an array so we can add the duplicates
315  $this->parameters[$name] = array($this->parameters[$name]);
316  }
317 
318  $this->parameters[$name][] = $value;
319  } else {
320  $this->parameters[$name] = $value;
321  }
322  }
if($format !==null) $name
Definition: metadata.php:230

◆ sign_request()

OAuthRequest::sign_request (   $signature_method,
  $consumer,
  $token 
)

Definition at line 457 of file OAuth.php.

References $token.

458  {
459  $this->set_parameter(
460  "oauth_signature_method",
461  $signature_method->get_name(),
462  false
463  );
464  $signature = $this->build_signature($signature_method, $consumer, $token);
465  $this->set_parameter("oauth_signature", $signature, false);
466  }
set_parameter($name, $value, $allow_duplicates=true)
Definition: OAuth.php:308
$token
Definition: xapitoken.php:52
build_signature($signature_method, $consumer, $token)
Definition: OAuth.php:468

◆ to_header()

OAuthRequest::to_header ( )

builds the Authorization: header

Definition at line 431 of file OAuth.php.

References $out, $total, and OAuthUtil\urlencode_rfc3986().

432  {
433  $out = 'Authorization: OAuth realm=""';
434  $total = array();
435  foreach ($this->parameters as $k => $v) {
436  if (substr($k, 0, 5) != "oauth") {
437  continue;
438  }
439  if (is_array($v)) {
440  throw new OAuthException('Arrays not supported in headers');
441  }
442  $out .= ',' .
444  '="' .
446  '"';
447  }
448  return $out;
449  }
static urlencode_rfc3986($input)
Definition: OAuth.php:747
$total
Definition: Utf8Test.php:87
+ Here is the call graph for this function:

◆ to_postdata()

OAuthRequest::to_postdata ( )

builds the data one would send in a POST request

Definition at line 423 of file OAuth.php.

References OAuthUtil\build_http_query().

424  {
425  return OAuthUtil::build_http_query($this->parameters);
426  }
static build_http_query($params)
Definition: OAuth.php:860
+ Here is the call graph for this function:

◆ to_url()

OAuthRequest::to_url ( )

builds a url usable for a GET request

Definition at line 410 of file OAuth.php.

References $out.

411  {
412  $post_data = $this->to_postdata();
413  $out = $this->get_normalized_http_url();
414  if ($post_data) {
415  $out .= '?' . $post_data;
416  }
417  return $out;
418  }
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:389
to_postdata()
builds the data one would send in a POST request
Definition: OAuth.php:423

◆ unset_parameter()

OAuthRequest::unset_parameter (   $name)

Definition at line 334 of file OAuth.php.

References $name.

335  {
336  unset($this->parameters[$name]);
337  }
if($format !==null) $name
Definition: metadata.php:230

Field Documentation

◆ $base_string

OAuthRequest::$base_string

Definition at line 212 of file OAuth.php.

◆ $http_method

OAuthRequest::$http_method
private

Definition at line 209 of file OAuth.php.

◆ $http_url

OAuthRequest::$http_url
private

Definition at line 210 of file OAuth.php.

◆ $parameters

OAuthRequest::$parameters
private

Definition at line 208 of file OAuth.php.

◆ $POST_INPUT

OAuthRequest::$POST_INPUT = 'php://input'
static

Definition at line 214 of file OAuth.php.

◆ $version

OAuthRequest::$version = '1.0'
static

Definition at line 213 of file OAuth.php.

Referenced by from_consumer_and_token().


The documentation for this class was generated from the following file: