-
Notifications
You must be signed in to change notification settings - Fork 127
/
index.js
34 lines (30 loc) · 1.08 KB
/
index.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
33
34
const simpleOauthModule = require('simple-oauth2')
const authMiddleWareInit = require('./auth.js')
const callbackMiddleWareInit = require('./callback')
const oauthProvider = process.env.OAUTH_PROVIDER || 'github'
const loginAuthTarget = process.env.AUTH_TARGET || '_self'
const config = {
client: {
id: process.env.OAUTH_CLIENT_ID,
secret: process.env.OAUTH_CLIENT_SECRET
},
auth: {
// Supply GIT_HOSTNAME for enterprise github installs.
tokenHost: process.env.GIT_HOSTNAME || 'https://github.com',
tokenPath: process.env.OAUTH_TOKEN_PATH || '/login/oauth/access_token',
authorizePath: process.env.OAUTH_AUTHORIZE_PATH || '/login/oauth/authorize'
}
}
const oauth2 = new simpleOauthModule.AuthorizationCode(config)
function indexMiddleWare (req, res) {
res.send(`Hello<br>
<a href="/auth" target="${loginAuthTarget}">
Log in with ${oauthProvider.toUpperCase()}
</a>`)
}
module.exports = {
auth: authMiddleWareInit(oauth2),
callback: callbackMiddleWareInit(oauth2, oauthProvider),
success: (req, res) => { res.send('') },
index: indexMiddleWare
}