problem in sign in with LinkedIn in angular and node (using passportjs)

1.1k Views Asked by At

I am having problem in logging in with LinkedIn, both in angular front-end and on node side using passport js. I guess It might be due to change in policy of LinkedIn after 1st march. i have following three files

Server file

app.set('view engine', 'ejs');
// initialize passport
app.use(passport.initialize());
app.use(passport.session());

 // set up routes
 app.use('/auth', authRoutes);
 app.use('/profile', profileRoutes);

  // create home route 
  app.get('/', (req, res) => {
   res.render('home');
   });

  app.listen(3000, () => {
    console.log('app now listening for requests on port 3000'); 
  });

Routes file

 const router = require('express').Router();
 const passport = require('passport');

 // auth login
 router.get('/login', (req, res) => {
 res.render('login', { user: req.user });
 });

 // auth logout
 router.get('/logout', (req, res) => {
 // handle with passport
 res.send('logging out');
 });

router.get('/google',
 passport.authenticate('linkedin'),
   function(req, res){
 // The request will be redirected to LinkedIn for authentication, so this
 // function will not be called.
 });

  router.get('/linkedin/callback', passport.authenticate('linkedin'), (req, 
 res) => {
 res.send(req.user);
// res.redirect('/profile');
});
module.exports = router;

Paasport setup file

 const passport = require('passport');
 const LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;
 passport.use(new LinkedInStrategy({
          clientID: LINKEDIN_CLIENT_ID,
         clientSecret: LINKEDIN_CLIENT_SECRET,
         callbackURL: "http://localhost:3000/auth/linkedin/callback",
         scope: ['r_emailaddress','r_liteprofile'],
 }, function(accessToken, refreshToken, profile, done) {
 // asynchronous verification, for effect...
 process.nextTick(function () {
 return done(null, profile);
   });
 }));
0

There are 0 best solutions below