2012-06-12 15:36:25 +00:00
|
|
|
<?php
|
2015-03-26 10:44:34 +00:00
|
|
|
/**
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Michael Gapczynski <GapczynskiM@gmail.com>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
2016-01-12 14:02:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 10:44:34 +00:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2013-11-05 09:33:21 +00:00
|
|
|
require_once __DIR__ . '/../3rdparty/Dropbox/autoload.php';
|
2012-06-12 15:36:25 +00:00
|
|
|
|
|
|
|
OCP\JSON::checkAppEnabled('files_external');
|
|
|
|
OCP\JSON::checkLoggedIn();
|
2013-02-12 10:35:16 +00:00
|
|
|
OCP\JSON::callCheck();
|
2014-08-31 08:05:59 +00:00
|
|
|
$l = \OC::$server->getL10N('files_external');
|
2013-02-12 10:35:16 +00:00
|
|
|
|
2015-08-12 21:03:41 +00:00
|
|
|
// FIXME: currently hard-coded to Dropbox OAuth
|
2012-06-12 15:36:25 +00:00
|
|
|
if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
|
2015-02-13 12:33:20 +00:00
|
|
|
$oauth = new Dropbox_OAuth_Curl((string)$_POST['app_key'], (string)$_POST['app_secret']);
|
2012-06-12 15:36:25 +00:00
|
|
|
if (isset($_POST['step'])) {
|
|
|
|
switch ($_POST['step']) {
|
|
|
|
case 1:
|
|
|
|
try {
|
|
|
|
if (isset($_POST['callback'])) {
|
2015-02-13 12:33:20 +00:00
|
|
|
$callback = (string)$_POST['callback'];
|
2012-06-12 15:36:25 +00:00
|
|
|
} else {
|
|
|
|
$callback = null;
|
|
|
|
}
|
|
|
|
$token = $oauth->getRequestToken();
|
2012-11-30 15:27:11 +00:00
|
|
|
OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback),
|
|
|
|
'request_token' => $token['token'],
|
|
|
|
'request_token_secret' => $token['token_secret'])));
|
2012-06-12 15:36:25 +00:00
|
|
|
} catch (Exception $exception) {
|
2012-11-30 15:27:11 +00:00
|
|
|
OCP\JSON::error(array('data' => array('message' =>
|
2015-08-12 21:03:41 +00:00
|
|
|
$l->t('Fetching request tokens failed. Verify that your app key and secret are correct.'))
|
2012-11-30 15:27:11 +00:00
|
|
|
));
|
2012-06-12 15:36:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
|
|
|
|
try {
|
2015-02-13 12:33:20 +00:00
|
|
|
$oauth->setToken((string)$_POST['request_token'], (string)$_POST['request_token_secret']);
|
2012-06-12 15:36:25 +00:00
|
|
|
$token = $oauth->getAccessToken();
|
2012-11-30 15:27:11 +00:00
|
|
|
OCP\JSON::success(array('access_token' => $token['token'],
|
|
|
|
'access_token_secret' => $token['token_secret']));
|
2012-06-12 15:36:25 +00:00
|
|
|
} catch (Exception $exception) {
|
2012-11-30 15:27:11 +00:00
|
|
|
OCP\JSON::error(array('data' => array('message' =>
|
2015-08-12 21:03:41 +00:00
|
|
|
$l->t('Fetching access tokens failed. Verify that your app key and secret are correct.'))
|
2012-11-30 15:27:11 +00:00
|
|
|
));
|
2012-06-12 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-08-12 21:03:41 +00:00
|
|
|
OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid app key and secret.'))));
|
2012-06-12 15:36:25 +00:00
|
|
|
}
|