diff --git a/js/gdrive.js b/js/gdrive.js index 1ab7346..1dab7fd 100644 --- a/js/gdrive.js +++ b/js/gdrive.js @@ -21,8 +21,8 @@ $(document).ready(function () { if ($(configured).val() == 'true') { displayGranted($tr); } else { - var client_id = $tr.find('.configuration [data-parameter="client_id"]').val(); - var client_secret = $tr.find('.configuration [data-parameter="client_secret"]').val(); + var client_id = $tr.find('.configuration [data-parameter="client_id"]').val().trim(); + var client_secret = $tr.find('.configuration [data-parameter="client_secret"]').val().trim(); var params = {}; window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) { @@ -54,8 +54,8 @@ $(document).ready(function () { $('#externalStorage').on('click', '[name="oauth2_grant_gdrive"]', function (event) { event.preventDefault(); var tr = $(this).parent().parent(); - var client_id = $(this).parent().find('[data-parameter="client_id"]').val(); - var client_secret = $(this).parent().find('[data-parameter="client_secret"]').val(); + var client_id = $(this).parent().find('[data-parameter="client_id"]').val().trim(); + var client_secret = $(this).parent().find('[data-parameter="client_secret"]').val().trim(); if (client_id !== '' && client_secret !== '') { $('.configuration').trigger('oauth_step1', [{ backend_id: tr.attr('class'), @@ -68,8 +68,6 @@ $(document).ready(function () { }); $('.configuration').on('oauth_step1', function (event, data) { - console.log('b', data); - if (data['backend_id'] !== backendId) { return false; // means the trigger is not for this storage adapter } diff --git a/lib/Controller/OauthController.php b/lib/Controller/OauthController.php index 458edf8..2d858a3 100644 --- a/lib/Controller/OauthController.php +++ b/lib/Controller/OauthController.php @@ -73,12 +73,10 @@ public function receiveToken( $step, $code ) { - $clientId = $client_id; - $clientSecret = $client_secret; - if ($clientId !== null && $clientSecret !== null && $redirect !== null) { + if ($client_id !== null && $client_secret !== null && $redirect !== null) { $client = new \Google_Client(); - $client->setClientId($clientId); - $client->setClientSecret($clientSecret); + $client->setClientId($client_id); + $client->setClientSecret($client_secret); $client->setRedirectUri($redirect); $client->setScopes([ \Google_Service_Drive::DRIVE, @@ -99,6 +97,7 @@ public function receiveToken( } catch (Exception $exception) { return new DataResponse( [ + 'status' => 'error', 'data' => [ 'message' => $l->t('Step 1 failed. Exception: %s', [$exception->getMessage()]) ] @@ -113,6 +112,7 @@ public function receiveToken( if (isset($token['error'])) { return new DataResponse( [ + 'status' => 'error', 'data' => $token ], Http::STATUS_BAD_REQUEST @@ -130,6 +130,7 @@ public function receiveToken( } catch (Exception $exception) { return new DataResponse( [ + 'status' => 'error', 'data' => [ 'message' => $l->t('Step 2 failed. Exception: %s', [$exception->getMessage()]) ] @@ -141,7 +142,10 @@ public function receiveToken( } } return new DataResponse( - [], + [ + 'status' => 'error', + 'data' => [], + ], Http::STATUS_BAD_REQUEST ); }