From: Zach Copley Date: Thu, 7 Oct 2010 19:01:00 +0000 (-0700) Subject: More OAuthy name for temp credentials fetching test script X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=82a0a1a74b9452fbc122fed9ee9c4e0a86b7a79e;p=quix0rs-gnu-social.git More OAuthy name for temp credentials fetching test script --- diff --git a/tests/oauth/fetch_temp_creds.php b/tests/oauth/fetch_temp_creds.php new file mode 100755 index 0000000000..73f502af30 --- /dev/null +++ b/tests/oauth/fetch_temp_creds.php @@ -0,0 +1,98 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..')); + +require_once INSTALLDIR . '/scripts/commandline.inc'; +require_once INSTALLDIR . '/extlib/OAuth.php'; + +$ini = parse_ini_file("oauth.ini"); + +// Check to make sure we have everything we need from the ini file +foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'request_token_url') as $inikey) { + if (empty($ini[$inikey])) { + print "You forgot to specify a $inikey in your oauth.ini file.\n"; + exit(1); + } +} + +$testConsumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); +$requestTokenUrl = $ini['apiroot'] . $ini['request_token_url']; +$parsed = parse_url($requestTokenUrl); +$params = array(); + +parse_str($parsed['query'], $params); +$params['oauth_callback'] = 'oob'; // out-of-band + +$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); + +try { + $req = OAuthRequest::from_consumer_and_token( + $testConsumer, + null, + "POST", + $requestTokenUrl, + $params + ); + $req->sign_request($hmac_method, $testConsumer, NULL); + $r = httpRequest($req->to_url()); +} catch (Exception $e) { + // oh noez + print $e->getMessage(); + print "OAuth Request:\n"; + var_dump($req); + exit(1); +} + +$body = $r->getBody(); +$tokenStuff = array(); + +parse_str($body, $tokenStuff); + +$tok = $tokenStuff['oauth_token']; +$confirmed = $tokenStuff['oauth_callback_confirmed']; + +if (empty($tokenStuff['oauth_token']) || empty($confirmed) || $confirmed != 'true') { + print "Error: $body\n"; + exit(1); +} + +$authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $tok; + +print "\nSuccess! "; +print "Authorize URL:\n\n$authurl\n\n"; +print "Now paste the Authorize URL into your browser and authorize your temporary credentials.\n"; + +function httpRequest($url) +{ + $request = HTTPClient::start(); + + $request->setConfig( + array( + 'follow_redirects' => true, + 'connect_timeout' => 120, + 'timeout' => 120, + 'ssl_verify_peer' => false, + 'ssl_verify_host' => false + ) + ); + + return $request->post($url); +} diff --git a/tests/oauth/getrequesttoken.php b/tests/oauth/getrequesttoken.php deleted file mode 100755 index 73f502af30..0000000000 --- a/tests/oauth/getrequesttoken.php +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env php -. - */ - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..')); - -require_once INSTALLDIR . '/scripts/commandline.inc'; -require_once INSTALLDIR . '/extlib/OAuth.php'; - -$ini = parse_ini_file("oauth.ini"); - -// Check to make sure we have everything we need from the ini file -foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'request_token_url') as $inikey) { - if (empty($ini[$inikey])) { - print "You forgot to specify a $inikey in your oauth.ini file.\n"; - exit(1); - } -} - -$testConsumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); -$requestTokenUrl = $ini['apiroot'] . $ini['request_token_url']; -$parsed = parse_url($requestTokenUrl); -$params = array(); - -parse_str($parsed['query'], $params); -$params['oauth_callback'] = 'oob'; // out-of-band - -$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); - -try { - $req = OAuthRequest::from_consumer_and_token( - $testConsumer, - null, - "POST", - $requestTokenUrl, - $params - ); - $req->sign_request($hmac_method, $testConsumer, NULL); - $r = httpRequest($req->to_url()); -} catch (Exception $e) { - // oh noez - print $e->getMessage(); - print "OAuth Request:\n"; - var_dump($req); - exit(1); -} - -$body = $r->getBody(); -$tokenStuff = array(); - -parse_str($body, $tokenStuff); - -$tok = $tokenStuff['oauth_token']; -$confirmed = $tokenStuff['oauth_callback_confirmed']; - -if (empty($tokenStuff['oauth_token']) || empty($confirmed) || $confirmed != 'true') { - print "Error: $body\n"; - exit(1); -} - -$authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $tok; - -print "\nSuccess! "; -print "Authorize URL:\n\n$authurl\n\n"; -print "Now paste the Authorize URL into your browser and authorize your temporary credentials.\n"; - -function httpRequest($url) -{ - $request = HTTPClient::start(); - - $request->setConfig( - array( - 'follow_redirects' => true, - 'connect_timeout' => 120, - 'timeout' => 120, - 'ssl_verify_peer' => false, - 'ssl_verify_host' => false - ) - ); - - return $request->post($url); -}