ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
OAuth.php
Go to the documentation of this file.
1 <?php
11 if (!class_exists('OAuthException')) {
12  /*
13  * Generic exception class
14  */
15  class OAuthException extends Exception
16  {
17  // pass
18  }
19 }
20 
21 if (!class_exists('OAuthConsumer')) {
22  class OAuthConsumer
23  {
24  public $key;
25  public $secret;
26  public $callback_url;
27 
28  public function __construct($key, $secret, $callback_url = null)
29  {
30  $this->key = $key;
31  $this->secret = $secret;
32  $this->callback_url = $callback_url;
33  }
34 
35  public function __toString()
36  {
37  return "OAuthConsumer[key=$this->key,secret=$this->secret]";
38  }
39  }
40 }
41 
43 {
44  // access tokens and request tokens
45  public $key;
46  public $secret;
47 
52  public function __construct($key, $secret)
53  {
54  $this->key = $key;
55  $this->secret = $secret;
56  }
57 
62  public function to_string()
63  {
64  return "oauth_token=" .
65  OAuthUtil::urlencode_rfc3986($this->key) .
66  "&oauth_token_secret=" .
67  OAuthUtil::urlencode_rfc3986($this->secret) .
68  "&oauth_callback_confirmed=true";
69  }
70 
71  public function __toString()
72  {
73  return $this->to_string();
74  }
75 }
76 
81 abstract class OAuthSignatureMethod
82 {
87  abstract public function get_name();
88 
99  abstract public function build_signature($request, $consumer, $token);
100 
109  public function check_signature($request, $consumer, $token, $signature)
110  {
111  $built = $this->build_signature($request, $consumer, $token);
112 
113  // Check for zero length, although unlikely here
114  if (strlen($built) == 0 || strlen($signature) == 0) {
115  return false;
116  }
117 
118  if (strlen($built) != strlen($signature)) {
119  return false;
120  }
121 
122  // Avoid a timing leak with a (hopefully) time insensitive compare
123  $result = 0;
124  for ($i = 0; $i < strlen($signature); $i++) {
125  $result |= ord($built{$i}) ^ ord($signature{$i});
126  }
127 
128  return $result == 0;
129  }
130 }
131 
140 {
141  public function get_name()
142  {
143  return "HMAC-SHA1";
144  }
145 
146  public function build_signature($request, $consumer, $token)
147  {
148  $base_string = $request->get_signature_base_string();
149  $request->base_string = $base_string;
150 
151  $key_parts = array(
152  $consumer->secret,
153  ($token) ? $token->secret : ""
154  );
155 
156  $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
157  $key = implode('&', $key_parts);
158 
159  return base64_encode(hash_hmac('sha1', $base_string, $key, true));
160  }
161 }
162 
169 {
170  public function get_name()
171  {
172  return "PLAINTEXT";
173  }
174 
184  public function build_signature($request, $consumer, $token)
185  {
186  $key_parts = array(
187  $consumer->secret,
188  ($token) ? $token->secret : ""
189  );
190 
191  $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
192  $key = implode('&', $key_parts);
193  $request->base_string = $key;
194 
195  return $key;
196  }
197 }
198 
208 {
209  public function get_name()
210  {
211  return "RSA-SHA1";
212  }
213 
214  // Up to the SP to implement this lookup of keys. Possible ideas are:
215  // (1) do a lookup in a table of trusted certs keyed off of consumer
216  // (2) fetch via http using a url provided by the requester
217  // (3) some sort of specific discovery code based on request
218  //
219  // Either way should return a string representation of the certificate
220  abstract protected function fetch_public_cert(&$request);
221 
222  // Up to the SP to implement this lookup of keys. Possible ideas are:
223  // (1) do a lookup in a table of trusted certs keyed off of consumer
224  //
225  // Either way should return a string representation of the certificate
226  abstract protected function fetch_private_cert(&$request);
227 
228  public function build_signature($request, $consumer, $token)
229  {
230  $base_string = $request->get_signature_base_string();
231  $request->base_string = $base_string;
232 
233  // Fetch the private key cert based on the request
234  $cert = $this->fetch_private_cert($request);
235 
236  // Pull the private key ID from the certificate
237  $privatekeyid = openssl_get_privatekey($cert);
238 
239  // Sign using the key
240  openssl_sign($base_string, $signature, $privatekeyid);
241 
242  // Release the key resource
243  openssl_free_key($privatekeyid);
244 
245  return base64_encode($signature);
246  }
247 
248  public function check_signature($request, $consumer, $token, $signature)
249  {
250  $decoded_sig = base64_decode($signature);
251 
252  $base_string = $request->get_signature_base_string();
253 
254  // Fetch the public key cert based on the request
255  $cert = $this->fetch_public_cert($request);
256 
257  // Pull the public key ID from the certificate
258  $publickeyid = openssl_get_publickey($cert);
259 
260  // Check the computed signature against the one passed in the query
261  $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
262 
263  // Release the key resource
264  openssl_free_key($publickeyid);
265 
266  return $ok == 1;
267  }
268 }
269 
271 {
272  protected $parameters;
273  protected $http_method;
274  protected $http_url;
275  // for debug purposes
276  public $base_string;
277  public static $version = '1.0';
278  public static $POST_INPUT = 'php://input';
279 
280  public function __construct($http_method, $http_url, $parameters = null)
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  }
288 
289 
293  public static function from_request($http_method = null, $http_url = null, $parameters = null)
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
314  $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
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 
340  return new OAuthRequest($http_method, $http_url, $parameters);
341  }
342 
346  public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = null)
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 
358  return new OAuthRequest($http_method, $http_url, $parameters);
359  }
360 
361  public function set_parameter($name, $value, $allow_duplicates = true)
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  }
376 
377  public function get_parameter($name)
378  {
379  return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
380  }
381 
382  public function get_parameters()
383  {
384  return $this->parameters;
385  }
386 
387  public function unset_parameter($name)
388  {
389  unset($this->parameters[$name]);
390  }
391 
396  public function get_signable_parameters()
397  {
398  // Grab all parameters
399  $params = $this->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  }
409 
417  public function get_signature_base_string()
418  {
419  $parts = array(
420  $this->get_normalized_http_method(),
421  $this->get_normalized_http_url(),
422  $this->get_signable_parameters()
423  );
424 
425  $parts = OAuthUtil::urlencode_rfc3986($parts);
426 
427  return implode('&', $parts);
428  }
429 
433  public function get_normalized_http_method()
434  {
435  return strtoupper($this->http_method);
436  }
437 
442  public function get_normalized_http_url()
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  }
457 
461  public function to_url()
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  }
470 
474  public function to_postdata()
475  {
476  return OAuthUtil::build_http_query($this->parameters);
477  }
478 
482  public function to_header($realm = null)
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  }
508 
509  public function __toString()
510  {
511  return $this->to_url();
512  }
513 
514 
515  public function sign_request($signature_method, $consumer, $token)
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  }
525 
526  public function build_signature($signature_method, $consumer, $token)
527  {
528  $signature = $signature_method->build_signature($this, $consumer, $token);
529  return $signature;
530  }
531 
535  private static function generate_timestamp()
536  {
537  return time();
538  }
539 
543  private static function generate_nonce()
544  {
545  $mt = microtime();
546  $rand = mt_rand();
547 
548  return md5($mt . $rand); // md5s look nicer than numbers
549  }
550 }
551 
553 {
554  protected $timestamp_threshold = 300; // in seconds, five minutes
555  protected $version = '1.0'; // hi blaine
556  protected $signature_methods = array();
557 
558  protected $data_store;
559 
560  public function __construct($data_store)
561  {
562  $this->data_store = $data_store;
563  }
564 
565  public function add_signature_method($signature_method)
566  {
567  $this->signature_methods[$signature_method->get_name()] =
568  $signature_method;
569  }
570 
571  // high level functions
572 
577  public function fetch_request_token(&$request)
578  {
579  $this->get_version($request);
580 
581  $consumer = $this->get_consumer($request);
582 
583  // no token required for the initial token request
584  $token = NULL;
585 
586  $this->check_signature($request, $consumer, $token);
587 
588  // Rev A change
589  $callback = $request->get_parameter('oauth_callback');
590  $new_token = $this->data_store->new_request_token($consumer, $callback);
591 
592  return $new_token;
593  }
594 
599  public function fetch_access_token(&$request)
600  {
601  $this->get_version($request);
602 
603  $consumer = $this->get_consumer($request);
604 
605  // requires authorized request token
606  $token = $this->get_token($request, $consumer, "request");
607 
608  $this->check_signature($request, $consumer, $token);
609 
610  // Rev A change
611  $verifier = $request->get_parameter('oauth_verifier');
612  $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
613 
614  return $new_token;
615  }
616 
620  public function verify_request(&$request)
621  {
622  $this->get_version($request);
623  $consumer = $this->get_consumer($request);
624  $token = $this->get_token($request, $consumer, "access");
625  $this->check_signature($request, $consumer, $token);
626  return array($consumer, $token);
627  }
628 
629  // Internals from here
633  private function get_version(&$request)
634  {
635  $version = $request->get_parameter("oauth_version");
636  if (!$version) {
637  // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
638  // Chapter 7.0 ("Accessing Protected Ressources")
639  $version = '1.0';
640  }
641  if ($version !== $this->version) {
642  throw new OAuthException("OAuth version '$version' not supported");
643  }
644  return $version;
645  }
646 
650  private function get_signature_method($request)
651  {
652  $signature_method = $request instanceof OAuthRequest
653  ? $request->get_parameter("oauth_signature_method")
654  : NULL;
655 
656  if (!$signature_method) {
657  // According to chapter 7 ("Accessing Protected Ressources") the signature-method
658  // parameter is required, and we can't just fallback to PLAINTEXT
659  throw new OAuthException('No signature method parameter. This parameter is required');
660  }
661 
662  if (!in_array($signature_method,
663  array_keys($this->signature_methods))) {
664  throw new OAuthException(
665  "Signature method '$signature_method' not supported " .
666  "try one of the following: " .
667  implode(", ", array_keys($this->signature_methods))
668  );
669  }
670  return $this->signature_methods[$signature_method];
671  }
672 
676  private function get_consumer($request)
677  {
678  $consumer_key = $request instanceof OAuthRequest
679  ? $request->get_parameter("oauth_consumer_key")
680  : NULL;
681 
682  if (!$consumer_key) {
683  throw new OAuthException("Invalid consumer key");
684  }
685 
686  $consumer = $this->data_store->lookup_consumer($consumer_key);
687  if (!$consumer) {
688  throw new OAuthException("Invalid consumer");
689  }
690 
691  return $consumer;
692  }
693 
697  private function get_token($request, $consumer, $token_type="access")
698  {
699  $token_field = $request instanceof OAuthRequest
700  ? $request->get_parameter('oauth_token')
701  : null;
702 
703  if (!empty($token_field)) {
704  $token = $this->data_store->lookup_token(
705  $consumer, $token_type, $token_field
706  );
707  if (!$token) {
708  throw new OAuthException("Invalid $token_type token: $token_field");
709  }
710  }
711  else {
712  $token = new OAuthToken('', '');
713  }
714  return $token;
715  }
716 
721  private function check_signature($request, $consumer, $token)
722  {
723  // this should probably be in a different method
724  $timestamp = $request instanceof OAuthRequest
725  ? $request->get_parameter('oauth_timestamp')
726  : null;
727  $nonce = $request instanceof OAuthRequest
728  ? $request->get_parameter('oauth_nonce')
729  : null;
730 
731  $this->check_timestamp($timestamp);
732  $this->check_nonce($consumer, $token, $nonce, $timestamp);
733 
734  $signature_method = $this->get_signature_method($request);
735 
736  $signature = $request->get_parameter('oauth_signature');
737  $valid_sig = $signature_method->check_signature(
738  $request,
739  $consumer,
740  $token,
741  $signature
742  );
743 
744  if (!$valid_sig) {
745  throw new OAuthException("Invalid signature");
746  }
747  }
748 
752  private function check_timestamp($timestamp)
753  {
754  if (!$timestamp) {
755  throw new OAuthException(
756  'Missing timestamp parameter. The parameter is required'
757  );
758  }
759 
760  // verify that timestamp is recentish
761  $now = time();
762  if (abs($now - $timestamp) > $this->timestamp_threshold) {
763  throw new OAuthException(
764  "Expired timestamp, yours $timestamp, ours $now"
765  );
766  }
767  }
768 
772  private function check_nonce($consumer, $token, $nonce, $timestamp)
773  {
774  if (!$nonce) {
775  throw new OAuthException(
776  'Missing nonce parameter. The parameter is required'
777  );
778  }
779 
780  // verify that the nonce is uniqueish
781  $found = $this->data_store->lookup_nonce(
782  $consumer,
783  $token,
784  $nonce,
785  $timestamp
786  );
787  if ($found) {
788  throw new OAuthException("Nonce already used: $nonce");
789  }
790  }
791 }
792 
794 {
795  public function lookup_consumer($consumer_key)
796  {
797  // implement me
798  }
799 
800  public function lookup_token($consumer, $token_type, $token)
801  {
802  // implement me
803  }
804 
805  public function lookup_nonce($consumer, $token, $nonce, $timestamp)
806  {
807  // implement me
808  }
809 
810  public function new_request_token($consumer, $callback = null)
811  {
812  // return a new token attached to this consumer
813  }
814 
815  public function new_access_token($token, $consumer, $verifier = null)
816  {
817  // return a new access token attached to this consumer
818  // for the user associated with this token if the request token
819  // is authorized
820  // should also invalidate the request token
821  }
822 
823 }
824 
826 {
827  public static function urlencode_rfc3986($input)
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  }
841 
842 
843  // This decode function isn't taking into consideration the above
844  // modifications to the encoding process. However, this method doesn't
845  // seem to be used anywhere so leaving it as is.
846  public static function urldecode_rfc3986($string)
847  {
848  return urldecode($string);
849  }
850 
851  // Utility function for turning the Authorization: header into
852  // parameters, has to do some unescaping
853  // Can filter out any non-oauth parameters if needed (default behaviour)
854  // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
855  // see http://code.google.com/p/oauth/issues/detail?id=163
856  public static function split_header($header, $only_allow_oauth_parameters = true)
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  }
869 
870  // helper to try to sort out headers for people who aren't running apache
871  public static function get_headers()
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  }
922 
923  // This function takes a input like a=b&a=c&d=e and returns the parsed
924  // parameters like this
925  // array('a' => array('b','c'), 'd' => 'e')
926  public static function parse_parameters($input)
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  }
957 
958  public static function build_http_query($params)
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  }
991 }
to_string()
generates the basic string serialization of a token that a server would respond to request_token and ...
Definition: OAuth.php:62
new_access_token($token, $consumer, $verifier=null)
Definition: OAuth.php:815
check_timestamp($timestamp)
check that the timestamp is new enough
Definition: OAuth.php:752
A class for implementing a Signature Method See section 9 ("Signing Requests") in the spec...
Definition: OAuth.php:81
$path
Definition: aliased.php:25
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
static generate_timestamp()
util function: current timestamp
Definition: OAuth.php:535
check_signature($request, $consumer, $token, $signature)
Definition: OAuth.php:248
set_parameter($name, $value, $allow_duplicates=true)
Definition: OAuth.php:361
static urlencode_rfc3986($input)
Definition: OAuth.php:827
static parse_parameters($input)
Definition: OAuth.php:926
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
static from_request($http_method=null, $http_url=null, $parameters=null)
attempt to build up a request from what was passed to the server
Definition: OAuth.php:293
$h
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:42
build_signature($request, $consumer, $token)
oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret...
Definition: OAuth.php:184
check_nonce($consumer, $token, $nonce, $timestamp)
check that the nonce is not repeated
Definition: OAuth.php:772
static urldecode_rfc3986($string)
Definition: OAuth.php:846
lookup_nonce($consumer, $token, $nonce, $timestamp)
Definition: OAuth.php:805
get_normalized_http_method()
just uppercases the http method
Definition: OAuth.php:433
static generate_nonce()
util function: current nonce
Definition: OAuth.php:543
$keys
add_signature_method($signature_method)
Definition: OAuth.php:565
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
Definition: OAuth.php:396
__construct($http_method, $http_url, $parameters=null)
Definition: OAuth.php:280
__toString()
Definition: OAuth.php:509
check_signature($request, $consumer, $token)
all-in-one function to check the signature on a request should guess the signature method appropriate...
Definition: OAuth.php:721
get_parameter($name)
Definition: OAuth.php:377
$version
Definition: build.php:27
check_signature($request, $consumer, $token, $signature)
Verifies that a given signature is correct.
Definition: OAuth.php:109
get_version(&$request)
version 1
Definition: OAuth.php:633
verify_request(&$request)
verify an api call, checks all the parameters
Definition: OAuth.php:620
static build_http_query($params)
Definition: OAuth.php:958
lookup_consumer($consumer_key)
Definition: OAuth.php:795
__toString()
Definition: OAuth.php:71
$values
fetch_request_token(&$request)
process a request_token request returns the request token on success
Definition: OAuth.php:577
lookup_token($consumer, $token_type, $token)
Definition: OAuth.php:800
unset_parameter($name)
Definition: OAuth.php:387
static $version
Definition: OAuth.php:277
to_url()
builds a url usable for a GET request
Definition: OAuth.php:461
The PLAINTEXT method does not provide any security protection and SHOULD only be used over a secure c...
Definition: OAuth.php:168
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:442
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
build_signature($request, $consumer, $token)
Definition: OAuth.php:146
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=null)
pretty much a helper function to set up the request
Definition: OAuth.php:346
get_signature_method($request)
figure out the signature with some defaults
Definition: OAuth.php:650
build_signature($request, $consumer, $token)
Definition: OAuth.php:228
get_parameters()
Definition: OAuth.php:382
static get_headers()
Definition: OAuth.php:871
The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in [RFC3447] ...
Definition: OAuth.php:207
new_request_token($consumer, $callback=null)
Definition: OAuth.php:810
get_token($request, $consumer, $token_type="access")
try to find the token for the provided request&#39;s token key
Definition: OAuth.php:697
__construct($data_store)
Definition: OAuth.php:560
$i
Definition: disco.tpl.php:19
get_consumer($request)
try to find the consumer for the provided request&#39;s consumer key
Definition: OAuth.php:676
sign_request($signature_method, $consumer, $token)
Definition: OAuth.php:515
The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] where t...
Definition: OAuth.php:139
get_signature_base_string()
Returns the base string of this request.
Definition: OAuth.php:417
__construct($key, $secret)
key = the token secret = the token secret
Definition: OAuth.php:52
to_postdata()
builds the data one would send in a POST request
Definition: OAuth.php:474
build_signature($signature_method, $consumer, $token)
Definition: OAuth.php:526
$key
Definition: croninfo.php:18
fetch_access_token(&$request)
process an access_token request returns the access token on success
Definition: OAuth.php:599
static split_header($header, $only_allow_oauth_parameters=true)
Definition: OAuth.php:856
to_header($realm=null)
builds the Authorization: header
Definition: OAuth.php:482