title: From facebook token to jwt token
body: <p>I'm using the passport module to authenticate a user and generate a jwt token.</p>
  
  <p>Now I want to make facebook login possible. I'm in the phase that I get a fb token and facebook id.</p>
  
  <p>What am I supposed to do with this info? Currently I make a new user that has a variable with facebook id but without a password.</p>
  
  <p>Without a password I can't generate a jwt token, thus I cannot login.</p>
  
  <p>How does this work?</p>
  
  <p>My front end is angular and my API is written with nodejs, express &amp; mongoose.</p>
  
  <p>Passport code:</p>
  
  <pre><code>passport.use(new LocalStrategy(
      function(username, password, done) {
          User.findOne({ username: username }, function (err, user) {
              if (err) { return done(err); }
              if (!user) {
                  return done(null, false, { message: 'Incorrect username.' });
              }
              if (!user.validPassword(password)) {
                  return done(null, false, { message: 'Incorrect password.' });
              }
              return done(null, user);
          });
      }
  ));
  </code></pre>
  
  <p>generatejwt code:</p>
  
  <pre><code>UserSchema.methods.generateJWT = function() {
  
      // set expiration to 60 days
      var today = new Date();
      var exp = new Date(today);
      exp.setDate(today.getDate() + 60);
  
      return jwt.sign({
          _id: this._id,
          username: this.username,
          exp: parseInt(exp.getTime() / 1000),
      }, 'SECRET');
  };
  </code></pre>