Full-Stack Web Development with Vue.js and Node

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

Passport's Facebook Strategy


Passport's Facebook Strategy is easy to integrate. As always, let's start with the installation
of this strategy.


Installing Passport's Facebook Strategy


We can install passport's Facebook Strategy by running the following command:


$ npm install passport-facebook --save

The following code should add the package to your package.json file:


"node-sass": "^4.7.2",
"nodemon": "^1.14.10",
"passport": "^0.4.0",
"passport-facebook": "^2.1.1",

Configuring Passport's Facebook Strategy


There are a few steps to configure the Passport's Facebook Strategy. We will discuss each
step in detail:



  1. Create and set up a Facebook app. This will provide us with an App ID and an
    App Secret.


Adding a button to our login page that allows users to log in via Twitter [ vi ]



  1. Add the necessary routes for Facebook authentication.

  2. Add a middleware method to check whether authentication is successful.


Let's dive into the details for each of the preceding steps.


Creating and setting up a Facebook app


To be able to use the Facebook Strategy, you have to build a Facebook application first. The


developers, portal for Facebook is at https:/​/​developers.​facebook.​com/​.

Free download pdf