Created
October 13, 2015 18:44
-
-
Save jrobber/ba9748f3ecb0a5ba7566 to your computer and use it in GitHub Desktop.
facebook passport example
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
config.js |
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
var config = { | |
appId: 'facebookAppIdGoesHere', | |
appSecret: 'facebookAppSecretGoesHere' | |
} | |
module.exports = config; |
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
var express = require('express'); | |
var session = require('express-session'); | |
var passport = require('passport'); | |
var config = require('./config.js'); | |
var FacebookStrategy = require('passport-facebook').Strategy; | |
var app = express(); | |
app.use(session({secret: 'I just cant even'})); | |
app.use(passport.initialize()); | |
app.use(passport.session()); | |
passport.use(new FacebookStrategy({ | |
clientID: config.appId, | |
clientSecret: config.appSecret, | |
callbackURL: 'http://localhost:3000/auth/facebook/callback' | |
}, function(token, refreshToken, profile, done) { | |
return done(null, profile); | |
})); | |
//app.get | |
app.get('/auth/facebook/', passport.authenticate('facebook')); | |
app.get('/auth/facebook/callback', passport.authenticate('facebook', { | |
successRedirect: '/me', | |
failureRedirect: '/login' | |
}), function(req, res) { | |
console.log(req.session); | |
}); | |
app.get('/new', function(req, res){ | |
res.send("Winning") | |
}); | |
passport.serializeUser(function(user, done) { | |
done(null, user); | |
}); | |
passport.deserializeUser(function(obj, done) { | |
done(null, obj); | |
}); | |
app.get('/me', function(req, res){ | |
res.send(req.user); | |
}); | |
app.listen(3000, function(){ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment