Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Twitter plugin: Make OAuth callback URL work on localhost
* Explicitly specify OAuth callback URL when rendering Add Twitter User link
* Automatically convert localhost to IP address
Closes #1340
  • Loading branch information
CVi authored and ginatrapani committed Jul 5, 2012
1 parent 49a815f commit 87a8fc7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Expand Up @@ -106,7 +106,7 @@ public function authControl() {
if ($plugin->isConfigured()) {
$to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
/* Request tokens from twitter */
$tok = $to->getRequestToken();
$tok = $to->getRequestToken(Utils::getApplicationURL(true)."plugins/twitter/auth.php");

if (isset($tok['oauth_token'])
|| (isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { //testing
Expand Down
Expand Up @@ -262,6 +262,28 @@ public function testForDeleteCSRFToken() {
$output = $controller->go();
$this->assertPattern('/name="csrf_token" value="'. self::CSRF_TOKEN . '"/', $output);
}

public function testLocalhostOAuthCallbackLink() {
require THINKUP_WEBAPP_PATH.'config.inc.php';
$_SERVER['SERVER_NAME'] = 'localhost';
$options_array = $this->buildPluginOptions();

$controller = new TwitterPluginConfigurationController(null, 'twitter');
$config = Config::getInstance();

//From logged in
$this->simulateLogin('me@example.com');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new TwitterPluginConfigurationController($owner, 'twitter');
$output = $controller->go();
$v_mgr = $controller->getViewManager();

//Check if a URL was passed
$auth_link = $v_mgr->getTemplateDataItem('oauthorize_link');
$this->assertEqual("test_auth_URL_".urlencode("http://127.0.0.1".$THINKUP_CFG['site_root_path'].
"plugins/twitter/auth.php"), $auth_link);
}

/**
* build plugin option values
Expand Down
12 changes: 8 additions & 4 deletions webapp/plugins/twitter/tests/classes/mock.TwitterOAuth.php
Expand Up @@ -19,9 +19,9 @@
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
*
* Mock Twitter OAuth class for tests
*
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2012 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
Expand Down Expand Up @@ -96,8 +96,12 @@ public function lastStatusCode() {
return $this->last_status_code;
}

public function getRequestToken() {
return array('oauth_token'=>'dummytoken', 'oauth_token_secret'=>'dummytoken');
public function getRequestToken($oauth_callback = NULL) {
if (!empty($oauth_callback)) {
return array('oauth_token'=>urlencode($oauth_callback), 'oauth_token_secret'=>'dummytoken');
} else {
return array('oauth_token'=>'dummytoken', 'oauth_token_secret'=>'dummytoken');
}
}

public function getAuthorizeURL($token) {
Expand Down

0 comments on commit 87a8fc7

Please sign in to comment.