-
Notifications
You must be signed in to change notification settings - Fork 3
/
HabitsPassport.js
53 lines (45 loc) · 1.32 KB
/
HabitsPassport.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
47
48
49
50
51
52
53
/**
* @module HabitsPassport
* @desc The Passports module configured for the Facebook authentication
* used by Habits.
*/
var passport = require('passport'),
FacebookStrategy = require('passport-facebook').Strategy;
var fbPermsScope = ['email'];
function getFBCallbackURL(config) {
// Use Prod by default
var baseURL = config.BASE_URL_PRODUCTION;
if (config.env === 'dev') {
baseURL = config.BASE_URL_DEV;
}
return baseURL + 'auth/facebook/callback';
}
function getFBConfig(config) {
if (config.env === 'dev') {
return config.FB_DEVO;
} else if (config.env === 'production') {
return config.FB_PROD;
}
throw new Error('Unknown environment name');
}
module.exports = function(config) {
var fbConfig = getFBConfig(config);
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new FacebookStrategy({
clientID: fbConfig.APP_ID,
clientSecret: fbConfig.SECRET,
callbackURL: getFBCallbackURL(config),
profileFields: ['id', 'displayName', 'email', 'picture', 'friends']
},
function(accessToken, refreshToken, profile, done) {
// TODO: Associate the user profile with a database record here
return done(null, profile);
}
));
return passport;
};