Github oauth2 has a check for authenticated user now as well
This commit is contained in:
@ -49,7 +49,21 @@ passport.use(new FacebookStrategy(config.facebook, function (accessToken, refres
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
passport.use(new GitHubStrategy(config.github, function(accessToken, refreshToken, profile, done) {
|
passport.use(new GitHubStrategy(config.github, function(req, accessToken, refreshToken, profile, done) {
|
||||||
|
if (req.user) {
|
||||||
|
User.findById(req.user.id, function(err, user) {
|
||||||
|
user.github = profile.id;
|
||||||
|
user.tokens.push({ kind: 'github', token: accessToken, tokenSecret: tokenSecret });
|
||||||
|
user.profile.name = profile.displayName;
|
||||||
|
user.profile.email = user.profile.email || profile._json.email;
|
||||||
|
user.profile.picture = user.profile.picture || profile._json.profile_image_url;
|
||||||
|
user.profile.location = user.profile.location || profile._json.location;
|
||||||
|
user.profile.website = user.profile.website || profile._json.blog;
|
||||||
|
user.save(function(err) {
|
||||||
|
done(err, user);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
User.findOne({ github: profile.id }, function(err, existingUser) {
|
User.findOne({ github: profile.id }, function(err, existingUser) {
|
||||||
if (existingUser) return done(null, existingUser);
|
if (existingUser) return done(null, existingUser);
|
||||||
var user = new User();
|
var user = new User();
|
||||||
@ -64,6 +78,7 @@ passport.use(new GitHubStrategy(config.github, function(accessToken, refreshToke
|
|||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
passport.use(new TwitterStrategy(config.twitter, function(req, accessToken, tokenSecret, profile, done) {
|
passport.use(new TwitterStrategy(config.twitter, function(req, accessToken, tokenSecret, profile, done) {
|
||||||
|
Reference in New Issue
Block a user