-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
24 lines (19 loc) · 902 Bytes
/
auth.ts
File metadata and controls
24 lines (19 loc) · 902 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
import { Express } from 'express';
import axios from 'axios';
import * as queryString from 'query-string';
import { environment } from '../environments/environment';
const githubConfig = environment.ghConfig;
const accessTokenURL = (code) => `https://github.com/login/oauth/access_token?code=${code}&client_secret=${githubConfig.client_id}&client_id=${githubConfig.client_secret}&redirect_uri=http://localhost:4200/callback`;
export function githubAccessToken(app: Express) {
app.post('/api/auth', async (req, res) => {
const ghCodeFromClient = req.query.code;
try {
const queryForAccessToken = await axios.post(accessTokenURL(ghCodeFromClient));
const parseData = queryString.parse(queryForAccessToken.data);
const access_token = parseData.access_token;
res.send({ access_token });
} catch (error) {
console.log('Error adfadsf ', error);
}
});
}