Example #1
0
 /**
  *	Hack: wrap the Dropbox library's OAuth object up to:
  *	(1) prevent it from running on its own
  *	(2) spoof OAuth tokens from the plugin's own data store
  *
  *	@return	Dropbox\OAuth\Consumer\ConsumerAbstract
  */
 protected function _getOAuth()
 {
     $callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $encrypter = new \Dropbox\OAuth\Storage\Encrypter(self::encrypter_secret);
     $storage = new \Dropbox\OAuth\Storage\Session($encrypter);
     // spoof storage using token stored with plugin
     if ($this->is_authorized()) {
         $storage->set($this->_plugin->setting(self::token_setting), 'access_token');
     }
     $OAuth = new \Dropbox\OAuth\Consumer\Curl(self::consumer_key, self::consumer_secret, $storage, $callback);
     return $OAuth;
 }
Example #2
0
 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");
     }
 }
Example #3
0
            unlink('oauth.token');
            echo 'Access token deleted. Continuing setup.' . PHP_EOL;
        }
    }
}
while (empty($consumerKey)) {
    echo 'Please enter your consumer key: ';
    $consumerKey = trim(fgets(STDIN));
}
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) {
Example #4
-1
    spl_autoload_register(function ($class) {
        if (substr($class, 0, 7) === 'Dropbox') {
            $class = str_replace('\\', '/', $class);
            require_once __DIR__ . '/' . $class . '.php';
        }
    });
    $app_key = Laravel\Config::get('dropbox::config.app_key');
    $app_secret = Laravel\Config::get('dropbox::config.app_secret');
    $encryption_key = Laravel\Config::get('dropbox::config.encryption_key');
    if (empty($app_key) || empty($app_secret)) {
        throw new \Dropbox\Exception('Please set your Dropbox App key & secret.');
    }
    if (strlen($encryption_key) !== 32) {
        throw new \Dropbox\Exception('Expecting a 32 byte Dropbox encryption key, got ' . strlen($encryption_key));
    }
    // Check whether to use HTTPS and set the callback URL
    $protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
    $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
    $http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '127.0.0.1';
    $callback = $protocol . '://' . $http_host . $request_uri;
    // Instantiate the required Dropbox objects
    $encrypter = new \Dropbox\OAuth\Storage\Encrypter($encryption_key);
    $storage = new \Dropbox\OAuth\Storage\Session($encrypter);
    if ($access_token = Config::get('dropbox::config.access_token')) {
        $storage->set((object) $access_token, 'access_token');
    }
    $OAuth = new \Dropbox\OAuth\Consumer\Curl($app_key, $app_secret, $storage, $callback);
    $dropbox = new \Dropbox\API($OAuth, Laravel\Config::get('dropbox::config.root'));
    IoC::instance('dropbox::session', $storage);
    IoC::instance('dropbox::api', $dropbox);
});