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