Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
CastError: Cast to ObjectId failed for value "XXXXXXXXXX" (type string) at path "_id" for model "User" for passport-linkedin-oauth2

Getting the above error when trying to authenticate a new user using LinkedIn's oAuth 2.0. It looks like I'm getting passed a 10 digit ObjectId instead of a 12 or 24 character id...

passport.use(new LinkedInStrategy({
  clientID: process.env.LI_ID,
  clientSecret: process.env.LI_SECRET,
  callbackURL: "http://localhost:3000/auth/linkedin/think-it",
  scope: ['r_emailaddress', 'r_liteprofile'],
  state: true
}, function(accessToken, refreshToken, profile, done) {
  // asynchronous verification, for effect...
  process.nextTick(function () {
    // To keep the example simple, the user's LinkedIn profile is returned to
    // represent the logged-in user. In a typical application, you would want
    // to associate the LinkedIn account with a user record in your database,
    // and return that user instead.
    return done(null, profile);
  });
}));

I'm getting hung up at:

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolved. I was not returning a user from my DB. From the code above:

...function(accessToken, refreshToken, profile, done) {
  // asynchronous verification, for effect...
  process.nextTick(function () {
    //code below was not present when I was getting the error:
    User.findOrCreate({ linkedInId: profile.id}, function(err, user) {
          if (err) { return done(err); }
          done(null, user);
        });
  });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!