简体   繁体   中英

passport-linkedin callback does not work

I'm using passport-linkedin to integrate LinkedIn account in my project. Problem is when linkedin email does not found in my database, I need to display linkedin account information in callback function.

passport.js

passport.use(new LinkedInStrategy({
    consumerKey: '12121',
    consumerSecret: '1212121',
    callbackURL: "/auth/linkedin/callback",
    profileFields: ['id', 'first-name', 'last-name', 'email-address', 'headline']
  },
  function(token, tokenSecret, profile, done) {
        auth.findOne({ username: profile.emails[0].value }).then(function (err, user) {
            if (!user) {
                return done(null, profile);
            } else {
                return done(null, user);
            }
        }, function (err) {
            return done(err, null);
        })
    }
));

routes.js

app.get('/auth/linkedin/callback', 
    passport.authenticate('linkedin', { failureRedirect: '/login' }),
        function(req, res) {
        winston.error('linkedInfo: %s', req);
        res.redirect('/');
  });

In routes.js, I want to display all of json data from LinkedIn. But nothing display as not working at all.

One thing to check would be ensuring that you are requesting the r_basicprofile and r_emailaddress member permissions during the OAuth process, if you want to return a member's email address.

The entire call could be failing (and obscured to you via the Passport layer) as a result of you not having the necessary permissions to request all of the fields you are asking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM