- Update getrequesttoken test script to use 1.0a

- Some cleanup
This commit is contained in:
Zach Copley 2010-10-05 17:38:03 -07:00
parent 63663dbd0e
commit 73a73c9362
1 changed files with 23 additions and 16 deletions

View File

@ -2,7 +2,7 @@
<?php <?php
/* /*
* StatusNet - a distributed open-source microblogging tool * StatusNet - a distributed open-source microblogging tool
* Copyright (C) 2008-2010, StatusNet, Inc. * Copyright (C) 2010, StatusNet, Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by
@ -33,38 +33,45 @@ foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'request_token_url')
} }
} }
$test_consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $testConsumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$rt_endpoint = $ini['apiroot'] . $ini['request_token_url']; $requestTokenUrl = $ini['apiroot'] . $ini['request_token_url'];
$parsed = parse_url($rt_endpoint); $parsed = parse_url($requestTokenUrl);
$params = array(); $params = array();
parse_str($parsed['query'], $params); parse_str($parsed['query'], $params);
$params['oauth_callback'] = 'oob';
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
try { try {
$req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $rt_endpoint, $params); $req = OAuthRequest::from_consumer_and_token(
$req_req->sign_request($hmac_method, $test_consumer, NULL); $testConsumer,
$r = httpRequest($req_req->to_url()); null,
"GET",
$requestTokenUrl,
$params
);
$req->sign_request($hmac_method, $testConsumer, NULL);
$r = httpRequest($req->to_url());
} catch (Exception $e) { } catch (Exception $e) {
// oh noez // oh noez
print $e->getMessage(); print $e->getMessage();
var_dump($req_req); var_dump($req);
exit(1); exit(1);
} }
$body = $r->getBody(); $body = $r->getBody();
$token_stuff = array(); $tokenStuff = array();
parse_str($body, $token_stuff); parse_str($body, $tokenStuff);
if (empty($token_stuff['oauth_token'])) { if (empty($tokenStuff['oauth_token'])) {
print "Error: $body\n"; print "Error: $body\n";
exit(1); exit(1);
} }
$authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $token_stuff['oauth_token']; $authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $tokenStuff['oauth_token'];
print "\nSuccess!\n\n"; print "\nSuccess!\n\n";
print 'Request token : ' . $token_stuff['oauth_token'] . "\n"; print 'Request token : ' . $tokenStuff['oauth_token'] . "\n";
print 'Request token secret : ' . $token_stuff['oauth_token_secret'] . "\n"; print 'Request token secret : ' . $tokenStuff['oauth_token_secret'] . "\n";
print "Authorize URL : $authurl\n"; print "Authorize URL : $authurl\n";
print "\nNow paste the Authorize URL into your browser and authorize the request token.\n"; print "\nNow paste the Authorize URL into your browser and authorize the request token.\n";
@ -72,7 +79,7 @@ print "\nNow paste the Authorize URL into your browser and authorize the request
function httpRequest($url) function httpRequest($url)
{ {
$request = HTTPClient::start(); $request = HTTPClient::start();
$request->setConfig( $request->setConfig(
array( array(
'follow_redirects' => true, 'follow_redirects' => true,
@ -82,7 +89,7 @@ function httpRequest($url)
'ssl_verify_host' => false 'ssl_verify_host' => false
) )
); );
return $request->get($url); return $request->get($url);
} }