diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-11 13:36:58 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-11 13:36:58 +0100 |
commit | c1d8a03662dcbf0f82e4ee6feb8cceadf399ae93 (patch) | |
tree | fafdd0a955bb9fcf971c1f82b83932ac6a6fda56 /apps/files_external | |
parent | 16097037afb5c072ee690c4b78aa13fa7e2257fe (diff) | |
parent | 430c5df6c468fcd7dcb2e8a87805f7b1ec74312b (diff) | |
download | nextcloud-server-c1d8a03662dcbf0f82e4ee6feb8cceadf399ae93.tar.gz nextcloud-server-c1d8a03662dcbf0f82e4ee6feb8cceadf399ae93.zip |
Merge pull request #21517 from owncloud/ext-oauth-fix
Fix OAuth external storage auth for step 2
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/js/oauth1.js | 66 | ||||
-rw-r--r-- | apps/files_external/js/oauth2.js | 94 |
2 files changed, 82 insertions, 78 deletions
diff --git a/apps/files_external/js/oauth1.js b/apps/files_external/js/oauth1.js index 47aca36871f..e2ba25ebf8e 100644 --- a/apps/files_external/js/oauth1.js +++ b/apps/files_external/js/oauth1.js @@ -1,6 +1,6 @@ $(document).ready(function() { - OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme) { + OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { if (authMechanism === 'oauth1::oauth1') { var config = $tr.find('.configuration'); config.append($(document.createElement('input')) @@ -10,39 +10,41 @@ $(document).ready(function() { .attr('name', 'oauth1_grant') ); - var configured = $tr.find('[data-parameter="configured"]'); - if ($(configured).val() == 'true') { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>'); - } else { - var app_key = $tr.find('.configuration [data-parameter="app_key"]').val(); - var app_secret = $tr.find('.configuration [data-parameter="app_secret"]').val(); - if (app_key != '' && app_secret != '') { - var pos = window.location.search.indexOf('oauth_token') + 12; - var token = $tr.find('.configuration [data-parameter="token"]'); - if (pos != -1 && window.location.search.substr(pos, $(token).val().length) == $(token).val()) { - var token_secret = $tr.find('.configuration [data-parameter="token_secret"]'); - var statusSpan = $tr.find('.status span'); - statusSpan.removeClass(); - statusSpan.addClass('waiting'); - $.post(OC.filePath('files_external', 'ajax', 'oauth1.php'), { step: 2, app_key: app_key, app_secret: app_secret, 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); - $(configured).val('true'); - OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) { - if (status) { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>'); - } - }); - } else { - OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring OAuth1')); - } - }); + onCompletion.then(function() { + var configured = $tr.find('[data-parameter="configured"]'); + if ($(configured).val() == 'true') { + $tr.find('.configuration input').attr('disabled', 'disabled'); + $tr.find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>'); + } else { + var app_key = $tr.find('.configuration [data-parameter="app_key"]').val(); + var app_secret = $tr.find('.configuration [data-parameter="app_secret"]').val(); + if (app_key != '' && app_secret != '') { + var pos = window.location.search.indexOf('oauth_token') + 12; + var token = $tr.find('.configuration [data-parameter="token"]'); + if (pos != -1 && window.location.search.substr(pos, $(token).val().length) == $(token).val()) { + var token_secret = $tr.find('.configuration [data-parameter="token_secret"]'); + var statusSpan = $tr.find('.status span'); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); + $.post(OC.filePath('files_external', 'ajax', 'oauth1.php'), { step: 2, app_key: app_key, app_secret: app_secret, 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); + $(configured).val('true'); + OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) { + if (status) { + $tr.find('.configuration input').attr('disabled', 'disabled'); + $tr.find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>'); + } + }); + } else { + OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring OAuth1')); + } + }); + } } } - } + }); } }); diff --git a/apps/files_external/js/oauth2.js b/apps/files_external/js/oauth2.js index 84941437420..2556bf45cae 100644 --- a/apps/files_external/js/oauth2.js +++ b/apps/files_external/js/oauth2.js @@ -1,6 +1,6 @@ $(document).ready(function() { - OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme) { + OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { if (authMechanism === 'oauth2::oauth2') { var config = $tr.find('.configuration'); config.append($(document.createElement('input')) @@ -10,54 +10,56 @@ $(document).ready(function() { .attr('name', 'oauth2_grant') ); - var configured = $tr.find('[data-parameter="configured"]'); - if ($(configured).val() == 'true') { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append($('<span/>').attr('id', 'access') - .text(t('files_external', 'Access granted'))); - } else { - var client_id = $tr.find('.configuration [data-parameter="client_id"]').val(); - var client_secret = $tr.find('.configuration [data-parameter="client_secret"]') - .val(); - if (client_id != '' && client_secret != '') { - var params = {}; - window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { - params[key] = value; - }); - if (params['code'] !== undefined) { - var token = $tr.find('.configuration [data-parameter="token"]'); - var statusSpan = $tr.find('.status span'); - statusSpan.removeClass(); - statusSpan.addClass('waiting'); - $.post(OC.filePath('files_external', 'ajax', 'oauth2.php'), - { - step: 2, - client_id: client_id, - client_secret: client_secret, - redirect: location.protocol + '//' + location.host + location.pathname, - code: params['code'], - }, function(result) { - if (result && result.status == 'success') { - $(token).val(result.data.token); - $(configured).val('true'); - OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) { - if (status) { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append($('<span/>') - .attr('id', 'access') - .text(t('files_external', 'Access granted'))); - } - }); - } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring OAuth2') - ); + onCompletion.then(function() { + var configured = $tr.find('[data-parameter="configured"]'); + if ($(configured).val() == 'true') { + $tr.find('.configuration input').attr('disabled', 'disabled'); + $tr.find('.configuration').append($('<span/>').attr('id', 'access') + .text(t('files_external', 'Access granted'))); + } else { + var client_id = $tr.find('.configuration [data-parameter="client_id"]').val(); + var client_secret = $tr.find('.configuration [data-parameter="client_secret"]') + .val(); + if (client_id != '' && client_secret != '') { + var params = {}; + window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { + params[key] = value; + }); + if (params['code'] !== undefined) { + var token = $tr.find('.configuration [data-parameter="token"]'); + var statusSpan = $tr.find('.status span'); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); + $.post(OC.filePath('files_external', 'ajax', 'oauth2.php'), + { + step: 2, + client_id: client_id, + client_secret: client_secret, + redirect: location.protocol + '//' + location.host + location.pathname, + code: params['code'], + }, function(result) { + if (result && result.status == 'success') { + $(token).val(result.data.token); + $(configured).val('true'); + OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) { + if (status) { + $tr.find('.configuration input').attr('disabled', 'disabled'); + $tr.find('.configuration').append($('<span/>') + .attr('id', 'access') + .text(t('files_external', 'Access granted'))); + } + }); + } else { + OC.dialogs.alert(result.data.message, + t('files_external', 'Error configuring OAuth2') + ); + } } - } - ); + ); + } } } - } + }); } }); |