-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (40 loc) · 1.3 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
35
36
37
38
39
40
41
42
43
44
const GitHubStrategy = require('passport-github2').Strategy;
module.exports = ({ config, host, app }) => {
return {
auth({ providers, passport }) {
providers.push({ id: 'github', name: 'Github' });
passport.use(
new GitHubStrategy(
{
clientID: config.client_id,
clientSecret: config.client_secret,
callbackURL: `${host}/auth/github/callback`
},
(accessToken, refreshToken, profile, done) => {
done(null, profile);
}
)
);
app.get(
'/auth/github',
passport.authenticate('github', {
scope: ['user:email']
})
);
app.get(
'/auth/github/callback',
passport.authenticate('github', {
failureRedirect: '/login'
}),
(request, reply) => {
reply.redirect('/success');
}
);
return {
getAuthorUrl({ name }) {
return `https://github.com/${name}`;
}
};
}
};
};