forked from eduardoboucas/staticman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubAuth.js
32 lines (28 loc) · 847 Bytes
/
githubAuth.js
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
'use strict'
const path = require('path')
const GitHub = require(path.join(__dirname, '/../lib/GitHub'))
const RSA = require('../lib/RSA')
const Staticman = require('../lib/Staticman')
module.exports = (req, res) => {
const github = new GitHub()
const staticman = new Staticman(req.params)
staticman.authenticate()
staticman.setConfigPath()
return staticman.getSiteConfig().then(siteConfig => {
return github.authenticateWithCode({
code: req.query.code,
clientId: siteConfig.get('githubAuth.clientId'),
clientSecret: siteConfig.get('githubAuth.clientSecret')
})
}).then(accessToken => {
return github.api.users.get({}).then(user => {
res.send({
accessToken: RSA.encrypt(accessToken),
user
})
})
}).catch(err => {
console.log('ERR:', err)
res.send(err)
})
}