Full-Stack Web Development with Vue.js and Node

(singke) #1
Building OAuth Strategies with passport.js Chapter 7

The preceding code will add a LOGIN WITH FACEBOOK button:


Adding configurations for Facebook app


Let's configure the Facebook Strategy just as we did for the local strategy. We will create a
separate file to handle Facebook login so that the code is simpler. Let's create a file called


facebook.js inside the controllers folder and add the following contents to it:


const User = require('../models/User.js');
const passport = require('passport');
const config = require('./../config/Config');
const Strategy = require('passport-facebook').Strategy;

module.exports.controller = (app) => {
// facebook strategy
passport.use(new Strategy({
clientID: config.FACEBOOK_APP_ID,
clientSecret: config.FACEBOOK_APP_SECRET,
callbackURL: '/login/facebook/return',
profileFields: ['id', 'displayName', 'email']
},
(accessToken, refreshToken, profile, cb) => {
Free download pdf