ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
OAuthUtil Class Reference
+ Collaboration diagram for 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

Definition at line 825 of file OAuth.php.

Member Function Documentation

◆ build_http_query()

static OAuthUtil::build_http_query (   $params)
static

Definition at line 958 of file OAuth.php.

References $keys, PHPMailer\PHPMailer\$params, $values, and urlencode_rfc3986().

Referenced by OAuthRequest\get_signable_parameters(), and OAuthRequest\to_postdata().

959  {
960  if (!$params) {
961  return '';
962  }
963 
964  // Urlencode both keys and values
967  $params = array_combine($keys, $values);
968 
969  // Parameters are sorted by name, using lexicographical byte value ordering.
970  // Ref: Spec: 9.1.1 (1)
971  uksort($params, 'strcmp');
972 
973  $pairs = array();
974  foreach ($params as $parameter => $value) {
975  if (is_array($value)) {
976  // If two or more parameters share the same name, they are sorted by their value
977  // Ref: Spec: 9.1.1 (1)
978  // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
979  sort($value, SORT_STRING);
980  foreach ($value as $duplicate_value) {
981  $pairs[] = $parameter . '=' . $duplicate_value;
982  }
983  } else {
984  $pairs[] = $parameter . '=' . $value;
985  }
986  }
987  // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
988  // Each name-value pair is separated by an '&' character (ASCII code 38)
989  return implode('&', $pairs);
990  }
static urlencode_rfc3986($input)
Definition: OAuth.php:827
$keys
$values
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_headers()

static OAuthUtil::get_headers ( )
static

Definition at line 871 of file OAuth.php.

References $_SERVER, $key, and $out.

Referenced by OAuthRequest\from_request().

872  {
873  if (function_exists('apache_request_headers')) {
874  // we need this to get the actual Authorization: header
875  // because apache tends to tell us it doesn't exist
876  $headers = apache_request_headers();
877 
878  // sanitize the output of apache_request_headers because
879  // we always want the keys to be Cased-Like-This and arh()
880  // returns the headers in the same case as they are in the
881  // request
882  $out = array();
883  foreach ($headers as $key => $value) {
884  $key = str_replace(
885  " ",
886  "-",
887  ucwords(strtolower(str_replace("-", " ", $key)))
888  );
889  $out[$key] = $value;
890  }
891  } else {
892  // otherwise we don't have apache and are just going to have to hope
893  // that $_SERVER actually contains what we need
894  $out = array();
895  if (isset($_SERVER['CONTENT_TYPE'])) {
896  $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
897  }
898  if (isset($_ENV['CONTENT_TYPE'])) {
899  $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
900  }
901 
902  foreach ($_SERVER as $key => $value) {
903  if (substr($key, 0, 5) == "HTTP_") {
904  // this is chaos, basically it is just there to capitalize the first
905  // letter of every word that is not an initial HTTP and strip HTTP
906  // code from przemek
907  $key = str_replace(
908  " ",
909  "-",
910  ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
911  );
912  $out[$key] = $value;
913  }
914  }
915  // The "Authorization" header may get turned into "Auth".
916  if (isset($out['Auth'])) {
917  $out['Authorization'] = $out['Auth'];
918  }
919  }
920  return $out;
921  }
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 OAuthUtil::parse_parameters (   $input)
static

Definition at line 926 of file OAuth.php.

References $input, and urldecode_rfc3986().

Referenced by OAuthRequest\__construct(), and OAuthRequest\from_request().

927  {
928  if (!isset($input) || !$input) {
929  return array();
930  }
931 
932  $pairs = explode('&', $input);
933 
934  $parsed_parameters = array();
935  foreach ($pairs as $pair) {
936  $split = explode('=', $pair, 2);
937  $parameter = OAuthUtil::urldecode_rfc3986($split[0]);
938  $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
939 
940  if (isset($parsed_parameters[$parameter])) {
941  // We have already recieved parameter(s) with this name, so add to the list
942  // of parameters with this name
943 
944  if (is_scalar($parsed_parameters[$parameter])) {
945  // This is the first duplicate, so transform scalar (string) into an array
946  // so we can add the duplicates
947  $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
948  }
949 
950  $parsed_parameters[$parameter][] = $value;
951  } else {
952  $parsed_parameters[$parameter] = $value;
953  }
954  }
955  return $parsed_parameters;
956  }
static urldecode_rfc3986($string)
Definition: OAuth.php:846
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ split_header()

static OAuthUtil::split_header (   $header,
  $only_allow_oauth_parameters = true 
)
static

Definition at line 856 of file OAuth.php.

References $h, $header, $i, PHPMailer\PHPMailer\$params, and urldecode_rfc3986().

Referenced by OAuthRequest\from_request().

857  {
858  $params = array();
859  if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
860  foreach ($matches[1] as $i => $h) {
861  $params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
862  }
863  if (isset($params['realm'])) {
864  unset($params['realm']);
865  }
866  }
867  return $params;
868  }
$h
static urldecode_rfc3986($string)
Definition: OAuth.php:846
$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 OAuthUtil::urldecode_rfc3986 (   $string)
static

Definition at line 846 of file OAuth.php.

Referenced by parse_parameters(), and split_header().

847  {
848  return urldecode($string);
849  }
+ Here is the caller graph for this function:

◆ urlencode_rfc3986()

static OAuthUtil::urlencode_rfc3986 (   $input)
static

Definition at line 827 of file OAuth.php.

References $input.

Referenced by build_http_query(), OAuthSignatureMethod_HMAC_SHA1\build_signature(), OAuthSignatureMethod_PLAINTEXT\build_signature(), OAuthRequest\get_signature_base_string(), OAuthRequest\to_header(), and OAuthToken\to_string().

828  {
829  if (is_array($input)) {
830  return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
831  } else if (is_scalar($input)) {
832  return str_replace(
833  '+',
834  ' ',
835  str_replace('%7E', '~', rawurlencode($input))
836  );
837  } else {
838  return '';
839  }
840  }
+ Here is the caller graph for this function:

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