4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
23 require_once INSTALLDIR . '/extlib/OAuth.php';
25 $shortoptions = 'o:s:';
26 $longoptions = array('oauth_token=', 'token_secret=');
28 $helptext = <<<END_OF_VERIFY_HELP
29 verifycreds.php [options]
30 Use an access token to verify credentials thru the api
32 -o --oauth_token access token
33 -s --token_secret access token secret
40 require_once INSTALLDIR . '/scripts/commandline.inc';
42 if (have_option('o', 'oauth_token')) {
43 $token = get_option_value('oauth_token');
46 if (have_option('s', 'token_secret')) {
47 $token_secret = get_option_value('s', 'token_secret');
51 print "Please specify an access token.\n";
55 if (empty($token_secret)) {
56 print "Please specify an access token secret.\n";
60 $ini = parse_ini_file("oauth.ini");
62 $test_consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
64 $endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
68 $at = new OAuthToken($token, $token_secret);
70 $parsed = parse_url($endpoint);
72 parse_str($parsed['query'], $params);
74 $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
76 $req_req = OAuthRequest::from_consumer_and_token($test_consumer, $at, "GET", $endpoint, $params);
77 $req_req->sign_request($hmac_method, $test_consumer, $at);
79 $r = httpRequest($req_req->to_url());
81 $body = $r->getBody();
85 //print $req_req->to_url() . "\n\n";
87 function httpRequest($url)
89 $request = HTTPClient::start();
91 $request->setConfig(array(
92 'follow_redirects' => true,
93 'connect_timeout' => 120,
95 'ssl_verify_peer' => false,
96 'ssl_verify_host' => false
99 return $request->get($url);