Full-Stack Web Development with Vue.js and Node

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

app.get('/login/google/return',
passport.authenticate('google', { failureRedirect: '/login' }),
(req, res) => {
res.redirect('/');
});
};

Passport's LinkedIn strategy


By now, you must understand quite well how to use each of the strategies provided by


passport.js. Let's quickly revise these using the LinkedIn strategy. This is the last


strategy we will be covering in this book. There are several other strategies that you can use


according to your needs. You can find the list at https:/​/​github.​com/​jaredhanson/


passport/​wiki/​Strategies.


Now, let's start with the installation of this strategy.


Installing Passport's LinkedIn strategy


Run the following command to install the LinkedIn strategy:


$ npm install passport-linkedin --save

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


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

Configuring Passport's LinkedIn strategy


The configuration for all the strategies is somewhat similar. So, the following are the steps


we have to follow to configure this strategy:



  1. Creating and registering an application on LinkedIn. 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 users to log in via LinkedIn.

Free download pdf