Created
January 18, 2015 21:08
-
-
Save mateusvahl/80d0fda929a1bf8e22dd 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
var twitterStrategy = require('passport-twitter').Strategy; | |
var facebookStrategy = require('passport-facebook').Strategy; | |
// Tem que criar um APP no twitter/facebook pra ter a chave publica e a secreta | |
// | |
var config = require('../config/passport'); | |
var twConfig = { | |
consumerKey: config.twitter.key, | |
consumerSecret: config.twitter.secret, | |
callbackURL: '/auth/twitter/callback', | |
passReqToCallback : true | |
}; | |
var fbConfig = { | |
clientID: config.facebook.id, | |
clientSecret: config.facebook.secret, | |
callbackURL: '/auth/facebook/callback', | |
profileFields: ['id'], | |
passReqToCallback : true | |
}; | |
function serializeUser(user, done) { | |
done(null, user); | |
} | |
function deserializeUser(obj, done) { | |
done(null, obj); | |
} | |
function afterAuthFacebook(req, accessToken, tokenSecret, profile, done) { | |
// Salvando a chave na sessão | |
req.session.facebookToken = accessToken; | |
done(null, profile); | |
} | |
function afterAuthTwitter(req, accessToken, tokenSecret, profile, done) { | |
// Salvando as chaves na sessão | |
req.session.twitterToken = accessToken; | |
req.session.twitterTokenSecret = tokenSecret; | |
// Twitter responde com nome do usr e oturas coisas se quiser salvar na sessão | |
req.session.userName = profile.displayName; | |
req.session.userPhoto = JSON.parse(profile._raw).profile_image_url; | |
done(null, profile); | |
} | |
/** | |
* exports | |
*/ | |
module.exports = function(passport) { | |
passport.serializeUser(serializeUser); | |
passport.deserializeUser(deserializeUser); | |
passport.use('twitter', new twitterStrategy(twConfig, afterAuthTwitter)); | |
passport.use('facebook', new facebookStrategy(fbConfig, afterAuthFacebook)); | |
}; |
Author
mateusvahl
commented
Jan 18, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment