forked from GNUsocial/gnu-social
Some fixups to this the OAuth verify credentials test script
This commit is contained in:
parent
46de847ce0
commit
474834a332
@ -22,15 +22,15 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
|
|||||||
|
|
||||||
require_once INSTALLDIR . '/extlib/OAuth.php';
|
require_once INSTALLDIR . '/extlib/OAuth.php';
|
||||||
|
|
||||||
$shortoptions = 'o:s:';
|
$shortoptions = 't:s:';
|
||||||
$longoptions = array('oauth_token=', 'token_secret=');
|
$longoptions = array('oauth_token=', 'oauth_token_secret=');
|
||||||
|
|
||||||
$helptext = <<<END_OF_VERIFY_HELP
|
$helptext = <<<END_OF_VERIFY_HELP
|
||||||
verifycreds.php [options]
|
oauth_verify_creds.php [options]
|
||||||
Use an access token to verify credentials thru the api
|
Access /api/account/verify_credentials.xml with OAuth
|
||||||
|
|
||||||
-o --oauth_token access token
|
-t --oauth_token access token
|
||||||
-s --token_secret access token secret
|
-s --oauth_token_secret access token secret
|
||||||
|
|
||||||
END_OF_VERIFY_HELP;
|
END_OF_VERIFY_HELP;
|
||||||
|
|
||||||
@ -39,63 +39,69 @@ $token_secret = null;
|
|||||||
|
|
||||||
require_once INSTALLDIR . '/scripts/commandline.inc';
|
require_once INSTALLDIR . '/scripts/commandline.inc';
|
||||||
|
|
||||||
if (have_option('o', 'oauth_token')) {
|
if (have_option('t', 'oauth_token')) {
|
||||||
$token = get_option_value('oauth_token');
|
$token = get_option_value('t', 'oauth_token');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (have_option('s', 'token_secret')) {
|
if (have_option('s', 'token_secret')) {
|
||||||
$token_secret = get_option_value('s', 'token_secret');
|
$token_secret = get_option_value('s', 'oauth_token_secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
print "Please specify an access token.\n";
|
print "Please specify an access token (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token_secret)) {
|
if (empty($token_secret)) {
|
||||||
print "Please specify an access token secret.\n";
|
print "Please specify an access token secret (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ini = parse_ini_file("oauth.ini");
|
$ini = parse_ini_file("oauth.ini");
|
||||||
|
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
||||||
$test_consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
|
||||||
|
|
||||||
$endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
|
$endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
|
||||||
|
|
||||||
print "$endpoint\n";
|
$atok = new OAuthToken($token, $token_secret);
|
||||||
|
|
||||||
$at = new OAuthToken($token, $token_secret);
|
|
||||||
|
|
||||||
$parsed = parse_url($endpoint);
|
$parsed = parse_url($endpoint);
|
||||||
$params = array();
|
|
||||||
parse_str($parsed['query'], $params);
|
parse_str($parsed['query'], $params);
|
||||||
|
|
||||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
try {
|
||||||
|
|
||||||
$req_req = OAuthRequest::from_consumer_and_token($test_consumer, $at, "GET", $endpoint, $params);
|
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||||
$req_req->sign_request($hmac_method, $test_consumer, $at);
|
|
||||||
|
|
||||||
$r = httpRequest($req_req->to_url());
|
$oauthReq = OAuthRequest::from_consumer_and_token(
|
||||||
|
$consumer,
|
||||||
|
$atok,
|
||||||
|
"GET",
|
||||||
|
$endpoint,
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
|
||||||
$body = $r->getBody();
|
$oauthReq->sign_request($hmac_method, $consumer, $atok);
|
||||||
|
|
||||||
print "$body\n";
|
$httpReq = httpRequest($oauthReq->to_url());
|
||||||
|
|
||||||
//print $req_req->to_url() . "\n\n";
|
} catch (Exception $e) {
|
||||||
|
print "Error! HTTP response body: " . $httpReq->getBody();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
print $httpReq->getBody();
|
||||||
|
|
||||||
function httpRequest($url)
|
function httpRequest($url)
|
||||||
{
|
{
|
||||||
$request = HTTPClient::start();
|
$request = HTTPClient::start();
|
||||||
|
|
||||||
$request->setConfig(array(
|
$request->setConfig(
|
||||||
'follow_redirects' => true,
|
array(
|
||||||
'connect_timeout' => 120,
|
'follow_redirects' => true,
|
||||||
'timeout' => 120,
|
'connect_timeout' => 120,
|
||||||
'ssl_verify_peer' => false,
|
'timeout' => 120,
|
||||||
'ssl_verify_host' => false
|
'ssl_verify_peer' => false,
|
||||||
));
|
'ssl_verify_host' => false
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return $request->get($url);
|
return $request->get($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user