forked from rickyrauch/Balloons.IO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.js
72 lines (60 loc) · 1.72 KB
/
strategy.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Module dependencies
*/
var passport = require('passport')
, TwitterStrategy = require('passport-twitter').Strategy
, FacebookStrategy = require('passport-facebook').Strategy
, GitHubStrategy = require('passport-github').Strategy;
/**
* Expose Authentication Strategy
*/
module.exports = Strategy;
/*
* Defines Passport authentication
* strategies from application configs
*
* @param {Express} app `Express` instance.
* @api public
*/
function Strategy (app) {
var config = app.get('config');
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
if(config.auth.twitter.consumerkey.length) {
passport.use(new TwitterStrategy({
consumerKey: config.auth.twitter.consumerkey,
consumerSecret: config.auth.twitter.consumersecret,
callbackURL: config.auth.twitter.callback
},
function(token, tokenSecret, profile, done) {
return done(null, profile);
}
));
}
if(config.auth.facebook.clientid.length) {
passport.use(new FacebookStrategy({
clientID: config.auth.facebook.clientid,
clientSecret: config.auth.facebook.clientsecret,
callbackURL: config.auth.facebook.callback
},
function(accessToken, refreshToken, profile, done) {
return done(null, profile);
}
));
}
if(config.auth.github.clientid.length) {
passport.use(new GitHubStrategy({
clientID: config.auth.github.clientid,
clientSecret: config.auth.github.clientsecret,
callbackURL: config.auth.github.callback
},
function(token, tokenSecret, profile, done) {
return done(null, profile);
}
));
}
}