public function authorize($code) { $this->init(); try { $csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, Dropbox::SESSION_TOKEN); $webAuth = new dbx\WebAuth($this->appInfo, Dropbox::CLIENT, $this->getRedirect(), $csrfTokenStore); list($accessToken, $userId, $urlState) = $webAuth->finish($code); $this->setAuthorizeToken($accessToken); return true; } catch (Dropbox\Exception $ex) { return false; } }
public function dropboxSuccess() { session_start(); $appInfo = dbx\AppInfo::loadFromJsonFile(__DIR__ . "\\app-info.json"); $csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token'); $webAuth = new dbx\WebAuth($appInfo, "PHP-Example/1.0", 'http://localhost:8080/CloudSync/public/FacebookModel.php', $csrfTokenStore); list($accessToken, $dropboxUserId) = $webAuth->finish($_GET); $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0"); $accountInfo = $dbxClient->getAccountInfo(); // Saving Access Token and usernifno to dropbox table $dropboxObject = new Dropbox(); $dropboxObject->userId = Auth::id(); $dropboxObject->username = $accountInfo["display_name"]; $dropboxObject->accessToken = $accessToken; $dropboxObject->uId = $accountInfo["uid"]; $dropboxObject->save(); $folderMetadata = $dbxClient->getMetadataWithChildren("/"); return view('pages.dropbox')->with('dropboxData', $folderMetadata); }
/** * (non-PHPdoc) * @see Symfony\Component\Console\Command\Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $appAuthJsonFile = $GLOBALS['_conf']['dropbox_auth_json']; $clientIdentifier = $GLOBALS['_conf']['p2name']; $callbackUrl = null; $key = $input->getOption('key'); $secret = $input->getOption('secret'); if ($input->getOption('full-access')) { $accessType = Dropbox\AccessType::FullDropbox(); $accessTypeName = 'FullDropbox'; } else { $accessType = Dropbox\AccessType::AppFolder(); $accessTypeName = 'AppFolder'; } $appInfo = new Dropbox\AppInfo($key, $secret, $accessType); $dbxConfig = new Dropbox\Config($appInfo, $clientIdentifier); $webAuth = new Dropbox\WebAuth($dbxConfig); list($requestToken, $authorizeUrl) = $webAuth->start($callbackUrl); $output->writeln("<comment>1. Go to the following URL:</comment>"); $output->writeln("<info>{$authorizeUrl}</info>"); $output->writeln("<comment>2. Click \"Allow\" (you might have to log in first).</comment>"); $output->writeln("<comment>3. Hit ENTER to continue.</comment>"); fgets(STDIN); list($accessToken, $dropboxUserId) = $webAuth->finish($requestToken); $serializedAccessToken = $accessToken->serialize(); $output->writeln("<comment>Authorization complete.</comment>"); $output->writeln("<comment>- User ID: {$dropboxUserId}</comment>"); $output->writeln("<comment>- Serialized Access Token: {$serializedAccessToken}</comment>"); $jsonOptions = 0; if (defined('JSON_PRETTY_PRINT')) { $jsonOptions |= \JSON_PRETTY_PRINT; } $json = json_encode(array('app' => array('key' => $key, 'secret' => $secret, 'access_type' => $accessTypeName), 'access_token' => $serializedAccessToken), $jsonOptions) . PHP_EOL; if (file_put_contents($appAuthJsonFile, $json) !== false) { $output->writeln("<info>Saved authorization information to \"{$appAuthJsonFile}\".</info>"); } else { $output->writeln("<error>Error saving to \"{$appAuthJsonFile}\".</error>"); $output->writeln("<info>Dumping to stderr instead:</info>"); $output->write($json, OutputInterface::OUTPUT_RAW); } }