1
|
|
|
$(document).ready(function() { |
2
|
|
|
|
3
|
|
|
function displayGranted($tr) { |
4
|
|
|
$tr.find('.configuration input.auth-param').attr('disabled', 'disabled').addClass('disabled-success'); |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { |
8
|
|
|
if (authMechanism === 'oauth2::oauth2') { |
9
|
|
|
var config = $tr.find('.configuration'); |
10
|
|
|
config.append($(document.createElement('input')) |
11
|
|
|
.addClass('button auth-param') |
12
|
|
|
.attr('type', 'button') |
13
|
|
|
.attr('value', t('files_external', 'Grant access')) |
14
|
|
|
.attr('name', 'oauth2_grant') |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
onCompletion.then(function() { |
18
|
|
|
var configured = $tr.find('[data-parameter="configured"]'); |
19
|
|
|
if ($(configured).val() == 'true') { |
20
|
|
|
displayGranted($tr); |
21
|
|
|
} else { |
22
|
|
|
var client_id = $tr.find('.configuration [data-parameter="client_id"]').val(); |
23
|
|
|
var client_secret = $tr.find('.configuration [data-parameter="client_secret"]').val(); |
24
|
|
|
|
25
|
|
|
var params = {}; |
26
|
|
|
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { |
27
|
|
|
params[key] = value; |
28
|
|
|
}); |
29
|
|
|
|
30
|
|
|
if ( |
31
|
|
|
params.code !== undefined |
32
|
|
|
&& typeof client_id === "string" |
33
|
|
|
&& client_id !== '' |
34
|
|
|
&& typeof client_secret === "string" |
35
|
|
|
&& client_secret !== '' |
36
|
|
|
) { |
37
|
|
|
$tr.find('.configuration').trigger('oauth_step2', [{ |
38
|
|
|
backend_id: $tr.attr('class'), |
39
|
|
|
client_id: client_id, |
40
|
|
|
client_secret: client_secret, |
41
|
|
|
redirect: location.protocol + '//' + location.host + location.pathname + '?sectionid=storage', |
42
|
|
|
tr: $tr, |
43
|
|
|
code: params.code || '' |
44
|
|
|
}]); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
$('#externalStorage').on('click', '[name="oauth2_grant"]', function(event) { |
52
|
|
|
event.preventDefault(); |
53
|
|
|
var tr = $(this).parent().parent(); |
54
|
|
|
var client_id = $(this).parent().find('[data-parameter="client_id"]').val(); |
55
|
|
|
var client_secret = $(this).parent().find('[data-parameter="client_secret"]').val(); |
56
|
|
|
|
57
|
|
|
if (client_id !== '' && client_secret !== '') { |
58
|
|
|
var button = $(event.target); |
59
|
|
|
button.prop('disabled', true); |
60
|
|
|
|
61
|
|
|
tr.one('oauth_step1_finished', function(event, data){ |
62
|
|
|
if (!data['success']) { |
|
|
|
|
63
|
|
|
button.prop('disabled', false); |
64
|
|
|
} |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
tr.find('.configuration').trigger('oauth_step1', [{ |
68
|
|
|
backend_id: tr.attr('class'), |
69
|
|
|
client_id: client_id, |
70
|
|
|
client_secret: client_secret, |
71
|
|
|
redirect: location.protocol + '//' + location.host + location.pathname + '?sectionid=storage', |
72
|
|
|
tr: tr |
73
|
|
|
}]); |
74
|
|
|
} |
75
|
|
|
}); |
76
|
|
|
|
77
|
|
|
}); |
78
|
|
|
|
You can rewrite this statement in dot notation: