forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
32 lines (23 loc) · 806 Bytes
/
Copy pathauth.js
File metadata and controls
32 lines (23 loc) · 806 Bytes
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
import express from 'express';
import { githubClientId } from '/environment';
import { GitHubApi } from '/apis';
const router = express.Router();
const request = (req, res, next) => {
res.redirect(`https://github.com/login/oauth/authorize?client_id=${githubClientId}&scope=user,gist`);
};
const response = (req, res, next) => {
const { code } = req.query;
GitHubApi.getAccessToken(code).then(({ access_token }) => {
res.send(`<script>window.opener.signIn('${access_token}');window.close();</script>`);
}).catch(next);
};
const destroy = (req, res, next) => {
res.send(`<script>window.opener.signOut();window.close();</script>`);
};
router.route('/request')
.get(request);
router.route('/response')
.get(response);
router.route('/destroy')
.get(destroy);
export default router;