check github token

This commit is contained in:
tdurieux
2021-04-30 14:21:30 +02:00
parent b1ab7e5659
commit fa79df7efa
3 changed files with 220 additions and 1 deletions

203
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "2.0.0",
"license": "MIT",
"dependencies": {
"@octokit/oauth-app": "^3.3.2",
"@octokit/rest": "^18.5.3",
"array-equal": "^1.0.0",
"compression": "^1.7.4",
@@ -33,6 +34,44 @@
"nodemon": "^2.0.4"
}
},
"node_modules/@octokit/auth-oauth-app": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/@octokit/auth-oauth-app/-/auth-oauth-app-4.1.2.tgz",
"integrity": "sha512-bdNGNRmuDJjKoHla3mUGtkk/xcxKngnQfBEnyk+7VwMqrABKvQB1wQRSrwSWkPPUX7Lcj2ttkPAPG7+iBkMRnw==",
"dependencies": {
"@octokit/auth-oauth-device": "^3.1.1",
"@octokit/auth-oauth-user": "^1.2.1",
"@octokit/request": "^5.3.0",
"@octokit/types": "^6.0.3",
"@types/btoa-lite": "^1.0.0",
"btoa-lite": "^1.0.0",
"universal-user-agent": "^6.0.0"
}
},
"node_modules/@octokit/auth-oauth-device": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@octokit/auth-oauth-device/-/auth-oauth-device-3.1.1.tgz",
"integrity": "sha512-ykDZROilszXZJ6pYdl6SZ15UZniCs0zDcKgwOZpMz3U0QDHPUhFGXjHToBCAIHwbncMu+jLt4/Nw4lq3FwAw/w==",
"dependencies": {
"@octokit/oauth-methods": "^1.1.0",
"@octokit/request": "^5.4.14",
"@octokit/types": "^6.10.0",
"universal-user-agent": "^6.0.0"
}
},
"node_modules/@octokit/auth-oauth-user": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@octokit/auth-oauth-user/-/auth-oauth-user-1.2.4.tgz",
"integrity": "sha512-efOajupCZBP1veqx5w59Qey0lIud1rDUgxTRjjkQDU3eOBmkAasY1pXemDsQwW0I85jb1P/gn2dMejedVxf9kw==",
"dependencies": {
"@octokit/auth-oauth-device": "^3.1.1",
"@octokit/oauth-methods": "^1.1.0",
"@octokit/request": "^5.4.14",
"@octokit/types": "^6.12.2",
"btoa-lite": "^1.0.0",
"universal-user-agent": "^6.0.0"
}
},
"node_modules/@octokit/auth-token": {
"version": "2.4.5",
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.5.tgz",
@@ -41,6 +80,15 @@
"@octokit/types": "^6.0.3"
}
},
"node_modules/@octokit/auth-unauthenticated": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-2.0.4.tgz",
"integrity": "sha512-jZMwIz2PfQuLcOQRRELY6zb/jIyWQKlPxVV1oEG4sxJNmnANz3Skvnz4kVNvfs1r2jhgKAx9Pb6f+3vXeyh7yg==",
"dependencies": {
"@octokit/request-error": "^2.0.2",
"@octokit/types": "^6.0.3"
}
},
"node_modules/@octokit/core": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.4.0.tgz",
@@ -75,6 +123,38 @@
"universal-user-agent": "^6.0.0"
}
},
"node_modules/@octokit/oauth-app": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/@octokit/oauth-app/-/oauth-app-3.3.2.tgz",
"integrity": "sha512-vZPleCS65Sq2fXQYWt1JmTqrNUdsmdvmgr4rmZhxKaX/Fc6xExtNCBmksAbSMY9q3uFBv76BuvNWGKFNpXy5Tw==",
"dependencies": {
"@octokit/auth-oauth-app": "^4.0.0",
"@octokit/auth-oauth-user": "^1.2.3",
"@octokit/auth-unauthenticated": "^2.0.0",
"@octokit/core": "^3.3.2",
"@octokit/oauth-authorization-url": "^4.2.1",
"@octokit/oauth-methods": "^1.2.2",
"fromentries": "^1.3.1",
"universal-user-agent": "^6.0.0"
}
},
"node_modules/@octokit/oauth-authorization-url": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-4.3.1.tgz",
"integrity": "sha512-sI/SOEAvzRhqdzj+kJl+2ifblRve2XU6ZB36Lq25Su8R31zE3GoKToSLh64nWFnKePNi2RrdcMm94UEIQZslOw=="
},
"node_modules/@octokit/oauth-methods": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@octokit/oauth-methods/-/oauth-methods-1.2.2.tgz",
"integrity": "sha512-CFMUMn9DdPLMcpffhKgkwIIClfv0ZToJM4qcg4O0egCoHMYkVlxl22bBoo9qCnuF1U/xn871KEXuozKIX+bA2w==",
"dependencies": {
"@octokit/oauth-authorization-url": "^4.3.1",
"@octokit/request": "^5.4.14",
"@octokit/request-error": "^2.0.5",
"@octokit/types": "^6.12.2",
"btoa-lite": "^1.0.0"
}
},
"node_modules/@octokit/openapi-types": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-6.1.1.tgz",
@@ -174,6 +254,11 @@
"node": ">=6"
}
},
"node_modules/@types/btoa-lite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/btoa-lite/-/btoa-lite-1.0.0.tgz",
"integrity": "sha512-wJsiX1tosQ+J5+bY5LrSahHxr2wT+uME5UDwdN1kg4frt40euqA+wzECkmq4t5QbveHiJepfdThgQrPw6KiSlg=="
},
"node_modules/@types/node": {
"version": "14.14.41",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.41.tgz",
@@ -557,6 +642,11 @@
"node": ">=0.6.19"
}
},
"node_modules/btoa-lite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/btoa-lite/-/btoa-lite-1.0.0.tgz",
"integrity": "sha1-M3dm2hWAEhD92VbCLpxokaudAzc="
},
"node_modules/buffer-crc32": {
"version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
@@ -1245,6 +1335,25 @@
"node": ">= 0.6"
}
},
"node_modules/fromentries": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz",
"integrity": "sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/fs-extra": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz",
@@ -3497,6 +3606,44 @@
}
},
"dependencies": {
"@octokit/auth-oauth-app": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/@octokit/auth-oauth-app/-/auth-oauth-app-4.1.2.tgz",
"integrity": "sha512-bdNGNRmuDJjKoHla3mUGtkk/xcxKngnQfBEnyk+7VwMqrABKvQB1wQRSrwSWkPPUX7Lcj2ttkPAPG7+iBkMRnw==",
"requires": {
"@octokit/auth-oauth-device": "^3.1.1",
"@octokit/auth-oauth-user": "^1.2.1",
"@octokit/request": "^5.3.0",
"@octokit/types": "^6.0.3",
"@types/btoa-lite": "^1.0.0",
"btoa-lite": "^1.0.0",
"universal-user-agent": "^6.0.0"
}
},
"@octokit/auth-oauth-device": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@octokit/auth-oauth-device/-/auth-oauth-device-3.1.1.tgz",
"integrity": "sha512-ykDZROilszXZJ6pYdl6SZ15UZniCs0zDcKgwOZpMz3U0QDHPUhFGXjHToBCAIHwbncMu+jLt4/Nw4lq3FwAw/w==",
"requires": {
"@octokit/oauth-methods": "^1.1.0",
"@octokit/request": "^5.4.14",
"@octokit/types": "^6.10.0",
"universal-user-agent": "^6.0.0"
}
},
"@octokit/auth-oauth-user": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@octokit/auth-oauth-user/-/auth-oauth-user-1.2.4.tgz",
"integrity": "sha512-efOajupCZBP1veqx5w59Qey0lIud1rDUgxTRjjkQDU3eOBmkAasY1pXemDsQwW0I85jb1P/gn2dMejedVxf9kw==",
"requires": {
"@octokit/auth-oauth-device": "^3.1.1",
"@octokit/oauth-methods": "^1.1.0",
"@octokit/request": "^5.4.14",
"@octokit/types": "^6.12.2",
"btoa-lite": "^1.0.0",
"universal-user-agent": "^6.0.0"
}
},
"@octokit/auth-token": {
"version": "2.4.5",
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.5.tgz",
@@ -3505,6 +3652,15 @@
"@octokit/types": "^6.0.3"
}
},
"@octokit/auth-unauthenticated": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-2.0.4.tgz",
"integrity": "sha512-jZMwIz2PfQuLcOQRRELY6zb/jIyWQKlPxVV1oEG4sxJNmnANz3Skvnz4kVNvfs1r2jhgKAx9Pb6f+3vXeyh7yg==",
"requires": {
"@octokit/request-error": "^2.0.2",
"@octokit/types": "^6.0.3"
}
},
"@octokit/core": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.4.0.tgz",
@@ -3539,6 +3695,38 @@
"universal-user-agent": "^6.0.0"
}
},
"@octokit/oauth-app": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/@octokit/oauth-app/-/oauth-app-3.3.2.tgz",
"integrity": "sha512-vZPleCS65Sq2fXQYWt1JmTqrNUdsmdvmgr4rmZhxKaX/Fc6xExtNCBmksAbSMY9q3uFBv76BuvNWGKFNpXy5Tw==",
"requires": {
"@octokit/auth-oauth-app": "^4.0.0",
"@octokit/auth-oauth-user": "^1.2.3",
"@octokit/auth-unauthenticated": "^2.0.0",
"@octokit/core": "^3.3.2",
"@octokit/oauth-authorization-url": "^4.2.1",
"@octokit/oauth-methods": "^1.2.2",
"fromentries": "^1.3.1",
"universal-user-agent": "^6.0.0"
}
},
"@octokit/oauth-authorization-url": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-4.3.1.tgz",
"integrity": "sha512-sI/SOEAvzRhqdzj+kJl+2ifblRve2XU6ZB36Lq25Su8R31zE3GoKToSLh64nWFnKePNi2RrdcMm94UEIQZslOw=="
},
"@octokit/oauth-methods": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@octokit/oauth-methods/-/oauth-methods-1.2.2.tgz",
"integrity": "sha512-CFMUMn9DdPLMcpffhKgkwIIClfv0ZToJM4qcg4O0egCoHMYkVlxl22bBoo9qCnuF1U/xn871KEXuozKIX+bA2w==",
"requires": {
"@octokit/oauth-authorization-url": "^4.3.1",
"@octokit/request": "^5.4.14",
"@octokit/request-error": "^2.0.5",
"@octokit/types": "^6.12.2",
"btoa-lite": "^1.0.0"
}
},
"@octokit/openapi-types": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-6.1.1.tgz",
@@ -3624,6 +3812,11 @@
"defer-to-connect": "^1.0.1"
}
},
"@types/btoa-lite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/btoa-lite/-/btoa-lite-1.0.0.tgz",
"integrity": "sha512-wJsiX1tosQ+J5+bY5LrSahHxr2wT+uME5UDwdN1kg4frt40euqA+wzECkmq4t5QbveHiJepfdThgQrPw6KiSlg=="
},
"@types/node": {
"version": "14.14.41",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.41.tgz",
@@ -3929,6 +4122,11 @@
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz",
"integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg=="
},
"btoa-lite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/btoa-lite/-/btoa-lite-1.0.0.tgz",
"integrity": "sha1-M3dm2hWAEhD92VbCLpxokaudAzc="
},
"buffer-crc32": {
"version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
@@ -4459,6 +4657,11 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"fromentries": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz",
"integrity": "sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg=="
},
"fs-extra": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz",

View File

@@ -19,6 +19,7 @@
},
"homepage": "https://github.com/tdurieux/anonymous_github#readme",
"dependencies": {
"@octokit/oauth-app": "^3.3.2",
"@octokit/rest": "^18.5.3",
"array-equal": "^1.0.0",
"compression": "^1.7.4",

View File

@@ -1,4 +1,5 @@
const ofs = require("fs");
const { OAuthApp } = require("@octokit/oauth-app");
const db = require("./database");
const repoUtils = require("./repository");
@@ -6,6 +7,12 @@ const fileUtils = require("./file");
const config = require("../config");
const app = new OAuthApp({
clientType: "github-app",
clientId: config.CLIENT_ID,
clientSecret: config.CLIENT_SECRET,
});
module.exports.getToken = async (repoConfig) => {
if (repoConfig.owner) {
const user = await db
@@ -20,7 +27,15 @@ module.exports.getToken = async (repoConfig) => {
}
}
if (repoConfig.token) {
return repoConfig.token;
try {
await app.checkToken({
token: repoConfig.token,
});
return repoConfig.token;
} catch (error) {
console.debug("Token is invalid.", error);
delete repoConfig.token;
}
}
return config.GITHUB_TOKEN;
};