From 4b0ca55eb79e963523eb6c8197825e9e8ae904e2 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 4 May 2015 15:53:29 +0800 Subject: First commit, version 0.2.7 --- lib/auth.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/auth.js (limited to 'lib/auth.js') diff --git a/lib/auth.js b/lib/auth.js new file mode 100644 index 00000000..e7b0dc7c --- /dev/null +++ b/lib/auth.js @@ -0,0 +1,49 @@ +//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, + callbackURL: config.domain + config.facebook.callbackPath +}, callback)); +//twitter +passport.use(new TwitterStrategy({ + consumerKey: config.twitter.consumerKey, + consumerSecret: config.twitter.consumerSecret, + callbackURL: config.domain + config.twitter.callbackPath +}, callback)); +//github +passport.use(new GithubStrategy({ + clientID: config.github.clientID, + clientSecret: config.github.clientSecret, + callbackURL: config.domain + config.github.callbackPath +}, callback)); +//dropbox +passport.use(new DropboxStrategy({ + clientID: config.dropbox.clientID, + clientSecret: config.dropbox.clientSecret, + callbackURL: config.domain + config.dropbox.callbackPath +}, callback)); \ No newline at end of file -- cgit v1.2.3