Created
March 11, 2013 17:01
-
-
Save mikaa123/5135712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from http://passportjs.org | |
var passport = require('passport') | |
// Each authentication mechanism is provided as an npm package. | |
// These packages expose a Strategy object. | |
, LocalStrategy = require('passport-local').Strategy | |
, FacebookStrategy = require('passport-facebook').Strategy; | |
// Passport can be instanciated using any Strategy. | |
passport.use(new LocalStrategy( | |
function(username, password, done) { | |
User.findOne({ username: username }, function (err, user) { | |
if (err) { return done(err); } | |
if (!user) { | |
return done(null, false, { message: 'Incorrect username.' }); | |
} | |
if (!user.validPassword(password)) { | |
return done(null, false, { message: 'Incorrect password.' }); | |
} | |
return done(null, user); | |
}); | |
} | |
)); | |
// In this case, we instanciate a Facebook Strategy | |
passport.use(new FacebookStrategy({ | |
clientID: FACEBOOK_APP_ID, | |
clientSecret: FACEBOOK_APP_SECRET, | |
callbackURL: "http://www.example.com/auth/facebook/callback" | |
}, | |
function(accessToken, refreshToken, profile, done) { | |
User.findOrCreate(..., function(err, user) { | |
if (err) { return done(err); } | |
done(null, user); | |
}); | |
} | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment