Full-Stack Web Development with Vue.js and Node

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

The preceding command should add the package to your package.json file:


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

Configuring Passport's Twitter Strategy


Just like Facebook Strategy, we have to perform the following steps to configure passport's
Twitter Strategy:



  1. Creating and setting up a Twitter application. This will provide us with a
    consumer key (API Key) and a consumer secret (API Secret).

  2. Adding a button to our login page that allows our users to LOGIN WITH
    TWITTER.

  3. Adding the necessary routes.

  4. Adding a middleware method to check authentication.

  5. Redirecting the user to the home page after redirection and displaying the
    logged-in user's email in the top bar.


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


Creating and setting up a Twitter app


Just as with Facebook Strategy, to be able to use the Twitter Strategy, we have to build a


Twitter application as well. The developers' portal for Twitter is at https:/​/​apps.​twitter.


com/​, where you will see a list of all of your applications. If this is new, you will see a


button to create a new application—click on Create your Twitter application.

Free download pdf