summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMichael Gapczynski <GapczynskiM@gmail.com>2012-06-13 13:54:32 -0400
committerMichael Gapczynski <GapczynskiM@gmail.com>2012-06-13 13:54:50 -0400
commitbd01e9346941fa85b4bb96a42cecdbc50e51c368 (patch)
treec72a41ad073894ddb4f4811e197d9cd7725bc777 /apps
parent613a122437a5fff0eb8c502719f8203ea0a61e81 (diff)
downloadnextcloud-server-bd01e9346941fa85b4bb96a42cecdbc50e51c368.tar.gz
nextcloud-server-bd01e9346941fa85b4bb96a42cecdbc50e51c368.zip
Add support for mounting Google Drive in external storage UI
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/ajax/google.php51
-rw-r--r--apps/files_external/js/google.js48
-rwxr-xr-xapps/files_external/lib/config.php3
-rw-r--r--apps/files_external/lib/google.php2
4 files changed, 102 insertions, 2 deletions
diff --git a/apps/files_external/ajax/google.php b/apps/files_external/ajax/google.php
new file mode 100644
index 00000000000..23ecfc3708d
--- /dev/null
+++ b/apps/files_external/ajax/google.php
@@ -0,0 +1,51 @@
+<?php
+
+require_once 'Google/common.inc.php';
+
+OCP\JSON::checkAppEnabled('files_external');
+OCP\JSON::checkLoggedIn();
+$consumer = new OAuthConsumer('anonymous', 'anonymous');
+$sigMethod = new OAuthSignatureMethod_HMAC_SHA1();
+if (isset($_POST['step'])) {
+ switch ($_POST['step']) {
+ case 1:
+ if (isset($_POST['callback'])) {
+ $callback = $_POST['callback'];
+ } else {
+ $callback = null;
+ }
+ $scope = 'https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/';
+ $url = 'https://www.google.com/accounts/OAuthGetRequestToken?scope='.urlencode($scope);
+ $params = array('scope' => $scope, 'oauth_callback' => $callback);
+ $request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $url, $params);
+ $request->sign_request($sigMethod, $consumer, null);
+ $response = send_signed_request('GET', $url, array($request->to_header()), null, false);
+ $token = array();
+ parse_str($response, $token);
+ if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
+ $authUrl = 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token='.$token['oauth_token'];
+ OCP\JSON::success(array('data' => array('url' => $authUrl, 'request_token' => $token['oauth_token'], 'request_token_secret' => $token['oauth_token_secret'])));
+ } else {
+ OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Error: '.$response)));
+ }
+ break;
+ case 2:
+ if (isset($_POST['oauth_verifier']) && isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
+ $token = new OAuthToken($_POST['request_token'], $_POST['request_token_secret']);
+ $url = 'https://www.google.com/accounts/OAuthGetAccessToken';
+ $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, array('oauth_verifier' => $_POST['oauth_verifier']));
+ $request->sign_request($sigMethod, $consumer, $token);
+ $response = send_signed_request('GET', $url, array($request->to_header()), null, false);
+ $token = array();
+ parse_str($response, $token);
+ if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
+ OCP\JSON::success(array('access_token' => $token['oauth_token'], 'access_token_secret' => $token['oauth_token_secret']));
+ } else {
+ OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Error: '.$response)));
+ }
+ }
+ break;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js
new file mode 100644
index 00000000000..0d65cfda011
--- /dev/null
+++ b/apps/files_external/js/google.js
@@ -0,0 +1,48 @@
+$(document).ready(function() {
+
+ $('#externalStorage tbody tr').each(function() {
+ if ($(this).find('.backend').data('class') == 'OC_Filestorage_Google') {
+ var token = $(this).find('[data-parameter="token"]');
+ var token_secret = $(this).find('[data-parameter="token_secret"]');
+ if ($(token).val() == '' && $(token).val() == '') {
+ $(this).find('.configuration').append('<a class="button google">Grant access</a>');
+ } else {
+ var params = {};
+ window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
+ params[key] = value;
+ });
+ if (params['oauth_token'].length > 1 && decodeURIComponent(params['oauth_token']) == $(token).val() && params['oauth_verifier'].length > 1) {
+ var tr = $(this);
+ $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 2, oauth_verifier: params['oauth_verifier'], request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) {
+ if (result && result.status == 'success') {
+ $(token).val(result.access_token);
+ $(token_secret).val(result.access_token_secret);
+ OC.MountConfig.saveStorage(tr);
+ } else {
+ OC.dialogs.alert(result.data.message, 'Error configuring Google Drive storage');
+ }
+ });
+ }
+ }
+ return false;
+ }
+ });
+
+ $('.google').live('click', function(event) {
+ event.preventDefault();
+ var tr = $(this).parent().parent();
+ var token = $(this).parent().find('[data-parameter="token"]');
+ var token_secret = $(this).parent().find('[data-parameter="token_secret"]');
+ $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 1, callback: window.location.href }, function(result) {
+ if (result && result.status == 'success') {
+ $(token).val(result.data.request_token);
+ $(token_secret).val(result.data.request_token_secret);
+ OC.MountConfig.saveStorage(tr);
+ window.location = result.data.url;
+ } else {
+ OC.dialogs.alert(result.data.message, 'Error configuring Google Drive storage');
+ }
+ });
+ });
+
+});
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index b2ebcd96fcc..870c13b5aed 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -41,8 +41,9 @@ class OC_Mount_Config {
return array(
'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
- 'OC_Filestorage_Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret' ), 'custom' => 'dropbox'),
+ 'OC_Filestorage_Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'),
'OC_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
+ 'OC_Filestorage_Google' => array('backend' => 'Google Drive', 'configuration' => array('token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root')),
'OC_Filestorage_DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index d2285a6d82c..c2a4af0ff8a 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -20,7 +20,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-require_once 'common.inc.php';
+require_once 'Google/common.inc.php';
class OC_Filestorage_Google extends OC_Filestorage_Common {