---
###
- Created a LinkedIn app in the LinkedIn Developer Portal
- Set the correct OAuth redirect URI
- Requested the following scopes: `r_liteprofile`, `r_emailaddress`
- Using Passport.js with `passport-linkedin-oauth2`
---
###
After the LinkedIn login, I expected the user profile and email to be returned successfully.
---
###
The login fails with the above error.
---
passport.use('linkedin-employee', new LinkedInStrategy({
clientID: process.env.LINKEDIN_CLIENT_ID,
clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
callbackURL: process.env.LINKEDIN_CALLBACK_URL,
scope: ['r_emailaddress', 'r_liteprofile'],
state: true,
passReqToCallback: true
},
async function (req, accessToken, refreshToken, profile, done) {
try {
const email = profile.emails?.[0]?.value;
const image = profile.photos?.[0]?.value;
let user = await User.findOne({ email });
if (!user) {
user = await User.create({
linkedinId: profile.id,
name: profile.displayName,
image: image || '',
email: email,
linkedinAuthCode: req.query.code,
social_login: '1',
status: 'active',
is_verify: 'true',
});
}
return done(null, user);
} catch (error) {
return done(error, null);
}
}));
router.get('/linkedin/callback', passport.authenticate('linkedin-employee', {
session: false,
failureRedirect: 'http://localhost:6600/login?error=linkedin'
}), async (req, res) => {
const token = generateToken(req.user);
await User.findByIdAndUpdate(req.user._id, { token });
res.redirect(`http://localhost:6600/auth/social-login ... ee/${token}`);
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... assport-js