oauth1.php 2.7 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 Robin Appelman <icewind@owncloud.com>
  7. * @author Robin McCorkell <robin@mccorkell.me.uk>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @copyright Copyright (c) 2016, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. require_once __DIR__ . '/../3rdparty/Dropbox/autoload.php';
  27. OCP\JSON::checkAppEnabled('files_external');
  28. OCP\JSON::checkLoggedIn();
  29. OCP\JSON::callCheck();
  30. $l = \OC::$server->getL10N('files_external');
  31. // FIXME: currently hard-coded to Dropbox OAuth
  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 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 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 app key and secret.'))));
  71. }