Skip to content

Commit d6f3e75

Browse files
Merge pull request #57 from DesmondSanctity/separate-project-event-badging
fix: separate concern for project and event badging
2 parents 9b2609c + 7c447e2 commit d6f3e75

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

providers/github/auth.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const githubAuth = (req, res) => {
3636
const scopes = ["public_repo"];
3737
const encryptedFormData = encrypt(JSON.stringify(req.body));
3838
const url = `https://github.com/login/oauth/authorize?client_id=${
39-
process.env.GITHUB_AUTH_CLIENT_ID
39+
process.env.GITHUB_AUTH_CLIENT_ID_EVENT
4040
}&scope=${scopes.join(",")}&state=${encryptedFormData}`;
4141

4242
res.send({ authorizationLink: url });
@@ -55,15 +55,19 @@ const githubAuth = (req, res) => {
5555
* @param {*} code Code returned by the GitHub OAuth authorization API
5656
* @returns A json object with `access_token` and `errors`
5757
*/
58-
const requestAccessToken = async (code) => {
58+
const requestAccessToken = async (code, isEventBadging = false) => {
5959
try {
6060
const {
6161
data: { access_token },
6262
} = await axios.post(
6363
"https://github.com/login/oauth/access_token",
6464
{
65-
client_id: process.env.GITHUB_AUTH_CLIENT_ID,
66-
client_secret: process.env.GITHUB_AUTH_CLIENT_SECRET,
65+
client_id: isEventBadging
66+
? process.env.GITHUB_AUTH_CLIENT_ID_EVENT
67+
: process.env.GITHUB_AUTH_CLIENT_ID,
68+
client_secret: isEventBadging
69+
? process.env.GITHUB_AUTH_CLIENT_SECRET_EVENT
70+
: process.env.GITHUB_AUTH_CLIENT_SECRET,
6771
code,
6872
},
6973
{
@@ -90,17 +94,19 @@ const handleOAuthCallback = async (req, res) => {
9094

9195
let issueTitle;
9296
let markdown;
97+
let isEventBadging = false;
9398

9499
if (req.query.state) {
95100
const encryptedState = req.query.state;
96101
const formData = decrypt(encryptedState);
97102
const parsedFormData = JSON.parse(formData);
98103
issueTitle = parsedFormData.title;
99104
markdown = convertToMarkdown(parsedFormData.body);
105+
isEventBadging = true;
100106
}
101107

102108
const { access_token: accessToken, errors: accessTokenErrors } =
103-
await requestAccessToken(code);
109+
await requestAccessToken(code, isEventBadging);
104110
if (accessTokenErrors.length > 0) {
105111
res.status(500).send(accessTokenErrors.join());
106112
return;

routes/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ const setupRoutes = (app) => {
159159
app.get("/api/callback/github", handleOAuthCallback);
160160
app.get("/api/callback/gitlab", handleOAuthCallbackGitlab);
161161

162+
app.post("/api/callback/github", handleOAuthCallback);
163+
app.post("/api/callback/gitlab", handleOAuthCallbackGitlab);
164+
162165
app.get("/api/badgedRepos", badgedRepos);
163166
app.post("/api/repos-to-badge", reposToBadge);
164167

0 commit comments

Comments
 (0)