Skip to content

Commit

Permalink
Merge pull request #132 from leonhartX/apps-scritp-api
Browse files Browse the repository at this point in the history
disable google login
  • Loading branch information
leonhartX authored Jan 3, 2021
2 parents 3ae95bf + febe64d commit c4b7f70
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
16 changes: 8 additions & 8 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
<b>repo</b> and <b>gist</b>
scope):</p>
<input id="accesstoken" type="password" placeholder="github access token" />
<p class="label"><a target="_blank"
<!-- <p class="label"><a target="_blank"
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">
Grant Google oauth token</a> (paste the result code here)
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
<input id="api-key" type="password" placeholder="google oauth token" />
<input id="api-key" type="password" placeholder="google oauth token" /> -->
</div>
<div class="login-item login-item-otp">
<input id="otp" type="text" placeholder="authentication code">
Expand All @@ -45,11 +45,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
<input id="ghe-password" type="password" placeholder="password" />
<p class="label">or accessToken(with <b>repo</b> and <b>gist</b> scope):</p>
<input id="ghe-accesstoken" type="password" placeholder="access token" />
<p class="label"><a target="_blank"
<!-- <p class="label"><a target="_blank"
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">
Grant Google oauth key</a> (paste the result code here)
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
<input id="ghe-api-key" type="password" placeholder="google oauth token" />
<input id="ghe-api-key" type="password" placeholder="google oauth token" /> -->
</div>
<div class="login-item login-item-otp">
<input id="ghe-otp" type="text" placeholder="authentication code">
Expand All @@ -67,11 +67,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
<div class="login-item login-item-basic">
<input id="bitbucket-email" type="email" placeholder="email" />
<input id="bitbucket-password" type="password" placeholder="password" />
<p class="label"><a target="_blank"
<!-- <p class="label"><a target="_blank"
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">
Grant Google oauth token</a> (paste the result code here)
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
<input id="bitbucket-api-key" type="password" placeholder="google oauth token" />
<input id="bitbucket-api-key" type="password" placeholder="google oauth token" /> -->
</div>
<button id="bitbucket-login">bitbucket login</button>
<p class="message">Please star this extension on <a href="https://github.com/leonhartX/gas-github">Github</a>
Expand All @@ -88,11 +88,11 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
<input id="gitlab-password" type="password" placeholder="password" />
<p class="label">or personal accessToken(with <b>api</b> scope):</p>
<input id="gitlab-accesstoken" type="password" placeholder="access token" />
<p class="label"><a target="_blank"
<!-- <p class="label"><a target="_blank"
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">
Grant Google oauth token</a> (paste the result code here)
<br>*or leave it empty to use Chrome login user(for <b>Chrome</b> only)</p>
<input id="gitlab-api-key" type="password" placeholder="google oauth token" />
<input id="gitlab-api-key" type="password" placeholder="google oauth token" /> -->
</div>
<button id="gitlab-login">gitlab login</button>
<p class="message">Please star this extension on <a href="https://github.com/leonhartX/gas-github">Github</a>
Expand Down
37 changes: 31 additions & 6 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ $(() => {
$('#login-user').text(`${user}${domain}`).attr('href', userLink);
$('#token').attr('href', tokenLink);
})
.then(() => {
auth();
})
.catch(err => {
//not logged in
})
Expand All @@ -86,7 +89,8 @@ function getGithubParam() {
const scm = 'github';
const username = $('#username').val();
const token = $('#accesstoken').val();
const apiKey = $('#api-key').val();
// const apiKey = $('#api-key').val();
const apiKey = null;
const baseUrl = `https://api.github.com`;
const otp = $('#otp').val();
return {
Expand All @@ -104,7 +108,8 @@ function getGHEParam() {
const username = $('#ghe-username').val();
const password = $('#ghe-password').val();
const token = $('#ghe-accesstoken').val();
const apiKey = $('#ghe-api-key').val();
// const apiKey = $('#ghe-api-key').val();
const apiKey = null;
const baseUrl = $('#ghe-url').val() + '/api/v3';
const otp = $('#ghe-otp').val();
return {
Expand All @@ -122,7 +127,8 @@ function getBitbucketParam() {
const scm = 'bitbucket';
const username = $('#bitbucket-email').val();
const password = $('#bitbucket-password').val();
const apiKey = $('#bitbucket-api-key').val();
// const apiKey = $('#bitbucket-api-key').val();
const apiKey = null;
const baseUrl = `https://api.bitbucket.org/2.0`;
return {
scm,
Expand All @@ -139,7 +145,8 @@ function getGitLabParam() {
const password = $('#gitlab-password').val();
const token = $('#gitlab-accesstoken').val();
const tokenType = (token && token.length > 0) ? 'personalToken' : 'oAuth';
const apiKey = $('#gitlab-api-key').val();
// const apiKey = $('#gitlab-api-key').val();
const apiKey = null;
const baseUrl = ($('#gitlab-url').val() || 'https://gitlab.com') + '/api/v4';
return {
scm,
Expand All @@ -164,7 +171,7 @@ function addCred(param) {
const payload = {
code: param.apiKey,
client_id: "971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com",
client_secret: "epw3f_WvEn0Uwqi6kE7DBQl7",
client_secret: __SECRET__,
redirect_uri: "urn:ietf:wg:oauth:2.0:oob",
grant_type: "authorization_code",
access_type: "offline"
Expand Down Expand Up @@ -408,7 +415,7 @@ function loginGitLabToken(param) {
}

function logout() {
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'googleApiKey'], () => {
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'gapiToken', 'gapiRefreshToken'], () => {
location.reload();
});
chrome.storage.local.get('tab', (item) => {
Expand Down Expand Up @@ -443,4 +450,22 @@ function addStar(token) {
})
.always(resolve);
})
}

function auth() {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({
cmd: 'login',
interactive: true
}, token => {
if (token == null) {
reject("can not get oauth token, currently only support Chrome");
} else {
chrome.storage.sync.set({
"gapiToken": token
});
resolve(token);
}
});
});
}
14 changes: 12 additions & 2 deletions src/gas-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function load() {
.then(updateBranch)
.then(updateGist)
.then(initPageEvent)
.catch((err) => {
showLog(err, LEVEL_ERROR);
})
break;
case 'not match':
break;
Expand Down Expand Up @@ -342,8 +345,15 @@ function auth() {
cmd: 'login',
interactive: true
}, token => {
context.gapiToken = token;
resolve(token);
if (token == null) {
reject("can not get oauth token, currently only support Chrome");
} else {
context.gapiToken = token;
chrome.storage.sync.set({
"gapiToken": token
});
resolve(token);
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/gas/script-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ScriptApi {
const payload = {
refresh_token: context.gapiRefreshToken,
client_id: "971735641612-am059p55sofdp30p2t4djecn72l6kmpf.apps.googleusercontent.com",
client_secret: "epw3f_WvEn0Uwqi6kE7DBQl7",
client_secret: __SECRET__,
redirect_uri: "urn:ietf:wg:oauth:2.0:oob",
grant_type: "refresh_token",
}
Expand Down

0 comments on commit c4b7f70

Please sign in to comment.