forked from nodebusters/ask-izzy-plus-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigPassport.js
31 lines (28 loc) · 1.16 KB
/
configPassport.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
// DOTENV: Reads environmental variables from .env file
require('dotenv').load();
// PASSPORT: Using Google authentication strategy for OAuth
const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
// PASSPORT: Once authenticated, each subsequent request will not contain credentials, but rather the unique cookie that identifies the session.
// In order to support login sessions, Passport will serialize and deserialize user instances to and from the session.
function configPassport(passport) {
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `${process.env.GOOGLE_CALLBACK_URL}`
},
// Requires a `verify` function, which accept credentials (a token, refreshToken, and Google profile), and invoke 'done' callback with a user object and options
(token, refreshToken, profile, done) => {
return done(null, {
profile: profile,
token: token
});
}
));
}
module.exports = configPassport;