]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/oauth/oauth_verify_creds.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / tests / oauth / oauth_verify_creds.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2008, 2009, StatusNet, Inc.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
22
23 require_once INSTALLDIR . '/extlib/OAuth.php';
24
25 $shortoptions = 't:s:';
26 $longoptions = array('oauth_token=', 'oauth_token_secret=');
27
28 $helptext = <<<END_OF_VERIFY_HELP
29   oauth_verify_creds.php [options]
30   Access /api/account/verify_credentials.xml with OAuth
31
32     -t --oauth_token        access token
33     -s --oauth_token_secret access token secret
34
35 END_OF_VERIFY_HELP;
36
37 $token        = null;
38 $token_secret = null;
39
40 require_once INSTALLDIR . '/scripts/commandline.inc';
41
42 if (have_option('t', 'oauth_token')) {
43     $token = get_option_value('t', 'oauth_token');
44 }
45
46 if (have_option('s', 'oauth_token_secret')) {
47     $token_secret = get_option_value('s', 'oauth_token_secret');
48 }
49
50 if (empty($token)) {
51     print "Please specify an access token (--help for help).\n";
52     exit(1);
53 }
54
55 if (empty($token_secret)) {
56     print "Please specify an access token secret (--help for help).\n";
57     exit(1);
58 }
59
60 $ini      = parse_ini_file("oauth.ini");
61 $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
62 $endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
63
64 $atok   = new OAuthToken($token, $token_secret);
65 $parsed = parse_url($endpoint);
66
67 parse_str($parsed['query'], $params);
68
69 try {
70
71     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
72
73     $oauthReq = OAuthRequest::from_consumer_and_token(
74         $consumer,
75         $atok,
76         "GET",
77         $endpoint,
78         $params
79     );
80
81     $oauthReq->sign_request($hmac_method, $consumer, $atok);
82
83     $httpReq = httpRequest($oauthReq->to_url());
84
85 } catch (Exception $e) {
86     print "Error! HTTP response body: " . $httpReq->getBody();
87     exit(1);
88 }
89
90 print $httpReq->getBody();
91
92 function httpRequest($url)
93 {
94     $request = HTTPClient::start();
95
96     $request->setConfig(
97         array(
98             'follow_redirects' => true,
99             'connect_timeout' => 120,
100             'timeout' => 120,
101             'ssl_verify_peer' => false,
102             'ssl_verify_host' => false
103         )
104     );
105
106     return $request->get($url);
107 }