-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
42 lines (33 loc) · 1.02 KB
/
auth.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
const passport = require('passport');
const GitHubStrategy = require('passport-github2').Strategy;
const config = require('./config');
const githubConfig = config.github;
const clientID = githubConfig.clientID;
const clientSecret = githubConfig.clientSecret;
function verify(req, accessToken, refreshToken, profile, done) {
profile = JSON.parse(profile._raw);
return done(null, {
id: profile.id,
avatar: profile.avatar_url,
login: profile.login,
accessToken
});
}
// serialize user into the session
passport.serializeUser((user, done) => {
done(null, JSON.stringify(user));
});
passport.deserializeUser((user, done) => {
done(null, JSON.parse(user));
});
if (!clientID || !clientSecret) {
console.error('Please provide clientID and clientSecret');
return;
}
passport.use(new GitHubStrategy({
clientID,
clientSecret,
callbackURL: githubConfig.authCallbackSite + config.pathPrefix + '/login_callback',
passReqToCallback: true
}, verify));
module.exports = passport;