ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 ($realm=null)
 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'
 

Protected Attributes

 $parameters
 
 $http_method
 
 $http_url
 

Static Private Member Functions

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

Detailed Description

Definition at line 249 of file OAuth.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 258 of file OAuth.php.

References array, and OAuthUtil\parse_parameters().

258  {
260  $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
261  $this->parameters = $parameters;
262  $this->http_method = $http_method;
263  $this->http_url = $http_url;
264  }
static parse_parameters( $input)
Definition: OAuth.php:856
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

OAuthRequest::__toString ( )

Definition at line 471 of file OAuth.php.

471  {
472  return $this->to_url();
473  }
to_url()
builds a url usable for a GET request
Definition: OAuth.php:428

◆ build_signature()

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

Definition at line 486 of file OAuth.php.

References $consumer.

486  {
487  $signature = $signature_method->build_signature($this, $consumer, $token);
488  return $signature;
489  }
$consumer
Definition: demo.php:30

◆ 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 322 of file OAuth.php.

References $consumer, $version, array, generate_nonce(), and generate_timestamp().

Referenced by sspmod_oauth_Consumer\getAccessToken(), sspmod_oauth_Consumer\getRequestToken(), sspmod_oauth_Consumer\getUserInfo(), and sspmod_oauth_Consumer\postRequest().

322  {
324  $defaults = array("oauth_version" => OAuthRequest::$version,
325  "oauth_nonce" => OAuthRequest::generate_nonce(),
326  "oauth_timestamp" => OAuthRequest::generate_timestamp(),
327  "oauth_consumer_key" => $consumer->key);
328  if ($token)
329  $defaults['oauth_token'] = $token->key;
330 
331  $parameters = array_merge($defaults, $parameters);
332 
334  }
static generate_timestamp()
util function: current timestamp
Definition: OAuth.php:494
static generate_nonce()
util function: current nonce
Definition: OAuth.php:501
static $version
Definition: OAuth.php:255
$consumer
Definition: demo.php:30
Create styles array
The data for the language used.
+ 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 270 of file OAuth.php.

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

270  {
271  $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
272  ? 'http'
273  : 'https';
274  $http_url = ($http_url) ? $http_url : $scheme .
275  '://' . $_SERVER['SERVER_NAME'] .
276  ':' .
277  $_SERVER['SERVER_PORT'] .
278  $_SERVER['REQUEST_URI'];
279  $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
280 
281  // We weren't handed any parameters, so let's find the ones relevant to
282  // this request.
283  // If you run XML-RPC or similar you should use this to provide your own
284  // parsed parameter-list
285  if (!$parameters) {
286  // Find request headers
287  $request_headers = OAuthUtil::get_headers();
288 
289  // Parse the query-string to find GET parameters
291 
292  // It's a POST request of the proper content-type, so parse POST
293  // parameters and add those overriding any duplicates from GET
294  if ($http_method == "POST"
295  && isset($request_headers['Content-Type'])
296  && strstr($request_headers['Content-Type'],
297  'application/x-www-form-urlencoded')
298  ) {
299  $post_data = OAuthUtil::parse_parameters(
300  file_get_contents(self::$POST_INPUT)
301  );
302  $parameters = array_merge($parameters, $post_data);
303  }
304 
305  // We have a Authorization-header with OAuth data. Parse the header
306  // and add those overriding any duplicates from GET or POST
307  if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
308  $header_parameters = OAuthUtil::split_header(
309  $request_headers['Authorization']
310  );
311  $parameters = array_merge($parameters, $header_parameters);
312  }
313 
314  }
315 
317  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
static parse_parameters( $input)
Definition: OAuth.php:856
static get_headers()
Definition: OAuth.php:804
static split_header($header, $only_allow_oauth_parameters=true)
Definition: OAuth.php:790
+ Here is the call graph for this function:

◆ generate_nonce()

static OAuthRequest::generate_nonce ( )
staticprivate

util function: current nonce

Definition at line 501 of file OAuth.php.

Referenced by from_consumer_and_token().

501  {
502  $mt = microtime();
503  $rand = mt_rand();
504 
505  return md5($mt . $rand); // md5s look nicer than numbers
506  }
+ Here is the caller graph for this function:

◆ generate_timestamp()

static OAuthRequest::generate_timestamp ( )
staticprivate

util function: current timestamp

Definition at line 494 of file OAuth.php.

References time.

Referenced by from_consumer_and_token().

494  {
495  return time();
496  }
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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 402 of file OAuth.php.

402  {
403  return strtoupper($this->http_method);
404  }

◆ get_normalized_http_url()

OAuthRequest::get_normalized_http_url ( )

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

Definition at line 410 of file OAuth.php.

References $path.

410  {
411  $parts = parse_url($this->http_url);
412 
413  $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
414  $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
415  $host = (isset($parts['host'])) ? strtolower($parts['host']) : '';
416  $path = (isset($parts['path'])) ? $parts['path'] : '';
417 
418  if (($scheme == 'https' && $port != '443')
419  || ($scheme == 'http' && $port != '80')) {
420  $host = "$host:$port";
421  }
422  return "$scheme://$host$path";
423  }

◆ get_parameter()

OAuthRequest::get_parameter (   $name)

Definition at line 351 of file OAuth.php.

References $name.

Referenced by OAuthServer\check_signature(), OAuthServer\get_consumer(), OAuthServer\get_signature_method(), and OAuthServer\get_token().

351  {
352  return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
353  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the caller graph for this function:

◆ get_parameters()

OAuthRequest::get_parameters ( )

Definition at line 355 of file OAuth.php.

355  {
356  return $this->parameters;
357  }

◆ get_signable_parameters()

OAuthRequest::get_signable_parameters ( )

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

Returns
string

Definition at line 367 of file OAuth.php.

References $params, and OAuthUtil\build_http_query().

367  {
368  // Grab all parameters
370 
371  // Remove oauth_signature if present
372  // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
373  if (isset($params['oauth_signature'])) {
374  unset($params['oauth_signature']);
375  }
376 
378  }
$params
Definition: disable.php:11
static build_http_query($params)
Definition: OAuth.php:885
+ 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 387 of file OAuth.php.

References array, and OAuthUtil\urlencode_rfc3986().

387  {
388  $parts = array(
390  $this->get_normalized_http_url(),
391  $this->get_signable_parameters()
392  );
393 
394  $parts = OAuthUtil::urlencode_rfc3986($parts);
395 
396  return implode('&', $parts);
397  }
static urlencode_rfc3986($input)
Definition: OAuth.php:763
get_normalized_http_method()
just uppercases the http method
Definition: OAuth.php:402
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
Definition: OAuth.php:367
Create styles array
The data for the language used.
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:410
+ Here is the call graph for this function:

◆ set_parameter()

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

Definition at line 336 of file OAuth.php.

References $name, and array.

336  {
337  if ($allow_duplicates && isset($this->parameters[$name])) {
338  // We have already added parameter(s) with this name, so add to the list
339  if (is_scalar($this->parameters[$name])) {
340  // This is the first duplicate, so transform scalar (string)
341  // into an array so we can add the duplicates
342  $this->parameters[$name] = array($this->parameters[$name]);
343  }
344 
345  $this->parameters[$name][] = $value;
346  } else {
347  $this->parameters[$name] = $value;
348  }
349  }
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.

◆ sign_request()

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

Definition at line 476 of file OAuth.php.

References $consumer.

476  {
477  $this->set_parameter(
478  "oauth_signature_method",
479  $signature_method->get_name(),
480  false
481  );
482  $signature = $this->build_signature($signature_method, $consumer, $token);
483  $this->set_parameter("oauth_signature", $signature, false);
484  }
set_parameter($name, $value, $allow_duplicates=true)
Definition: OAuth.php:336
$consumer
Definition: demo.php:30
build_signature($signature_method, $consumer, $token)
Definition: OAuth.php:486

◆ to_header()

OAuthRequest::to_header (   $realm = null)

builds the Authorization: header

Definition at line 447 of file OAuth.php.

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

447  {
448  $first = true;
449  if($realm) {
450  $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
451  $first = false;
452  } else
453  $out = 'Authorization: OAuth';
454 
455  $total = array();
456  foreach ($this->parameters as $k => $v) {
457  if (substr($k, 0, 5) != "oauth") continue;
458  if (is_array($v)) {
459  throw new OAuthException('Arrays not supported in headers');
460  }
461  $out .= ($first) ? ' ' : ',';
463  '="' .
465  '"';
466  $first = false;
467  }
468  return $out;
469  }
static urlencode_rfc3986($input)
Definition: OAuth.php:763
$total
Definition: Utf8Test.php:87
Create styles array
The data for the language used.
+ 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 440 of file OAuth.php.

References OAuthUtil\build_http_query().

440  {
441  return OAuthUtil::build_http_query($this->parameters);
442  }
static build_http_query($params)
Definition: OAuth.php:885
+ Here is the call graph for this function:

◆ to_url()

OAuthRequest::to_url ( )

builds a url usable for a GET request

Definition at line 428 of file OAuth.php.

References $out.

428  {
429  $post_data = $this->to_postdata();
430  $out = $this->get_normalized_http_url();
431  if ($post_data) {
432  $out .= '?'.$post_data;
433  }
434  return $out;
435  }
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:410
to_postdata()
builds the data one would send in a POST request
Definition: OAuth.php:440

◆ unset_parameter()

OAuthRequest::unset_parameter (   $name)

Definition at line 359 of file OAuth.php.

References $name.

359  {
360  unset($this->parameters[$name]);
361  }
if($format !==null) $name
Definition: metadata.php:146

Field Documentation

◆ $base_string

OAuthRequest::$base_string

Definition at line 254 of file OAuth.php.

◆ $http_method

OAuthRequest::$http_method
protected

Definition at line 251 of file OAuth.php.

◆ $http_url

OAuthRequest::$http_url
protected

Definition at line 252 of file OAuth.php.

◆ $parameters

OAuthRequest::$parameters
protected

Definition at line 250 of file OAuth.php.

◆ $POST_INPUT

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

Definition at line 256 of file OAuth.php.

◆ $version

OAuthRequest::$version = '1.0'
static

Definition at line 255 of file OAuth.php.

Referenced by from_consumer_and_token().


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