Linkedin Login nodejs

Hello guys, we had working nodejs code for linkedin social login.
With this latest updates we cant solve this code to work and this is our current nodejs code:

passport.use(
  new linkedinStrategy(
    {
      clientID: process.env.LINKEDIN_CLIENT_ID,
      clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
      callbackURL: 'http://localhost:5000/server/api/users/linkedin/callback',
      scope: ['openid', 'profile', 'email']
    },
    async (accessToken, refreshToken, done) => {
      try {
        const userInfo = await linkedin.getProfile(
          process.env.LINKEDIN_CLIENT_ID,
          process.env.LINKEDIN_CLIENT_SECRET,
          accessToken
        );

        console.log(userInfo)
        
        let existingUser = await User.findOne({ email: userInfo.email });

        if (existingUser) {
          return done(null, existingUser);
        }

        const newUser = new User({
          name: userInfo.name,
          email: userInfo.email,
          accessToken: accessToken,
          refreshToken: refreshToken,
          type: 'linkedin'
        });

        await newUser.save();

        done(null, newUser);
      } catch (err) {
        console.log(err)
        done(err, false);
      }
    }
  )
);

In previous code we had using like r_liteprofile and r_emailaddress and this was succesfully worked. Now we created new app before a couple of days and we cant solve this problem.

Is there any help to solve this? Current error is: {“message”:“failed to fetch user profile”}

2 Likes

use “npm install github:auth0/passport-linkedin-oauth2”,Currently the version of passport-linkedin-oauth2 is 2.0.0 which isn’t up to date. but here Im facing another issue im getting all the details from LinkedIn displayname,email,profile picture,provider and id and saving those details in database but my passport.serializeUser and passport.deserializeUser function is not working I’m not able to initialize values in the
session