-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth.js
33 lines (27 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
var passport = require('passport'),
googleAuth = require('passport-google-oauth2').Strategy,
user = require('./controllers/userController');
module.exports = function(app) {
app.use(passport.initialize());
app.use(passport.session());
// Setup Authentication
passport.use(new googleAuth({
clientID: config.google.clientId,
clientSecret: config.google.clientSecret,
callbackURL: config.google.callbackURL,
passReqToCallback: true
}, user.authenticate));
passport.serializeUser(user.serializeUser);
passport.deserializeUser(user.deserializeUser);
// google auth routes
app.get('/auth/google',
passport.authenticate('google', { scope:
[ 'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.profile.emails.read' ] }
));
app.get('/auth/google/callback',
passport.authenticate('google', {
successRedirect: '/',
failureRedirect: '/loginError'
}));
}