Skip to content

Commit c4b7f70

Browse files
authored
Merge pull request #132 from leonhartX/apps-scritp-api
disable google login
2 parents 3ae95bf + febe64d commit c4b7f70

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

options/options.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
2222
<b>repo</b> and <b>gist</b>
2323
scope):</p>
2424
<input id="accesstoken" type="password" placeholder="github access token" />
25-
<p class="label"><a target="_blank"
25+
<!-- <p class="label"><a target="_blank"
2626
href="https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/script.projects&access_type=offline">
2727
Grant Google oauth token</a> (paste the result code here)
2828
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
29-
<input id="api-key" type="password" placeholder="google oauth token" />
29+
<input id="api-key" type="password" placeholder="google oauth token" /> -->
3030
</div>
3131
<div class="login-item login-item-otp">
3232
<input id="otp" type="text" placeholder="authentication code">
@@ -45,11 +45,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
4545
<input id="ghe-password" type="password" placeholder="password" />
4646
<p class="label">or accessToken(with <b>repo</b> and <b>gist</b> scope):</p>
4747
<input id="ghe-accesstoken" type="password" placeholder="access token" />
48-
<p class="label"><a target="_blank"
48+
<!-- <p class="label"><a target="_blank"
4949
href="https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/script.projects&access_type=offline">
5050
Grant Google oauth key</a> (paste the result code here)
5151
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
52-
<input id="ghe-api-key" type="password" placeholder="google oauth token" />
52+
<input id="ghe-api-key" type="password" placeholder="google oauth token" /> -->
5353
</div>
5454
<div class="login-item login-item-otp">
5555
<input id="ghe-otp" type="text" placeholder="authentication code">
@@ -67,11 +67,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
6767
<div class="login-item login-item-basic">
6868
<input id="bitbucket-email" type="email" placeholder="email" />
6969
<input id="bitbucket-password" type="password" placeholder="password" />
70-
<p class="label"><a target="_blank"
70+
<!-- <p class="label"><a target="_blank"
7171
href="https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/script.projects&access_type=offline">
7272
Grant Google oauth token</a> (paste the result code here)
7373
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
74-
<input id="bitbucket-api-key" type="password" placeholder="google oauth token" />
74+
<input id="bitbucket-api-key" type="password" placeholder="google oauth token" /> -->
7575
</div>
7676
<button id="bitbucket-login">bitbucket login</button>
7777
<p class="message">Please star this extension on <a href="https://github.com/leonhartX/gas-github">Github</a>
@@ -88,11 +88,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
8888
<input id="gitlab-password" type="password" placeholder="password" />
8989
<p class="label">or personal accessToken(with <b>api</b> scope):</p>
9090
<input id="gitlab-accesstoken" type="password" placeholder="access token" />
91-
<p class="label"><a target="_blank"
91+
<!-- <p class="label"><a target="_blank"
9292
href="https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/script.projects&access_type=offline">
9393
Grant Google oauth token</a> (paste the result code here)
9494
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
95-
<input id="gitlab-api-key" type="password" placeholder="google oauth token" />
95+
<input id="gitlab-api-key" type="password" placeholder="google oauth token" /> -->
9696
</div>
9797
<button id="gitlab-login">gitlab login</button>
9898
<p class="message">Please star this extension on <a href="https://github.com/leonhartX/gas-github">Github</a>

options/options.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ $(() => {
7777
$('#login-user').text(`${user}${domain}`).attr('href', userLink);
7878
$('#token').attr('href', tokenLink);
7979
})
80+
.then(() => {
81+
auth();
82+
})
8083
.catch(err => {
8184
//not logged in
8285
})
@@ -86,7 +89,8 @@ function getGithubParam() {
8689
const scm = 'github';
8790
const username = $('#username').val();
8891
const token = $('#accesstoken').val();
89-
const apiKey = $('#api-key').val();
92+
// const apiKey = $('#api-key').val();
93+
const apiKey = null;
9094
const baseUrl = `https://api.github.com`;
9195
const otp = $('#otp').val();
9296
return {
@@ -104,7 +108,8 @@ function getGHEParam() {
104108
const username = $('#ghe-username').val();
105109
const password = $('#ghe-password').val();
106110
const token = $('#ghe-accesstoken').val();
107-
const apiKey = $('#ghe-api-key').val();
111+
// const apiKey = $('#ghe-api-key').val();
112+
const apiKey = null;
108113
const baseUrl = $('#ghe-url').val() + '/api/v3';
109114
const otp = $('#ghe-otp').val();
110115
return {
@@ -122,7 +127,8 @@ function getBitbucketParam() {
122127
const scm = 'bitbucket';
123128
const username = $('#bitbucket-email').val();
124129
const password = $('#bitbucket-password').val();
125-
const apiKey = $('#bitbucket-api-key').val();
130+
// const apiKey = $('#bitbucket-api-key').val();
131+
const apiKey = null;
126132
const baseUrl = `https://api.bitbucket.org/2.0`;
127133
return {
128134
scm,
@@ -139,7 +145,8 @@ function getGitLabParam() {
139145
const password = $('#gitlab-password').val();
140146
const token = $('#gitlab-accesstoken').val();
141147
const tokenType = (token && token.length > 0) ? 'personalToken' : 'oAuth';
142-
const apiKey = $('#gitlab-api-key').val();
148+
// const apiKey = $('#gitlab-api-key').val();
149+
const apiKey = null;
143150
const baseUrl = ($('#gitlab-url').val() || 'https://gitlab.com') + '/api/v4';
144151
return {
145152
scm,
@@ -164,7 +171,7 @@ function addCred(param) {
164171
const payload = {
165172
code: param.apiKey,
166173
client_id: "971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com",
167-
client_secret: "epw3f_WvEn0Uwqi6kE7DBQl7",
174+
client_secret: __SECRET__,
168175
redirect_uri: "urn:ietf:wg:oauth:2.0:oob",
169176
grant_type: "authorization_code",
170177
access_type: "offline"
@@ -408,7 +415,7 @@ function loginGitLabToken(param) {
408415
}
409416

410417
function logout() {
411-
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'googleApiKey'], () => {
418+
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'gapiToken', 'gapiRefreshToken'], () => {
412419
location.reload();
413420
});
414421
chrome.storage.local.get('tab', (item) => {
@@ -443,4 +450,22 @@ function addStar(token) {
443450
})
444451
.always(resolve);
445452
})
453+
}
454+
455+
function auth() {
456+
return new Promise((resolve, reject) => {
457+
chrome.runtime.sendMessage({
458+
cmd: 'login',
459+
interactive: true
460+
}, token => {
461+
if (token == null) {
462+
reject("can not get oauth token, currently only support Chrome");
463+
} else {
464+
chrome.storage.sync.set({
465+
"gapiToken": token
466+
});
467+
resolve(token);
468+
}
469+
});
470+
});
446471
}

src/gas-hub.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ function load() {
4949
.then(updateBranch)
5050
.then(updateGist)
5151
.then(initPageEvent)
52+
.catch((err) => {
53+
showLog(err, LEVEL_ERROR);
54+
})
5255
break;
5356
case 'not match':
5457
break;
@@ -342,8 +345,15 @@ function auth() {
342345
cmd: 'login',
343346
interactive: true
344347
}, token => {
345-
context.gapiToken = token;
346-
resolve(token);
348+
if (token == null) {
349+
reject("can not get oauth token, currently only support Chrome");
350+
} else {
351+
context.gapiToken = token;
352+
chrome.storage.sync.set({
353+
"gapiToken": token
354+
});
355+
resolve(token);
356+
}
347357
});
348358
});
349359
}

src/gas/script-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ScriptApi {
142142
const payload = {
143143
refresh_token: context.gapiRefreshToken,
144144
client_id: "971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com",
145-
client_secret: "epw3f_WvEn0Uwqi6kE7DBQl7",
145+
client_secret: __SECRET__,
146146
redirect_uri: "urn:ietf:wg:oauth:2.0:oob",
147147
grant_type: "refresh_token",
148148
}

0 commit comments

Comments
 (0)