Skip to content

Commit

Permalink
Improve OAuth2 queries and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
NastuzziSamy committed Mar 12, 2019
1 parent c7229a0 commit ca5386d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 4 additions & 6 deletions js/gdrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'),
Expand All @@ -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
}
Expand Down
16 changes: 10 additions & 6 deletions lib/Controller/OauthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()])
]
Expand All @@ -113,6 +112,7 @@ public function receiveToken(
if (isset($token['error'])) {
return new DataResponse(
[
'status' => 'error',
'data' => $token
],
Http::STATUS_BAD_REQUEST
Expand All @@ -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()])
]
Expand All @@ -141,7 +142,10 @@ public function receiveToken(
}
}
return new DataResponse(
[],
[
'status' => 'error',
'data' => [],
],
Http::STATUS_BAD_REQUEST
);
}
Expand Down

0 comments on commit ca5386d

Please sign in to comment.