Skip to content

Commit

Permalink
Fix ability to add a Facebook account under https
Browse files Browse the repository at this point in the history
When running under https, the redirect url generated when creating an
authorization url correctly set the protocol to https if the ThinkUp web
server is running under https, but always set the redirect url protocol
to http when creating the url to request an access token.  This caused
Facebook to reject the request for the access token if the app was
configured with the https url.
Closes #1048
  • Loading branch information
cwarden authored and ginatrapani committed Oct 20, 2011
1 parent a15f562 commit 9784edd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Expand Up @@ -152,7 +152,8 @@ protected function processPageActions($options, Facebook $facebook) {
//First, prep redirect URI
$config = Config::getInstance();
$site_root_path = $config->getValue('site_root_path');
$redirect_uri = urlencode('http://'.$_SERVER['SERVER_NAME'].$site_root_path.'account/?p=facebook');
$redirect_uri = urlencode(sprintf('%s://%s%s%s', !empty($_SERVER['HTTPS']) ? 'https' : 'http',
$_SERVER['SERVER_NAME'], $site_root_path, 'account/?p=facebook'));

//Build API request URL
$api_req = 'https://graph.facebook.com/oauth/access_token?client_id='.
Expand Down Expand Up @@ -294,4 +295,4 @@ protected function insertPage($fb_page_id, $viewer_id, $existing_instance_id, $f
$instance_id = $i->id;
}
}
}
}
Expand Up @@ -344,6 +344,46 @@ public function testConnectAccountSuccessful() {
$this->assertEqual($owner_instance->oauth_access_token, 'newfauxaccesstoken11234567890');
}

public function testConnectAccountHTTPSSuccessful() {
$owner_instance_dao = new OwnerInstanceMySQLDAO();
$instance_dao = new InstanceMySQLDAO();
$owner_dao = new OwnerMySQLDAO();

$config = Config::getInstance();
$config->setValue('site_root_path', '/');

$_SERVER['SERVER_NAME'] = "srvr";
$_SERVER['HTTPS'] = 'on';
SessionCache::put('facebook_auth_csrf', '123');
$_GET['p'] = 'facebook';
$_GET['code'] = '789';
$_GET['state'] = '123';

$options_arry = $this->buildPluginOptions();
$this->simulateLogin('me@example.com', true);

$instance = $instance_dao->getByUserIdOnNetwork('606837591', 'facebook');
$this->assertNull($instance); //Instance doesn't exist

$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new FacebookPluginConfigurationController($owner, 'facebook');
$output = $controller->go();

$v_mgr = $controller->getViewManager();

$msgs = $v_mgr->getTemplateDataItem('success_msgs');
$this->assertEqual($msgs['user_add'], "Success! Your Facebook account has been added to ThinkUp.");
$this->debug(Utils::varDumpToString($msgs));

$instance = $instance_dao->getByUserIdOnNetwork('606837591', 'facebook');
$this->assertNotNull($instance); //Instance created

$owner_instance = $owner_instance_dao->get($owner->id, $instance->id);
$this->assertNotNull($owner_instance); //Owner Instance created
//OAuth token set
$this->assertEqual($owner_instance->oauth_access_token, 'newfauxaccesstoken11234567890');
}

public function testConnectAccountInvalidCSRFToken() {
$owner_instance_dao = new OwnerInstanceMySQLDAO();
$instance_dao = new InstanceMySQLDAO();
Expand Down
@@ -0,0 +1 @@
{"error":{"message":"Invalid redirect_uri: Given URL is not allowed by the Application configuration.","type":"OAuthException"}}
@@ -0,0 +1 @@
access_token=newfauxaccesstoken11234567890

0 comments on commit 9784edd

Please sign in to comment.