ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 270 of file OAuth.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 280 of file OAuth.php.

281 {
282 $parameters = ($parameters) ? $parameters : array();
283 $parameters = array_merge(OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
284 $this->parameters = $parameters;
285 $this->http_method = $http_method;
286 $this->http_url = $http_url;
287 }
static parse_parameters($input)
Definition: OAuth.php:926

References $http_method, $http_url, $parameters, and OAuthUtil\parse_parameters().

+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

OAuthRequest::__toString ( )

Definition at line 509 of file OAuth.php.

510 {
511 return $this->to_url();
512 }
to_url()
builds a url usable for a GET request
Definition: OAuth.php:461

References to_url().

+ Here is the call graph for this function:

◆ build_signature()

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

Definition at line 526 of file OAuth.php.

527 {
528 $signature = $signature_method->build_signature($this, $consumer, $token);
529 return $signature;
530 }

References PHPMailer\PHPMailer\$token.

Referenced by sign_request().

+ Here is the caller graph for this function:

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

347 {
348 $parameters = ($parameters) ? $parameters : array();
349 $defaults = array("oauth_version" => OAuthRequest::$version,
350 "oauth_nonce" => OAuthRequest::generate_nonce(),
351 "oauth_timestamp" => OAuthRequest::generate_timestamp(),
352 "oauth_consumer_key" => $consumer->key);
353 if ($token)
354 $defaults['oauth_token'] = $token->key;
355
356 $parameters = array_merge($defaults, $parameters);
357
359 }
static $version
Definition: OAuth.php:277
static generate_timestamp()
util function: current timestamp
Definition: OAuth.php:535
static generate_nonce()
util function: current nonce
Definition: OAuth.php:543

References $http_method, $http_url, $parameters, PHPMailer\PHPMailer\$token, $version, generate_nonce(), and generate_timestamp().

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

+ 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 293 of file OAuth.php.

294 {
295 $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
296 ? 'http'
297 : 'https';
298 $http_url = ($http_url) ? $http_url : $scheme .
299 '://' . $_SERVER['SERVER_NAME'] .
300 ':' .
301 $_SERVER['SERVER_PORT'] .
302 $_SERVER['REQUEST_URI'];
303 $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
304
305 // We weren't handed any parameters, so let's find the ones relevant to
306 // this request.
307 // If you run XML-RPC or similar you should use this to provide your own
308 // parsed parameter-list
309 if (!$parameters) {
310 // Find request headers
311 $request_headers = OAuthUtil::get_headers();
312
313 // Parse the query-string to find GET parameters
315
316 // It's a POST request of the proper content-type, so parse POST
317 // parameters and add those overriding any duplicates from GET
318 if ($http_method == "POST"
319 && isset($request_headers['Content-Type'])
320 && strstr($request_headers['Content-Type'],
321 'application/x-www-form-urlencoded')
322 ) {
323 $post_data = OAuthUtil::parse_parameters(
324 file_get_contents(self::$POST_INPUT)
325 );
326 $parameters = array_merge($parameters, $post_data);
327 }
328
329 // We have a Authorization-header with OAuth data. Parse the header
330 // and add those overriding any duplicates from GET or POST
331 if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
332 $header_parameters = OAuthUtil::split_header(
333 $request_headers['Authorization']
334 );
335 $parameters = array_merge($parameters, $header_parameters);
336 }
337
338 }
339
341 }
static get_headers()
Definition: OAuth.php:871
static split_header($header, $only_allow_oauth_parameters=true)
Definition: OAuth.php:856
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

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

+ Here is the call graph for this function:

◆ generate_nonce()

static OAuthRequest::generate_nonce ( )
staticprivate

util function: current nonce

Definition at line 543 of file OAuth.php.

544 {
545 $mt = microtime();
546 $rand = mt_rand();
547
548 return md5($mt . $rand); // md5s look nicer than numbers
549 }

Referenced by from_consumer_and_token().

+ Here is the caller graph for this function:

◆ generate_timestamp()

static OAuthRequest::generate_timestamp ( )
staticprivate

util function: current timestamp

Definition at line 535 of file OAuth.php.

536 {
537 return time();
538 }

Referenced by from_consumer_and_token().

+ 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 433 of file OAuth.php.

434 {
435 return strtoupper($this->http_method);
436 }

Referenced by get_signature_base_string().

+ Here is the caller graph for this function:

◆ get_normalized_http_url()

OAuthRequest::get_normalized_http_url ( )

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

Definition at line 442 of file OAuth.php.

443 {
444 $parts = parse_url($this->http_url);
445
446 $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
447 $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
448 $host = (isset($parts['host'])) ? strtolower($parts['host']) : '';
449 $path = (isset($parts['path'])) ? $parts['path'] : '';
450
451 if (($scheme == 'https' && $port != '443')
452 || ($scheme == 'http' && $port != '80')) {
453 $host = "$host:$port";
454 }
455 return "$scheme://$host$path";
456 }
$path
Definition: aliased.php:25

References $path.

Referenced by get_signature_base_string(), and to_url().

+ Here is the caller graph for this function:

◆ get_parameter()

OAuthRequest::get_parameter (   $name)

Definition at line 377 of file OAuth.php.

378 {
379 return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
380 }

References $name.

◆ get_parameters()

OAuthRequest::get_parameters ( )

Definition at line 382 of file OAuth.php.

383 {
384 return $this->parameters;
385 }

References $parameters.

◆ get_signable_parameters()

OAuthRequest::get_signable_parameters ( )

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

Returns
string

Definition at line 396 of file OAuth.php.

397 {
398 // Grab all parameters
400
401 // Remove oauth_signature if present
402 // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
403 if (isset($params['oauth_signature'])) {
404 unset($params['oauth_signature']);
405 }
406
408 }
static build_http_query($params)
Definition: OAuth.php:958

References $parameters, PHPMailer\PHPMailer\$params, and OAuthUtil\build_http_query().

Referenced by get_signature_base_string().

+ Here is the call graph for this function:
+ Here is the caller 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 417 of file OAuth.php.

418 {
419 $parts = array(
423 );
424
425 $parts = OAuthUtil::urlencode_rfc3986($parts);
426
427 return implode('&', $parts);
428 }
get_normalized_http_method()
just uppercases the http method
Definition: OAuth.php:433
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:442
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
Definition: OAuth.php:396
static urlencode_rfc3986($input)
Definition: OAuth.php:827

References get_normalized_http_method(), get_normalized_http_url(), get_signable_parameters(), and OAuthUtil\urlencode_rfc3986().

+ Here is the call graph for this function:

◆ set_parameter()

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

Definition at line 361 of file OAuth.php.

362 {
363 if ($allow_duplicates && isset($this->parameters[$name])) {
364 // We have already added parameter(s) with this name, so add to the list
365 if (is_scalar($this->parameters[$name])) {
366 // This is the first duplicate, so transform scalar (string)
367 // into an array so we can add the duplicates
368 $this->parameters[$name] = array($this->parameters[$name]);
369 }
370
371 $this->parameters[$name][] = $value;
372 } else {
373 $this->parameters[$name] = $value;
374 }
375 }

References $name.

Referenced by sign_request().

+ Here is the caller graph for this function:

◆ sign_request()

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

Definition at line 515 of file OAuth.php.

516 {
517 $this->set_parameter(
518 "oauth_signature_method",
519 $signature_method->get_name(),
520 false
521 );
522 $signature = $this->build_signature($signature_method, $consumer, $token);
523 $this->set_parameter("oauth_signature", $signature, false);
524 }
set_parameter($name, $value, $allow_duplicates=true)
Definition: OAuth.php:361
build_signature($signature_method, $consumer, $token)
Definition: OAuth.php:526

References PHPMailer\PHPMailer\$token, build_signature(), and set_parameter().

+ Here is the call graph for this function:

◆ to_header()

OAuthRequest::to_header (   $realm = null)

builds the Authorization: header

Definition at line 482 of file OAuth.php.

483 {
484 $first = true;
485 if ($realm) {
486 $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
487 $first = false;
488 } else {
489 $out = 'Authorization: OAuth';
490 }
491
492 foreach ($this->parameters as $k => $v) {
493 if (substr($k, 0, 5) != "oauth") {
494 continue;
495 }
496 if (is_array($v)) {
497 throw new OAuthException('Arrays not supported in headers');
498 }
499 $out .= ($first) ? ' ' : ',';
501 '="' .
503 '"';
504 $first = false;
505 }
506 return $out;
507 }

References $out, and OAuthUtil\urlencode_rfc3986().

+ 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 474 of file OAuth.php.

475 {
476 return OAuthUtil::build_http_query($this->parameters);
477 }

References OAuthUtil\build_http_query().

Referenced by to_url().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_url()

OAuthRequest::to_url ( )

builds a url usable for a GET request

Definition at line 461 of file OAuth.php.

462 {
463 $post_data = $this->to_postdata();
464 $out = $this->get_normalized_http_url();
465 if ($post_data) {
466 $out .= '?'.$post_data;
467 }
468 return $out;
469 }
to_postdata()
builds the data one would send in a POST request
Definition: OAuth.php:474

References $out, get_normalized_http_url(), and to_postdata().

Referenced by __toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unset_parameter()

OAuthRequest::unset_parameter (   $name)

Definition at line 387 of file OAuth.php.

388 {
389 unset($this->parameters[$name]);
390 }

References $name.

Field Documentation

◆ $base_string

OAuthRequest::$base_string

Definition at line 276 of file OAuth.php.

◆ $http_method

OAuthRequest::$http_method
protected

Definition at line 273 of file OAuth.php.

Referenced by __construct(), from_consumer_and_token(), and from_request().

◆ $http_url

OAuthRequest::$http_url
protected

Definition at line 274 of file OAuth.php.

Referenced by __construct(), from_consumer_and_token(), and from_request().

◆ $parameters

OAuthRequest::$parameters
protected

◆ $POST_INPUT

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

Definition at line 278 of file OAuth.php.

◆ $version

OAuthRequest::$version = '1.0'
static

Definition at line 277 of file OAuth.php.

Referenced by from_consumer_and_token().


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