r107661 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107660‎ | r107661 | r107662 >
Date:21:59, 30 December 2011
Author:reedy
Status:ok
Tags:
Comment:
Do r107654 again properly

Nicer readable diff from lack of whitespace changes!
Modified paths:
  • /trunk/extensions/TweetANew/lib/tmhOAuth.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TweetANew/lib/tmhOAuth.php
@@ -7,12 +7,12 @@
88 * REST requests. OAuth authentication is sent using the an Authorization Header.
99 *
1010 * @author themattharris
11 - * @version 0.57
 11+ * @version 0.60
1212 *
13 - * 11 December 2011
 13+ * 29 December 2011
1414 */
1515 class tmhOAuth {
16 - const VERSION = 0.57;
 16+ const VERSION = 0.60;
1717
1818 /**
1919 * Creates a new tmhOAuth object
@@ -28,27 +28,40 @@
2929 // default configuration options
3030 $this->config = array_merge(
3131 array(
32 - 'user_agent' => 'tmhOAuth ' . self::VERSION . ' - //github.com/themattharris/tmhOAuth',
 32+ // leave 'user_agent' blank for default, otherwise set this to
 33+ // something that clearly identifies your app
 34+ 'user_agent' => '',
 35+
 36+ 'use_ssl' => true,
 37+ 'host' => 'api.twitter.com',
 38+
3339 'consumer_key' => '',
3440 'consumer_secret' => '',
3541 'user_token' => '',
3642 'user_secret' => '',
37 - 'use_ssl' => true,
38 - 'host' => 'api.twitter.com',
39 - 'debug' => false,
4043 'force_nonce' => false,
4144 'nonce' => false, // used for checking signatures. leave as false for auto
4245 'force_timestamp' => false,
4346 'timestamp' => false, // used for checking signatures. leave as false for auto
 47+
 48+ // oauth signing variables that are not dynamic
4449 'oauth_version' => '1.0',
 50+ 'oauth_signature_method' => 'HMAC-SHA1',
4551
4652 // you probably don't want to change any of these curl values
4753 'curl_connecttimeout' => 30,
4854 'curl_timeout' => 10,
49 - // for security you may want to set this to TRUE. If you do you need
50 - // to install the servers certificate in your local certificate store.
51 - 'curl_ssl_verifypeer' => false,
 55+
 56+ // for security these should always be set to true.
 57+ 'curl_ssl_verifyhost' => true,
 58+ 'curl_ssl_verifypeer' => true,
 59+
 60+ // you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem
 61+ 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem',
 62+ 'curl_capath' => dirname(__FILE__),
 63+
5264 'curl_followlocation' => false, // whether to follow redirects or not
 65+
5366 // support for proxy servers
5467 'curl_proxy' => false, // really you don't want to use this if you are using streaming
5568 'curl_proxyuserpwd' => false, // format username:password for proxy, if required
@@ -59,15 +72,30 @@
6073 'streaming_eol' => "\r\n",
6174 'streaming_metrics_interval' => 60,
6275
63 - // header or querystring. You should always use header
64 - // this is just to help me debug other developers
65 - // implementations
 76+ // header or querystring. You should always use header!
 77+ // this is just to help me debug other developers implementations
6678 'as_header' => true,
 79+ 'debug' => false,
6780 ),
6881 $config
6982 );
 83+ $this->set_user_agent();
7084 }
7185
 86+ function set_user_agent() {
 87+ if (!empty($this->config['user_agent']))
 88+ return;
 89+
 90+ if ($this->config['curl_ssl_verifyhost'] && $this->config['curl_ssl_verifypeer']) {
 91+ $ssl = '+SSL';
 92+ } else {
 93+ $ssl = '-SSL';
 94+ }
 95+
 96+ $ua = 'tmhOAuth ' . self::VERSION . $ssl . ' - //github.com/themattharris/tmhOAuth';
 97+ $this->config['user_agent'] = $ua;
 98+ }
 99+
72100 /**
73101 * Generates a random OAuth nonce.
74102 * If 'force_nonce' is true a nonce is not generated and the value in the configuration will be retained.
@@ -83,7 +111,7 @@
84112 shuffle($sequence);
85113
86114 $prefix = $include_time ? microtime() : '';
87 - $this->config['nonce'] = md5(substr($prefix . implode($sequence), 0, $length));
 115+ $this->config['nonce'] = md5(substr($prefix . implode('', $sequence), 0, $length));
88116 }
89117 }
90118
@@ -146,7 +174,7 @@
147175 'oauth_nonce' => $this->config['nonce'],
148176 'oauth_timestamp' => $this->config['timestamp'],
149177 'oauth_consumer_key' => $this->config['consumer_key'],
150 - 'oauth_signature_method' => 'HMAC-SHA1',
 178+ 'oauth_signature_method' => $this->config['oauth_signature_method'],
151179 );
152180
153181 // include the user token if it exists
@@ -261,6 +289,11 @@
262290 unset($_signing_params['oauth_callback']);
263291 }
264292
 293+ if (isset($_signing_params['oauth_verifier'])) {
 294+ $this->auth_params['oauth_verifier'] = $_signing_params['oauth_verifier'];
 295+ unset($_signing_params['oauth_verifier']);
 296+ }
 297+
265298 // request_params is already set if we're doing multipart, if not we need to set them now
266299 if ( ! $this->config['multipart'])
267300 $this->request_params = array_diff_key($_signing_params, $this->get_defaults());
@@ -535,18 +568,26 @@
536569 CURLOPT_USERAGENT => $this->config['user_agent'],
537570 CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
538571 CURLOPT_TIMEOUT => $this->config['curl_timeout'],
539 - CURLOPT_RETURNTRANSFER => TRUE,
 572+ CURLOPT_RETURNTRANSFER => true,
540573 CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
 574+ CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],
 575+
541576 CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
542577 CURLOPT_PROXY => $this->config['curl_proxy'],
543578 CURLOPT_ENCODING => $this->config['curl_encoding'],
544579 CURLOPT_URL => $this->url,
545580 // process the headers
546581 CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'),
547 - CURLOPT_HEADER => FALSE,
 582+ CURLOPT_HEADER => false,
548583 CURLINFO_HEADER_OUT => true,
549584 ));
550585
 586+ if ($this->config['curl_cainfo'] !== false)
 587+ curl_setopt($c, CURLOPT_CAINFO, $this->config['curl_cainfo']);
 588+
 589+ if ($this->config['curl_capath'] !== false)
 590+ curl_setopt($c, CURLOPT_CAPATH, $this->config['curl_capath']);
 591+
551592 if ($this->config['curl_proxyuserpwd'] !== false)
552593 curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']);
553594
@@ -561,7 +602,7 @@
562603 case 'GET':
563604 break;
564605 case 'POST':
565 - curl_setopt($c, CURLOPT_POST, TRUE);
 606+ curl_setopt($c, CURLOPT_POST, true);
566607 break;
567608 default:
568609 curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method);
@@ -599,12 +640,16 @@
600641 $response = curl_exec($c);
601642 $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
602643 $info = curl_getinfo($c);
 644+ $error = curl_error($c);
 645+ $errno = curl_errno($c);
603646 curl_close($c);
604647
605648 // store the response
606649 $this->response['code'] = $code;
607650 $this->response['response'] = $response;
608651 $this->response['info'] = $info;
 652+ $this->response['error'] = $error;
 653+ $this->response['errno'] = $errno;
609654 return $code;
610655 }
611656 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107654Bump to 0.60 from https://raw.github.com/themattharris/tmhOAuth/master/tmhOAu...reedy21:05, 30 December 2011

Status & tagging log