dropbox.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Volkan Gezer <volkangezer@gmail.com>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. require_once __DIR__ . '/../3rdparty/Dropbox/autoload.php';
  28. OCP\JSON::checkAppEnabled('files_external');
  29. OCP\JSON::checkLoggedIn();
  30. OCP\JSON::callCheck();
  31. $l = \OC::$server->getL10N('files_external');
  32. if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
  33. $oauth = new Dropbox_OAuth_Curl((string)$_POST['app_key'], (string)$_POST['app_secret']);
  34. if (isset($_POST['step'])) {
  35. switch ($_POST['step']) {
  36. case 1:
  37. try {
  38. if (isset($_POST['callback'])) {
  39. $callback = (string)$_POST['callback'];
  40. } else {
  41. $callback = null;
  42. }
  43. $token = $oauth->getRequestToken();
  44. OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback),
  45. 'request_token' => $token['token'],
  46. 'request_token_secret' => $token['token_secret'])));
  47. } catch (Exception $exception) {
  48. OCP\JSON::error(array('data' => array('message' =>
  49. $l->t('Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.'))
  50. ));
  51. }
  52. break;
  53. case 2:
  54. if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
  55. try {
  56. $oauth->setToken((string)$_POST['request_token'], (string)$_POST['request_token_secret']);
  57. $token = $oauth->getAccessToken();
  58. OCP\JSON::success(array('access_token' => $token['token'],
  59. 'access_token_secret' => $token['token_secret']));
  60. } catch (Exception $exception) {
  61. OCP\JSON::error(array('data' => array('message' =>
  62. $l->t('Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.'))
  63. ));
  64. }
  65. }
  66. break;
  67. }
  68. }
  69. } else {
  70. OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid Dropbox app key and secret.'))));
  71. }