-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
38 lines (35 loc) · 1 KB
/
server.ts
File metadata and controls
38 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import express from 'express';
import { CLIENT_ID, CLIENT_SECRET } from './utils/creds';
import axios from 'axios';
import { addEmailTOOrg } from './src/AddEmail';
const app = express();
const port = 3000;
let token = null;
app.get('/', (req, res) => {
res.redirect(
`https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&scope=admin:org`
);
});
app.get('/authenticated', (req, res) => {
res.send('Authenticated!');
});
app.get('/oauth-callback', async (req, res) => {
const body = {
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
code: req.query.code,
};
const opts = { headers: { accept: 'application/json' } };
const resGit = await axios.post(
`https://github.com/login/oauth/access_token`,
body,
opts
);
const token = resGit.data['access_token'];
if (await addEmailTOOrg(token, 'mnimitsavant@outlook.com')) {
res.redirect('http://localhost:3000/authenticated');
}
});
app.listen(port, () => {
console.log(`Application running on port: ${port}`);
});