-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpassport.js
124 lines (105 loc) · 3.78 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//passport strategies
var passport = require('passport');
var C = require('./config.js');
var TwitterStrategy = require('passport-twitter').Strategy;
var FacebookStrategy = require('passport-facebook').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var GithubStrategy = require('passport-github').Strategy;
var Url = require('url');
exports.passport = passport;
passport.serializeUser(function(user, done) {
done(null, JSON.stringify(user));
});
passport.deserializeUser(function(serializedUser, done) {
try{
done(null, JSON.parse(serializedUser));
}catch(e){
done(e, null);
};
});
passport.use(new TwitterStrategy({
consumerKey: C.PASSPORT.Twitter.ConsumerKey,
consumerSecret: C.PASSPORT.Twitter.ConsumerSecret,
callbackURL: C.PASSPORT.Twitter.CallbackUrl
},
function(token, tokenSecret, profile, done) {
C.debug('>>> SEARCHING FOR TWITTER USER ON CLOUDSPOKES');
C.debug('Twitter profile');
C.debug(profile);
done(null, {id: profile.id,
username: profile.username,
service: 'twitter',
displayName: profile.displayName});
}));
passport.use(new FacebookStrategy({
clientID: C.PASSPORT.Facebook.ConsumerKey,
clientSecret: C.PASSPORT.Facebook.ConsumerSecret,
callbackURL: C.PASSPORT.Facebook.CallbackUrl
},
function(token, tokenSecret, profile, done) {
C.debug('>>> SEARCHING FOR FACEBOOK USER ON CLOUDSPOKES');
C.debug('Facebook profile');
C.debug(profile);
done(null, {id: profile.id,
username: profile.username,
service: 'facebook',
displayName: profile.displayName});
}));
passport.use(new GoogleStrategy({
clientID: C.PASSPORT.Google.ClientKey,
clientSecret: C.PASSPORT.Google.ClientSecret,
callbackURL: C.PASSPORT.Google.CallbackURL
},
function(accessToken, refreshToken, profile, done) {
C.debug('>>> SEARCHING FOR GOOGLE USER ON CLOUDSPOKES');
C.debug('Google profile');
C.debug(profile);
done(null, {id: profile.id,
username: profile.id,
service: 'google_oauth2',
displayName: profile.displayName});
}
));
passport.use(new GithubStrategy({
clientID: C.PASSPORT.GitHub.ClientId,
clientSecret: C.PASSPORT.GitHub.ClientSecret,
callbackURL: C.PASSPORT.GitHub.CallbackURL
},
function(accessToken, refreshToken, profile, done) {
C.debug('>>> SEARCHING FOR GITHUB USER ON CLOUDSPOKES');
C.debug('GitHub profile');
C.debug(profile);
done(null, {id: profile.id,
username: profile.username,
service: 'github',
displayName: profile.displayName});
}
));
exports.twitterAuthRequest = function(req,res){
passport.authenticate('twitter')(req,res);
};
exports.twitterAuthCallback = function(req,res){
passport.authenticate('twitter', { successRedirect: '/',
failureRedirect: '/' })(req,res);
};
exports.facebookAuthRequest = function(req,res){
passport.authenticate('facebook')(req,res);
};
exports.facebookAuthCallback = function(req,res){
passport.authenticate('facebook', { successRedirect: '/',
failureRedirect: '/' })(req,res);
};
exports.googleAuthRequest = function(req,res){
passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/userinfo.profile'] })(req,res);
};
exports.googleAuthCallback = function(req,res){
passport.authenticate('google', { successRedirect: '/',
failureRedirect: '/' })(req,res);
};
exports.githubAuthRequest = function(req,res){
passport.authenticate('github')(req,res);
};
exports.githubAuthCallback = function(req,res){
passport.authenticate('github', { successRedirect: '/',
failureRedirect: '/' })(req,res);
};