-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassport.js
46 lines (38 loc) · 1.56 KB
/
passport.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
45
46
// https://massivcode.com/9
const commonInfo = require('./routes/util');
const FacebookStrategy = require('passport-facebook').Strategy;
const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
module.exports = (passport) => {
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
passport.use(new FacebookStrategy({
clientID: commonInfo.facebook_clientID,
clientSecret: commonInfo.facebook_clientSecret,
profileFields: ['id', 'displayName', 'name', 'email'],
callbackURL: commonInfo.facebook_callbackURL
},
function (accessToken, refreshToken, profile, done) {
let user = {sns:'f', id: 'f'+profile.id, name: profile.name.familyName+profile.name.givenName, email: profile.emails[0].value}
onLoginSuccess(user, done);
}
));
passport.use(new GoogleStrategy({
clientID: commonInfo.google_clientID,
clientSecret: commonInfo.google_clientSecret,
callbackURL: commonInfo.google_callbackURL,
scope: ["profile", "email"]
}, function (accessToken, refreshToken, profile, done) {
let user = {sns:'g', id: 'g' + profile.id, name: profile.displayName, email: profile.emails[0].value}
console.log(profile)
onLoginSuccess(user, done);
}
));
function onLoginSuccess( user, done) {
//console.log(socialid);
return done(null, user);
}
};