3namespace ceLTIc\LTI\OAuth;
24 if (is_array($input)) {
25 return array_map(array(
'ceLTIc\LTI\OAuth\OAuthUtil',
'urlencode_rfc3986'), $input);
26 } elseif (is_scalar($input)) {
27 return str_replace(
'+',
' ', str_replace(
'%7E',
'~', rawurlencode($input)));
46 return urldecode($string);
62 public static function split_header($header, $only_allow_oauth_parameters =
true)
65 if (preg_match_all(
'/(' . ($only_allow_oauth_parameters ?
'oauth_' :
'') .
'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header,
67 foreach ($matches[1] as $i => $h) {
70 if (isset($params[
'realm'])) {
71 unset($params[
'realm']);
85 if (function_exists(
'apache_request_headers')) {
88 $headers = apache_request_headers();
95 foreach ($headers AS $key => $value) {
96 $key = str_replace(
" ",
"-", ucwords(strtolower(str_replace(
"-",
" ", $key))));
103 if (isset($_SERVER[
'CONTENT_TYPE']))
104 $out[
'Content-Type'] = $_SERVER[
'CONTENT_TYPE'];
105 if (isset($_ENV[
'CONTENT_TYPE']))
106 $out[
'Content-Type'] = $_ENV[
'CONTENT_TYPE'];
108 foreach ($_SERVER as $key => $value) {
109 if (substr($key, 0, 5) ==
'HTTP_') {
113 $key = str_replace(
' ',
'-', ucwords(strtolower(str_replace(
'_',
' ', substr($key, 5)))));
134 if (!isset($input) || !$input)
137 $pairs = explode(
'&', $input);
139 $parsed_parameters = array();
140 foreach ($pairs as $pair) {
141 $split = explode(
'=', $pair, 2);
145 if (isset($parsed_parameters[$parameter])) {
149 if (is_scalar($parsed_parameters[$parameter])) {
152 $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
155 $parsed_parameters[$parameter][] = $value;
157 $parsed_parameters[$parameter] = $value;
161 return $parsed_parameters;
179 $params = array_combine($keys, $values);
183 uksort($params,
'strcmp');
186 foreach ($params as $parameter => $value) {
187 if (is_array($value)) {
191 sort($value, SORT_STRING);
192 foreach ($value as $duplicate_value) {
193 $pairs[] = $parameter .
'=' . $duplicate_value;
196 $pairs[] = $parameter .
'=' . $value;
202 return implode(
'&', $pairs);
Class to provide OAuth utility methods.
static build_http_query($params)
Build HTTP query string.
static split_header($header, $only_allow_oauth_parameters=true)
Utility function for turning the Authorization: header into parameters, has to do some unescaping.
static urldecode_rfc3986($string)
URL decode.
static urlencode_rfc3986($input)
URL encode.
static parse_parameters($input)
Parse parameters.
static get_headers()
Helper to try to sort out headers for people who aren't running apache.