HackMD/lib/auth.js

49 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-05-04 07:53:29 +00:00
//auth
//external modules
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
var TwitterStrategy = require('passport-twitter').Strategy;
var GithubStrategy = require('passport-github').Strategy;
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
//core
var User = require('./user.js')
var config = require('../config.js')
function callback(accessToken, refreshToken, profile, done) {
//console.log(profile.displayName || profile.username);
User.findOrNewUser(profile.id, profile, function (err, user) {
if (err || user == null) {
console.log('auth callback failed: ' + err);
} else {
if(config.debug && user)
console.log('user login: ' + user._id);
done(null, user);
}
});
}
//facebook
module.exports = passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
2015-05-15 04:58:13 +00:00
callbackURL: config.getserverurl() + config.facebook.callbackPath
2015-05-04 07:53:29 +00:00
}, callback));
//twitter
passport.use(new TwitterStrategy({
consumerKey: config.twitter.consumerKey,
consumerSecret: config.twitter.consumerSecret,
2015-05-15 04:58:13 +00:00
callbackURL: config.getserverurl() + config.twitter.callbackPath
2015-05-04 07:53:29 +00:00
}, callback));
//github
passport.use(new GithubStrategy({
clientID: config.github.clientID,
clientSecret: config.github.clientSecret,
2015-05-15 04:58:13 +00:00
callbackURL: config.getserverurl() + config.github.callbackPath
2015-05-04 07:53:29 +00:00
}, callback));
//dropbox
passport.use(new DropboxStrategy({
clientID: config.dropbox.clientID,
clientSecret: config.dropbox.clientSecret,
2015-05-15 04:58:13 +00:00
callbackURL: config.getserverurl() + config.dropbox.callbackPath
2015-05-04 07:53:29 +00:00
}, callback));