mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 10:52:53 +00:00
check github token
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user