ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
OAuth.php
Go to the documentation of this file.
1<?php
11if (!class_exists('OAuthException')) {
12 /*
13 * Generic exception class
14 */
15 class OAuthException extends Exception {
16 // pass
17 }
18}
19
20if (!class_exists('OAuthConsumer')) {
21 class OAuthConsumer {
22 public $key;
23 public $secret;
24
25 function __construct($key, $secret, $callback_url=NULL) {
26 $this->key = $key;
27 $this->secret = $secret;
28 $this->callback_url = $callback_url;
29 }
30
31 function __toString() {
32 return "OAuthConsumer[key=$this->key,secret=$this->secret]";
33 }
34 }
35}
36
38 // access tokens and request tokens
39 public $key;
40 public $secret;
41
47 $this->key = $key;
48 $this->secret = $secret;
49 }
50
55 function to_string() {
56 return "oauth_token=" .
58 "&oauth_token_secret=" .
59 OAuthUtil::urlencode_rfc3986($this->secret) .
60 "&oauth_callback_confirmed=true";
61 }
62
63 function __toString() {
64 return $this->to_string();
65 }
66}
67
72abstract class OAuthSignatureMethod {
77 abstract public function get_name();
78
89 abstract public function build_signature($request, $consumer, $token);
90
99 public function check_signature($request, $consumer, $token, $signature) {
100 $built = $this->build_signature($request, $consumer, $token);
101
102 // Check for zero length, although unlikely here
103 if (strlen($built) == 0 || strlen($signature) == 0) {
104 return false;
105 }
106
107 if (strlen($built) != strlen($signature)) {
108 return false;
109 }
110
111 // Avoid a timing leak with a (hopefully) time insensitive compare
112 $result = 0;
113 for ($i = 0; $i < strlen($signature); $i++) {
114 $result |= ord($built{$i}) ^ ord($signature{$i});
115 }
116
117 return $result == 0;
118 }
119}
120
129 function get_name() {
130 return "HMAC-SHA1";
131 }
132
133 public function build_signature($request, $consumer, $token) {
134 $base_string = $request->get_signature_base_string();
135 $request->base_string = $base_string;
136
137 $key_parts = array(
138 $consumer->secret,
139 ($token) ? $token->secret : ""
140 );
141
142 $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
143 $key = implode('&', $key_parts);
144
145 return base64_encode(hash_hmac('sha1', $base_string, $key, true));
146 }
147}
148
155 public function get_name() {
156 return "PLAINTEXT";
157 }
158
168 public function build_signature($request, $consumer, $token) {
169 $key_parts = array(
170 $consumer->secret,
171 ($token) ? $token->secret : ""
172 );
173
174 $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
175 $key = implode('&', $key_parts);
176 $request->base_string = $key;
177
178 return $key;
179 }
180}
181
191 public function get_name() {
192 return "RSA-SHA1";
193 }
194
195 // Up to the SP to implement this lookup of keys. Possible ideas are:
196 // (1) do a lookup in a table of trusted certs keyed off of consumer
197 // (2) fetch via http using a url provided by the requester
198 // (3) some sort of specific discovery code based on request
199 //
200 // Either way should return a string representation of the certificate
201 protected abstract function fetch_public_cert(&$request);
202
203 // Up to the SP to implement this lookup of keys. Possible ideas are:
204 // (1) do a lookup in a table of trusted certs keyed off of consumer
205 //
206 // Either way should return a string representation of the certificate
207 protected abstract function fetch_private_cert(&$request);
208
209 public function build_signature($request, $consumer, $token) {
210 $base_string = $request->get_signature_base_string();
211 $request->base_string = $base_string;
212
213 // Fetch the private key cert based on the request
214 $cert = $this->fetch_private_cert($request);
215
216 // Pull the private key ID from the certificate
217 $privatekeyid = openssl_get_privatekey($cert);
218
219 // Sign using the key
220 $ok = openssl_sign($base_string, $signature, $privatekeyid);
221
222 // Release the key resource
223 openssl_free_key($privatekeyid);
224
225 return base64_encode($signature);
226 }
227
228 public function check_signature($request, $consumer, $token, $signature) {
229 $decoded_sig = base64_decode($signature);
230
231 $base_string = $request->get_signature_base_string();
232
233 // Fetch the public key cert based on the request
234 $cert = $this->fetch_public_cert($request);
235
236 // Pull the public key ID from the certificate
237 $publickeyid = openssl_get_publickey($cert);
238
239 // Check the computed signature against the one passed in the query
240 $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
241
242 // Release the key resource
243 openssl_free_key($publickeyid);
244
245 return $ok == 1;
246 }
247}
248
250 protected $parameters;
251 protected $http_method;
252 protected $http_url;
253 // for debug purposes
255 public static $version = '1.0';
256 public static $POST_INPUT = 'php://input';
257
259 $parameters = ($parameters) ? $parameters : array();
260 $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
261 $this->parameters = $parameters;
262 $this->http_method = $http_method;
263 $this->http_url = $http_url;
264 }
265
266
270 public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
271 $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
272 ? 'http'
273 : 'https';
274 $http_url = ($http_url) ? $http_url : $scheme .
275 '://' . $_SERVER['SERVER_NAME'] .
276 ':' .
277 $_SERVER['SERVER_PORT'] .
278 $_SERVER['REQUEST_URI'];
279 $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
280
281 // We weren't handed any parameters, so let's find the ones relevant to
282 // this request.
283 // If you run XML-RPC or similar you should use this to provide your own
284 // parsed parameter-list
285 if (!$parameters) {
286 // Find request headers
287 $request_headers = OAuthUtil::get_headers();
288
289 // Parse the query-string to find GET parameters
291
292 // It's a POST request of the proper content-type, so parse POST
293 // parameters and add those overriding any duplicates from GET
294 if ($http_method == "POST"
295 && isset($request_headers['Content-Type'])
296 && strstr($request_headers['Content-Type'],
297 'application/x-www-form-urlencoded')
298 ) {
299 $post_data = OAuthUtil::parse_parameters(
300 file_get_contents(self::$POST_INPUT)
301 );
302 $parameters = array_merge($parameters, $post_data);
303 }
304
305 // We have a Authorization-header with OAuth data. Parse the header
306 // and add those overriding any duplicates from GET or POST
307 if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
308 $header_parameters = OAuthUtil::split_header(
309 $request_headers['Authorization']
310 );
311 $parameters = array_merge($parameters, $header_parameters);
312 }
313
314 }
315
317 }
318
322 public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
323 $parameters = ($parameters) ? $parameters : array();
324 $defaults = array("oauth_version" => OAuthRequest::$version,
325 "oauth_nonce" => OAuthRequest::generate_nonce(),
326 "oauth_timestamp" => OAuthRequest::generate_timestamp(),
327 "oauth_consumer_key" => $consumer->key);
328 if ($token)
329 $defaults['oauth_token'] = $token->key;
330
331 $parameters = array_merge($defaults, $parameters);
332
334 }
335
336 public function set_parameter($name, $value, $allow_duplicates = true) {
337 if ($allow_duplicates && isset($this->parameters[$name])) {
338 // We have already added parameter(s) with this name, so add to the list
339 if (is_scalar($this->parameters[$name])) {
340 // This is the first duplicate, so transform scalar (string)
341 // into an array so we can add the duplicates
342 $this->parameters[$name] = array($this->parameters[$name]);
343 }
344
345 $this->parameters[$name][] = $value;
346 } else {
347 $this->parameters[$name] = $value;
348 }
349 }
350
351 public function get_parameter($name) {
352 return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
353 }
354
355 public function get_parameters() {
356 return $this->parameters;
357 }
358
359 public function unset_parameter($name) {
360 unset($this->parameters[$name]);
361 }
362
367 public function get_signable_parameters() {
368 // Grab all parameters
370
371 // Remove oauth_signature if present
372 // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
373 if (isset($params['oauth_signature'])) {
374 unset($params['oauth_signature']);
375 }
376
378 }
379
387 public function get_signature_base_string() {
388 $parts = array(
392 );
393
394 $parts = OAuthUtil::urlencode_rfc3986($parts);
395
396 return implode('&', $parts);
397 }
398
402 public function get_normalized_http_method() {
403 return strtoupper($this->http_method);
404 }
405
410 public function get_normalized_http_url() {
411 $parts = parse_url($this->http_url);
412
413 $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
414 $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
415 $host = (isset($parts['host'])) ? strtolower($parts['host']) : '';
416 $path = (isset($parts['path'])) ? $parts['path'] : '';
417
418 if (($scheme == 'https' && $port != '443')
419 || ($scheme == 'http' && $port != '80')) {
420 $host = "$host:$port";
421 }
422 return "$scheme://$host$path";
423 }
424
428 public function to_url() {
429 $post_data = $this->to_postdata();
430 $out = $this->get_normalized_http_url();
431 if ($post_data) {
432 $out .= '?'.$post_data;
433 }
434 return $out;
435 }
436
440 public function to_postdata() {
441 return OAuthUtil::build_http_query($this->parameters);
442 }
443
447 public function to_header($realm=null) {
448 $first = true;
449 if($realm) {
450 $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
451 $first = false;
452 } else
453 $out = 'Authorization: OAuth';
454
455 $total = array();
456 foreach ($this->parameters as $k => $v) {
457 if (substr($k, 0, 5) != "oauth") continue;
458 if (is_array($v)) {
459 throw new OAuthException('Arrays not supported in headers');
460 }
461 $out .= ($first) ? ' ' : ',';
463 '="' .
465 '"';
466 $first = false;
467 }
468 return $out;
469 }
470
471 public function __toString() {
472 return $this->to_url();
473 }
474
475
476 public function sign_request($signature_method, $consumer, $token) {
477 $this->set_parameter(
478 "oauth_signature_method",
479 $signature_method->get_name(),
480 false
481 );
482 $signature = $this->build_signature($signature_method, $consumer, $token);
483 $this->set_parameter("oauth_signature", $signature, false);
484 }
485
486 public function build_signature($signature_method, $consumer, $token) {
487 $signature = $signature_method->build_signature($this, $consumer, $token);
488 return $signature;
489 }
490
494 private static function generate_timestamp() {
495 return time();
496 }
497
501 private static function generate_nonce() {
502 $mt = microtime();
503 $rand = mt_rand();
504
505 return md5($mt . $rand); // md5s look nicer than numbers
506 }
507}
508
510 protected $timestamp_threshold = 300; // in seconds, five minutes
511 protected $version = '1.0'; // hi blaine
512 protected $signature_methods = array();
513
514 protected $data_store;
515
517 $this->data_store = $data_store;
518 }
519
520 public function add_signature_method($signature_method) {
521 $this->signature_methods[$signature_method->get_name()] =
522 $signature_method;
523 }
524
525 // high level functions
526
531 public function fetch_request_token(&$request) {
532 $this->get_version($request);
533
534 $consumer = $this->get_consumer($request);
535
536 // no token required for the initial token request
537 $token = NULL;
538
539 $this->check_signature($request, $consumer, $token);
540
541 // Rev A change
542 $callback = $request->get_parameter('oauth_callback');
543 $new_token = $this->data_store->new_request_token($consumer, $callback);
544
545 return $new_token;
546 }
547
552 public function fetch_access_token(&$request) {
553 $this->get_version($request);
554
555 $consumer = $this->get_consumer($request);
556
557 // requires authorized request token
558 $token = $this->get_token($request, $consumer, "request");
559
560 $this->check_signature($request, $consumer, $token);
561
562 // Rev A change
563 $verifier = $request->get_parameter('oauth_verifier');
564 $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
565
566 return $new_token;
567 }
568
572 public function verify_request(&$request) {
573 $this->get_version($request);
574 $consumer = $this->get_consumer($request);
575 $token = $this->get_token($request, $consumer, "access");
576 $this->check_signature($request, $consumer, $token);
577 return array($consumer, $token);
578 }
579
580 // Internals from here
584 private function get_version(&$request) {
585 $version = $request->get_parameter("oauth_version");
586 if (!$version) {
587 // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
588 // Chapter 7.0 ("Accessing Protected Ressources")
589 $version = '1.0';
590 }
591 if ($version !== $this->version) {
592 throw new OAuthException("OAuth version '$version' not supported");
593 }
594 return $version;
595 }
596
600 private function get_signature_method($request) {
601 $signature_method = $request instanceof OAuthRequest
602 ? $request->get_parameter("oauth_signature_method")
603 : NULL;
604
605 if (!$signature_method) {
606 // According to chapter 7 ("Accessing Protected Ressources") the signature-method
607 // parameter is required, and we can't just fallback to PLAINTEXT
608 throw new OAuthException('No signature method parameter. This parameter is required');
609 }
610
611 if (!in_array($signature_method,
612 array_keys($this->signature_methods))) {
613 throw new OAuthException(
614 "Signature method '$signature_method' not supported " .
615 "try one of the following: " .
616 implode(", ", array_keys($this->signature_methods))
617 );
618 }
619 return $this->signature_methods[$signature_method];
620 }
621
625 private function get_consumer($request) {
626 $consumer_key = $request instanceof OAuthRequest
627 ? $request->get_parameter("oauth_consumer_key")
628 : NULL;
629
630 if (!$consumer_key) {
631 throw new OAuthException("Invalid consumer key");
632 }
633
634 $consumer = $this->data_store->lookup_consumer($consumer_key);
635 if (!$consumer) {
636 throw new OAuthException("Invalid consumer");
637 }
638
639 return $consumer;
640 }
641
645 private function get_token($request, $consumer, $token_type="access") {
646 $token_field = $request instanceof OAuthRequest
647 ? $request->get_parameter('oauth_token')
648 : NULL;
649
650 if (!empty($token_field)) {
651 $token = $this->data_store->lookup_token(
652 $consumer, $token_type, $token_field
653 );
654 if (!$token) {
655 throw new OAuthException("Invalid $token_type token: $token_field");
656 }
657 }
658 else {
659 $token = new OAuthToken('', '');
660 }
661 return $token;
662 }
663
668 private function check_signature($request, $consumer, $token) {
669 // this should probably be in a different method
670 $timestamp = $request instanceof OAuthRequest
671 ? $request->get_parameter('oauth_timestamp')
672 : NULL;
673 $nonce = $request instanceof OAuthRequest
674 ? $request->get_parameter('oauth_nonce')
675 : NULL;
676
678 $this->check_nonce($consumer, $token, $nonce, $timestamp);
679
680 $signature_method = $this->get_signature_method($request);
681
682 $signature = $request->get_parameter('oauth_signature');
683 $valid_sig = $signature_method->check_signature(
684 $request,
685 $consumer,
686 $token,
687 $signature
688 );
689
690 if (!$valid_sig) {
691 throw new OAuthException("Invalid signature");
692 }
693 }
694
698 private function check_timestamp($timestamp) {
699 if( ! $timestamp )
700 throw new OAuthException(
701 'Missing timestamp parameter. The parameter is required'
702 );
703
704 // verify that timestamp is recentish
705 $now = time();
706 if (abs($now - $timestamp) > $this->timestamp_threshold) {
707 throw new OAuthException(
708 "Expired timestamp, yours $timestamp, ours $now"
709 );
710 }
711 }
712
716 private function check_nonce($consumer, $token, $nonce, $timestamp) {
717 if( ! $nonce )
718 throw new OAuthException(
719 'Missing nonce parameter. The parameter is required'
720 );
721
722 // verify that the nonce is uniqueish
723 $found = $this->data_store->lookup_nonce(
724 $consumer,
725 $token,
726 $nonce,
728 );
729 if ($found) {
730 throw new OAuthException("Nonce already used: $nonce");
731 }
732 }
733
734}
735
737 function lookup_consumer($consumer_key) {
738 // implement me
739 }
740
741 function lookup_token($consumer, $token_type, $token) {
742 // implement me
743 }
744
745 function lookup_nonce($consumer, $token, $nonce, $timestamp) {
746 // implement me
747 }
748
749 function new_request_token($consumer, $callback = null) {
750 // return a new token attached to this consumer
751 }
752
753 function new_access_token($token, $consumer, $verifier = null) {
754 // return a new access token attached to this consumer
755 // for the user associated with this token if the request token
756 // is authorized
757 // should also invalidate the request token
758 }
759
760}
761
763 public static function urlencode_rfc3986($input) {
764 if (is_array($input)) {
765 return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
766 } else if (is_scalar($input)) {
767 return str_replace(
768 '+',
769 ' ',
770 str_replace('%7E', '~', rawurlencode($input))
771 );
772 } else {
773 return '';
774 }
775 }
776
777
778 // This decode function isn't taking into consideration the above
779 // modifications to the encoding process. However, this method doesn't
780 // seem to be used anywhere so leaving it as is.
781 public static function urldecode_rfc3986($string) {
782 return urldecode($string);
783 }
784
785 // Utility function for turning the Authorization: header into
786 // parameters, has to do some unescaping
787 // Can filter out any non-oauth parameters if needed (default behaviour)
788 // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
789 // see http://code.google.com/p/oauth/issues/detail?id=163
790 public static function split_header($header, $only_allow_oauth_parameters = true) {
791 $params = array();
792 if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
793 foreach ($matches[1] as $i => $h) {
794 $params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
795 }
796 if (isset($params['realm'])) {
797 unset($params['realm']);
798 }
799 }
800 return $params;
801 }
802
803 // helper to try to sort out headers for people who aren't running apache
804 public static function get_headers() {
805 if (function_exists('apache_request_headers')) {
806 // we need this to get the actual Authorization: header
807 // because apache tends to tell us it doesn't exist
808 $headers = apache_request_headers();
809
810 // sanitize the output of apache_request_headers because
811 // we always want the keys to be Cased-Like-This and arh()
812 // returns the headers in the same case as they are in the
813 // request
814 $out = array();
815 foreach ($headers AS $key => $value) {
816 $key = str_replace(
817 " ",
818 "-",
819 ucwords(strtolower(str_replace("-", " ", $key)))
820 );
821 $out[$key] = $value;
822 }
823 } else {
824 // otherwise we don't have apache and are just going to have to hope
825 // that $_SERVER actually contains what we need
826 $out = array();
827 if( isset($_SERVER['CONTENT_TYPE']) )
828 $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
829 if( isset($_ENV['CONTENT_TYPE']) )
830 $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
831
832 foreach ($_SERVER as $key => $value) {
833 if (substr($key, 0, 5) == "HTTP_") {
834 // this is chaos, basically it is just there to capitalize the first
835 // letter of every word that is not an initial HTTP and strip HTTP
836 // code from przemek
837 $key = str_replace(
838 " ",
839 "-",
840 ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
841 );
842 $out[$key] = $value;
843 }
844 }
845 // The "Authorization" header may get turned into "Auth".
846 if (isset($out['Auth'])) {
847 $out['Authorization'] = $out['Auth'];
848 }
849 }
850 return $out;
851 }
852
853 // This function takes a input like a=b&a=c&d=e and returns the parsed
854 // parameters like this
855 // array('a' => array('b','c'), 'd' => 'e')
856 public static function parse_parameters( $input ) {
857 if (!isset($input) || !$input) return array();
858
859 $pairs = explode('&', $input);
860
861 $parsed_parameters = array();
862 foreach ($pairs as $pair) {
863 $split = explode('=', $pair, 2);
864 $parameter = OAuthUtil::urldecode_rfc3986($split[0]);
865 $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
866
867 if (isset($parsed_parameters[$parameter])) {
868 // We have already recieved parameter(s) with this name, so add to the list
869 // of parameters with this name
870
871 if (is_scalar($parsed_parameters[$parameter])) {
872 // This is the first duplicate, so transform scalar (string) into an array
873 // so we can add the duplicates
874 $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
875 }
876
877 $parsed_parameters[$parameter][] = $value;
878 } else {
879 $parsed_parameters[$parameter] = $value;
880 }
881 }
882 return $parsed_parameters;
883 }
884
885 public static function build_http_query($params) {
886 if (!$params) return '';
887
888 // Urlencode both keys and values
890 $values = OAuthUtil::urlencode_rfc3986(array_values($params));
891 $params = array_combine($keys, $values);
892
893 // Parameters are sorted by name, using lexicographical byte value ordering.
894 // Ref: Spec: 9.1.1 (1)
895 uksort($params, 'strcmp');
896
897 $pairs = array();
898 foreach ($params as $parameter => $value) {
899 if (is_array($value)) {
900 // If two or more parameters share the same name, they are sorted by their value
901 // Ref: Spec: 9.1.1 (1)
902 // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
903 sort($value, SORT_STRING);
904 foreach ($value as $duplicate_value) {
905 $pairs[] = $parameter . '=' . $duplicate_value;
906 }
907 } else {
908 $pairs[] = $parameter . '=' . $value;
909 }
910 }
911 // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
912 // Each name-value pair is separated by an '&' character (ASCII code 38)
913 return implode('&', $pairs);
914 }
915}
$result
$total
Definition: Utf8Test.php:87
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
An exception for terminatinating execution or to throw for unit testing.
lookup_consumer($consumer_key)
Definition: OAuth.php:737
lookup_token($consumer, $token_type, $token)
Definition: OAuth.php:741
new_request_token($consumer, $callback=null)
Definition: OAuth.php:749
lookup_nonce($consumer, $token, $nonce, $timestamp)
Definition: OAuth.php:745
new_access_token($token, $consumer, $verifier=null)
Definition: OAuth.php:753
__construct($http_method, $http_url, $parameters=NULL)
Definition: OAuth.php:258
static $POST_INPUT
Definition: OAuth.php:256
sign_request($signature_method, $consumer, $token)
Definition: OAuth.php:476
static $version
Definition: OAuth.php:255
__toString()
Definition: OAuth.php:471
get_normalized_http_method()
just uppercases the http method
Definition: OAuth.php:402
to_postdata()
builds the data one would send in a POST request
Definition: OAuth.php:440
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
Definition: OAuth.php:410
to_url()
builds a url usable for a GET request
Definition: OAuth.php:428
unset_parameter($name)
Definition: OAuth.php:359
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
Definition: OAuth.php:367
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:270
get_signature_base_string()
Returns the base string of this request.
Definition: OAuth.php:387
set_parameter($name, $value, $allow_duplicates=true)
Definition: OAuth.php:336
get_parameters()
Definition: OAuth.php:355
to_header($realm=null)
builds the Authorization: header
Definition: OAuth.php:447
get_parameter($name)
Definition: OAuth.php:351
static generate_timestamp()
util function: current timestamp
Definition: OAuth.php:494
build_signature($signature_method, $consumer, $token)
Definition: OAuth.php:486
static generate_nonce()
util function: current nonce
Definition: OAuth.php:501
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:322
$signature_methods
Definition: OAuth.php:512
add_signature_method($signature_method)
Definition: OAuth.php:520
get_token($request, $consumer, $token_type="access")
try to find the token for the provided request's token key
Definition: OAuth.php:645
__construct($data_store)
Definition: OAuth.php:516
check_nonce($consumer, $token, $nonce, $timestamp)
check that the nonce is not repeated
Definition: OAuth.php:716
check_timestamp($timestamp)
check that the timestamp is new enough
Definition: OAuth.php:698
fetch_access_token(&$request)
process an access_token request returns the access token on success
Definition: OAuth.php:552
$timestamp_threshold
Definition: OAuth.php:510
get_signature_method($request)
figure out the signature with some defaults
Definition: OAuth.php:600
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:668
fetch_request_token(&$request)
process a request_token request returns the request token on success
Definition: OAuth.php:531
verify_request(&$request)
verify an api call, checks all the parameters
Definition: OAuth.php:572
get_version(&$request)
version 1
Definition: OAuth.php:584
get_consumer($request)
try to find the consumer for the provided request's consumer key
Definition: OAuth.php:625
The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] where t...
Definition: OAuth.php:128
get_name()
Needs to return the name of the Signature Method (ie HMAC-SHA1)
Definition: OAuth.php:129
build_signature($request, $consumer, $token)
Build up the signature NOTE: The output of this function MUST NOT be urlencoded.
Definition: OAuth.php:133
The PLAINTEXT method does not provide any security protection and SHOULD only be used over a secure c...
Definition: OAuth.php:154
build_signature($request, $consumer, $token)
oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret,...
Definition: OAuth.php:168
get_name()
Needs to return the name of the Signature Method (ie HMAC-SHA1)
Definition: OAuth.php:155
The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in [RFC3447] ...
Definition: OAuth.php:190
check_signature($request, $consumer, $token, $signature)
Verifies that a given signature is correct.
Definition: OAuth.php:228
build_signature($request, $consumer, $token)
Build up the signature NOTE: The output of this function MUST NOT be urlencoded.
Definition: OAuth.php:209
get_name()
Needs to return the name of the Signature Method (ie HMAC-SHA1)
Definition: OAuth.php:191
A class for implementing a Signature Method See section 9 ("Signing Requests") in the spec.
Definition: OAuth.php:72
get_name()
Needs to return the name of the Signature Method (ie HMAC-SHA1)
check_signature($request, $consumer, $token, $signature)
Verifies that a given signature is correct.
Definition: OAuth.php:99
build_signature($request, $consumer, $token)
Build up the signature NOTE: The output of this function MUST NOT be urlencoded.
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:37
to_string()
generates the basic string serialization of a token that a server would respond to request_token and ...
Definition: OAuth.php:55
__toString()
Definition: OAuth.php:63
__construct($key, $secret)
key = the token secret = the token secret
Definition: OAuth.php:46
static get_headers()
Definition: OAuth.php:804
static split_header($header, $only_allow_oauth_parameters=true)
Definition: OAuth.php:790
static urldecode_rfc3986($string)
Definition: OAuth.php:781
static parse_parameters( $input)
Definition: OAuth.php:856
static urlencode_rfc3986($input)
Definition: OAuth.php:763
static build_http_query($params)
Definition: OAuth.php:885
$key
Definition: croninfo.php:18
$secret
Definition: demo.php:27
$consumer
Definition: demo.php:30
$i
Definition: disco.tpl.php:19
$h
if($format !==null) $name
Definition: metadata.php:146
$keys
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$params
Definition: disable.php:11