예제 #1
0
 /**
  * Initializes the dropbox connection
  *
  * @param   array   $params  Any connection params needed
  * @return  \League\Flysystem\Dropbox\DropboxAdapter
  **/
 public static function init($params = [])
 {
     // Get the params
     $pparams = Plugin::params('filesystem', 'dropbox');
     if (isset($params['app_token'])) {
         $accessToken = $params['app_token'];
     } else {
         $info = ['key' => isset($params['app_key']) ? $params['app_key'] : $pparams->get('app_key'), 'secret' => isset($params['app_secret']) ? $params['app_secret'] : $pparams->get('app_secret')];
         \Session::set('dropbox.app_key', $info['key']);
         \Session::set('dropbox.app_secret', $info['secret']);
         \Session::set('dropbox.connection_to_set_up', Request::getVar('connection', 0));
         $appInfo = \Dropbox\AppInfo::loadFromJson($info);
         $clientIdentifier = 'hubzero-cms/2.0';
         $redirectUri = trim(Request::root(), '/') . '/developer/callback/dropboxAuthorize';
         $csrfTokenStore = new \Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
         $oauth = new \Dropbox\WebAuth($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore);
         // Redirect to dropbox
         // We hide the return url in the state field...that's not exactly what
         // it was intended for, but it does the trick
         $return = Request::getVar('return') ? Request::getVar('return') : Request::current(true);
         $return = base64_encode($return);
         App::redirect($oauth->start($return));
     }
     $app_secret = isset($params['app_secret']) ? $params['app_secret'] : $pparams->get('app_secret');
     // Create the client
     $client = new \Dropbox\Client($accessToken, $app_secret);
     // Return the adapter
     return new \League\Flysystem\Dropbox\DropboxAdapter($client, isset($params['subdir']) ? $params['subdir'] : null);
 }
예제 #2
0
 /**
  * Processes the dropbox callback from oauth authorize requests
  *
  * @return    void
  **/
 public function dropboxAuthorizeTask()
 {
     $pparams = \Plugin::params('filesystem', 'dropbox');
     $app_key = \Session::get('dropbox.app_key', false);
     $app_secret = \Session::get('dropbox.app_secret', false);
     $new_connection = Session::get('dropbox.connection_to_set_up', false);
     $info = ['key' => isset($app_key) ? $app_key : $pparams->get('app_key'), 'secret' => isset($app_secret) ? $app_secret : $pparams->get('app_secret')];
     $appInfo = \Dropbox\AppInfo::loadFromJson($info);
     $clientIdentifier = 'hubzero-cms/2.0';
     $redirectUri = trim(\Request::root(), '/') . '/developer/callback/dropboxAuthorize';
     $csrfTokenStore = new \Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
     $oauth = new \Dropbox\WebAuth($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore);
     \Session::set('dropbox.app_key', false);
     \Session::set('dropbox.app_secret', false);
     list($accessToken, $userId, $urlState) = $oauth->finish($_GET);
     //if this is a new connection, we can save the token on the server to ensure that it is used next time
     if ($new_connection) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'orm' . DS . 'connection.php';
         $connection = \Components\Projects\Models\Orm\Connection::oneOrFail($new_connection);
         $connection_params = json_decode($connection->get('params'));
         $connection_params->app_token = $accessToken;
         $connection->set('params', json_encode($connection_params));
         $connection->save();
     }
     // Redirect to the local endpoint
     App::redirect(base64_decode($urlState));
 }