ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 745 of file OAuth.php.

Member Function Documentation

◆ build_http_query()

static OAuthUtil::build_http_query (   $params)
static

Definition at line 860 of file OAuth.php.

References $keys, and urlencode_rfc3986().

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

861  {
862  if (!$params) {
863  return '';
864  }
865 
866  // Urlencode both keys and values
867  $keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
868  $values = OAuthUtil::urlencode_rfc3986(array_values($params));
869  $params = array_combine($keys, $values);
870 
871  // Parameters are sorted by name, using lexicographical byte value ordering.
872  // Ref: Spec: 9.1.1 (1)
873  uksort($params, 'strcmp');
874 
875  $pairs = array();
876  foreach ($params as $parameter => $value) {
877  if (is_array($value)) {
878  // If two or more parameters share the same name, they are sorted by their value
879  // Ref: Spec: 9.1.1 (1)
880  natsort($value);
881  foreach ($value as $duplicate_value) {
882  $pairs[] = $parameter . '=' . $duplicate_value;
883  }
884  } else {
885  $pairs[] = $parameter . '=' . $value;
886  }
887  }
888  // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
889  // Each name-value pair is separated by an '&' character (ASCII code 38)
890  return implode('&', $pairs);
891  }
static urlencode_rfc3986($input)
Definition: OAuth.php:747
$keys
Definition: metadata.php:187
+ 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 797 of file OAuth.php.

References $_SERVER, and $out.

Referenced by OAuthRequest\from_request().

798  {
799  if (function_exists('apache_request_headers')) {
800  // we need this to get the actual Authorization: header
801  // because apache tends to tell us it doesn't exist
802  return apache_request_headers();
803  }
804  // otherwise we don't have apache and are just going to have to hope
805  // that $_SERVER actually contains what we need
806  $out = array();
807  foreach ($_SERVER as $key => $value) {
808  if (substr($key, 0, 5) == "HTTP_") {
809  // this is chaos, basically it is just there to capitalize the first
810  // letter of every word that is not an initial HTTP and strip HTTP
811  // code from przemek
812  $key = str_replace(
813  " ",
814  "-",
815  ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
816  );
817  $out[$key] = $value;
818  }
819  }
820  return $out;
821  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ Here is the caller graph for this function:

◆ parse_parameters()

static OAuthUtil::parse_parameters (   $input)
static

Definition at line 826 of file OAuth.php.

References urldecode_rfc3986().

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

827  {
828  if (!isset($input) || !$input) {
829  return array();
830  }
831 
832  // fau: fix for PHP7
833  $pairs = explode('&', $input);
834 
835  $parsed_parameters = array();
836  foreach ($pairs as $pair) {
837  $split = explode('=', $pair, 2);
838  // fau.
839  $parameter = OAuthUtil::urldecode_rfc3986($split[0]);
840  $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
841 
842  if (isset($parsed_parameters[$parameter])) {
843  // We have already recieved parameter(s) with this name, so add to the list
844  // of parameters with this name
845 
846  if (is_scalar($parsed_parameters[$parameter])) {
847  // This is the first duplicate, so transform scalar (string) into an array
848  // so we can add the duplicates
849  $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
850  }
851 
852  $parsed_parameters[$parameter][] = $value;
853  } else {
854  $parsed_parameters[$parameter] = $value;
855  }
856  }
857  return $parsed_parameters;
858  }
static urldecode_rfc3986($string)
Definition: OAuth.php:766
+ 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 774 of file OAuth.php.

References urldecode_rfc3986().

Referenced by OAuthRequest\from_request().

775  {
776  $pattern = '/(([-_a-z]*)=("([^"]*)"|([^,]*)),?)/';
777  $offset = 0;
778  $params = array();
779  while (preg_match($pattern, $header, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
780  $match = $matches[0];
781  $header_name = $matches[2][0];
782  $header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0];
783  if (preg_match('/^oauth_/', $header_name) || !$only_allow_oauth_parameters) {
784  $params[$header_name] = OAuthUtil::urldecode_rfc3986($header_content);
785  }
786  $offset = $match[1] + strlen($match[0]);
787  }
788 
789  if (isset($params['realm'])) {
790  unset($params['realm']);
791  }
792 
793  return $params;
794  }
static urldecode_rfc3986($string)
Definition: OAuth.php:766
+ 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 766 of file OAuth.php.

Referenced by parse_parameters(), and split_header().

767  {
768  return urldecode($string);
769  }
+ Here is the caller graph for this function:

◆ urlencode_rfc3986()

static OAuthUtil::urlencode_rfc3986 (   $input)
static

Definition at line 747 of file OAuth.php.

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().

748  {
749  if (is_array($input)) {
750  return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
751  } elseif (is_scalar($input)) {
752  return str_replace(
753  '+',
754  ' ',
755  str_replace('%7E', '~', rawurlencode($input))
756  );
757  } else {
758  return '';
759  }
760  }
+ Here is the caller graph for this function:

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