ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
IMSGlobal\LTI\OAuth\OAuthUtil Class Reference

Class to provide OAuth utility methods. More...

+ Collaboration diagram for IMSGlobal\LTI\OAuth\OAuthUtil:

Static Public Member Functions

static urlencode_rfc3986 ($input)
 
static urldecode_rfc3986 ($string)
 
static split_header ($header, $only_allow_oauth_parameters=true)
 
static get_headers ()
 
static parse_parameters ( $input)
 
static build_http_query ($params)
 

Detailed Description

Class to provide OAuth utility methods.

Version
2008-08-04 https://opensource.org/licenses/MIT The MIT License

Definition at line 12 of file OAuthUtil.php.

Member Function Documentation

◆ build_http_query()

static IMSGlobal\LTI\OAuth\OAuthUtil::build_http_query (   $params)
static

Definition at line 127 of file OAuthUtil.php.

References $keys, PHPMailer\PHPMailer\$params, $values, and IMSGlobal\LTI\OAuth\OAuthUtil\urlencode_rfc3986().

Referenced by IMSGlobal\LTI\OAuth\OAuthRequest\get_signable_parameters(), and IMSGlobal\LTI\OAuth\OAuthRequest\to_postdata().

127  {
128 
129  if (!$params) return '';
130 
131  // Urlencode both keys and values
134  $params = array_combine($keys, $values);
135 
136  // Parameters are sorted by name, using lexicographical byte value ordering.
137  // Ref: Spec: 9.1.1 (1)
138  uksort($params, 'strcmp');
139 
140  $pairs = array();
141  foreach ($params as $parameter => $value) {
142  if (is_array($value)) {
143  // If two or more parameters share the same name, they are sorted by their value
144  // Ref: Spec: 9.1.1 (1)
145  // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
146  sort($value, SORT_STRING);
147  foreach ($value as $duplicate_value) {
148  $pairs[] = $parameter . '=' . $duplicate_value;
149  }
150  } else {
151  $pairs[] = $parameter . '=' . $value;
152  }
153  }
154 
155  // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
156  // Each name-value pair is separated by an '&' character (ASCII code 38)
157  return implode('&', $pairs);
158 
159  }
$keys
static urlencode_rfc3986($input)
Definition: OAuthUtil.php:14
$values
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_headers()

static IMSGlobal\LTI\OAuth\OAuthUtil::get_headers ( )
static

Definition at line 54 of file OAuthUtil.php.

References $_SERVER, $key, and $out.

Referenced by IMSGlobal\LTI\OAuth\OAuthRequest\from_request().

54  {
55 
56  if (function_exists('apache_request_headers')) {
57  // we need this to get the actual Authorization: header
58  // because apache tends to tell us it doesn't exist
59  $headers = apache_request_headers();
60 
61  // sanitize the output of apache_request_headers because
62  // we always want the keys to be Cased-Like-This and arh()
63  // returns the headers in the same case as they are in the
64  // request
65  $out = array();
66  foreach ($headers AS $key => $value) {
67  $key = str_replace(" ", "-", ucwords(strtolower(str_replace("-", " ", $key))));
68  $out[$key] = $value;
69  }
70  } else {
71  // otherwise we don't have apache and are just going to have to hope
72  // that $_SERVER actually contains what we need
73  $out = array();
74  if( isset($_SERVER['CONTENT_TYPE']) )
75  $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
76  if( isset($_ENV['CONTENT_TYPE']) )
77  $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
78 
79  foreach ($_SERVER as $key => $value) {
80  if (substr($key, 0, 5) == 'HTTP_') {
81  // this is chaos, basically it is just there to capitalize the first
82  // letter of every word that is not an initial HTTP and strip HTTP
83  // code from przemek
84  $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
85  $out[$key] = $value;
86  }
87  }
88  }
89  return $out;
90  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ parse_parameters()

static IMSGlobal\LTI\OAuth\OAuthUtil::parse_parameters (   $input)
static

Definition at line 95 of file OAuthUtil.php.

References $input.

Referenced by IMSGlobal\LTI\OAuth\OAuthRequest\__construct(), and IMSGlobal\LTI\OAuth\OAuthRequest\from_request().

95  {
96 
97  if (!isset($input) || !$input) return array();
98 
99  $pairs = explode('&', $input);
100 
101  $parsed_parameters = array();
102  foreach ($pairs as $pair) {
103  $split = explode('=', $pair, 2);
104  $parameter = self::urldecode_rfc3986($split[0]);
105  $value = isset($split[1]) ? self::urldecode_rfc3986($split[1]) : '';
106 
107  if (isset($parsed_parameters[$parameter])) {
108  // We have already recieved parameter(s) with this name, so add to the list
109  // of parameters with this name
110 
111  if (is_scalar($parsed_parameters[$parameter])) {
112  // This is the first duplicate, so transform scalar (string) into an array
113  // so we can add the duplicates
114  $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
115  }
116 
117  $parsed_parameters[$parameter][] = $value;
118  } else {
119  $parsed_parameters[$parameter] = $value;
120  }
121  }
122 
123  return $parsed_parameters;
124 
125  }
+ Here is the caller graph for this function:

◆ split_header()

static IMSGlobal\LTI\OAuth\OAuthUtil::split_header (   $header,
  $only_allow_oauth_parameters = true 
)
static

Definition at line 37 of file OAuthUtil.php.

References $h, $header, $i, PHPMailer\PHPMailer\$params, and IMSGlobal\LTI\OAuth\OAuthUtil\urldecode_rfc3986().

Referenced by IMSGlobal\LTI\OAuth\OAuthRequest\from_request().

37  {
38 
39  $params = array();
40  if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
41  foreach ($matches[1] as $i => $h) {
42  $params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
43  }
44  if (isset($params['realm'])) {
45  unset($params['realm']);
46  }
47  }
48 
49  return $params;
50 
51  }
$h
static urldecode_rfc3986($string)
Definition: OAuthUtil.php:28
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ urldecode_rfc3986()

static IMSGlobal\LTI\OAuth\OAuthUtil::urldecode_rfc3986 (   $string)
static

Definition at line 28 of file OAuthUtil.php.

Referenced by IMSGlobal\LTI\OAuth\OAuthUtil\split_header().

28  {
29  return urldecode($string);
30  }
+ Here is the caller graph for this function:

◆ urlencode_rfc3986()

static IMSGlobal\LTI\OAuth\OAuthUtil::urlencode_rfc3986 (   $input)
static

Definition at line 14 of file OAuthUtil.php.

References $input.

Referenced by IMSGlobal\LTI\OAuth\OAuthUtil\build_http_query(), IMSGlobal\LTI\OAuth\OAuthSignatureMethod_HMAC_SHA1\build_signature(), IMSGlobal\LTI\OAuth\OAuthSignatureMethod_HMAC_SHA256\build_signature(), IMSGlobal\LTI\OAuth\OAuthRequest\get_signature_base_string(), IMSGlobal\LTI\OAuth\OAuthRequest\to_header(), and IMSGlobal\LTI\OAuth\OAuthToken\to_string().

14  {
15 
16  if (is_array($input)) {
17  return array_map(array('IMSGlobal\LTI\OAuth\OAuthUtil', 'urlencode_rfc3986'), $input);
18  } else if (is_scalar($input)) {
19  return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode($input)));
20  } else {
21  return '';
22  }
23  }
+ Here is the caller graph for this function:

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