static function admin_dropbox_oauth($admin) { if (!Visitor::current()->group->can("change_settings")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings.")); } if (!empty($_GET["uid"]) and !empty($_GET["oauth_token"])) { # The user is redirected here by Dropbox after the authorization screen $data = json_decode(file_get_contents("http://chyrp.net/api/1/dropboxsync.php?keys"), true); $app_key = $data["key"]; $app_secret = $data["secret"]; $storage = new \Dropbox\OAuth\Storage\Session(); $OAuth = new \Dropbox\OAuth\Consumer\Curl($app_key, $app_secret, $storage); # Acquire the access token $token_data = get_object_vars($storage->get("access_token")); $set = array(Config::current()->set("module_dropbox", array("oauth_token_secret" => $token_data['oauth_token_secret'], "oauth_token" => $token_data['oauth_token'], "uid" => $token_data['uid'], "cursor" => null))); if (!in_array(false, $set)) { Flash::notice(__("Dropbox was successfully authorized.", "dropbox"), "/admin/?action=dropbox_settings"); } } elseif (isset($_GET["not_approved"])) { Flash::notice(__("Fine! You'll authorize it some other time.", "dropbox"), "/admin/?action=dropbox_settings"); } }
} while (empty($consumerSecret)) { echo 'Please enter your consumer secret: '; $consumerSecret = trim(fgets(STDIN)); } try { // Set up the OAuth consumer $storage = new \Dropbox\OAuth\Storage\Session(); $OAuth = new \Dropbox\OAuth\Consumer\Curl($consumerKey, $consumerSecret, $storage); // Generate the authorisation URL and prompt user echo "Generating Authorisation URL...\r\n\r\n"; echo "===== Begin Authorisation URL =====\r\n"; echo $OAuth->getAuthoriseUrl() . PHP_EOL; echo "===== End Authorisation URL =====\r\n\r\n"; echo "Visit the URL above and allow the SDK to connect to your account\r\n"; echo "Press any key once you have completed this step..."; fgets(STDIN); // Acquire the access token echo "Acquiring access token...\r\n"; $OAuth->getAccessToken(); $token = serialize(array('token' => $storage->get('access_token'), 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret)); // Write the access token to disk if (@file_put_contents('oauth.token', $token) === false) { throw new \Dropbox\Exception('Unable to write token to file'); } else { exit('Setup complete! You can now run the test suite.'); } } catch (\Dropbox\Exception $e) { echo $e->getMessage() . PHP_EOL; exit('Setup failed! Please try running setup again.'); }