title: Passport.js: Sign in with Github and return email address
body: <p>I have built a node.js web app that uses <code>passport.js</code> with the <code>passport-github</code> strategy. Here is my code:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  app.use(express.static('public'));
  var passport = require('passport');
  var GithubStrategy = require('passport-github').Strategy;
  passport.use(new GithubStrategy({
      clientID: "foo",
      clientSecret: "bar",
      callbackURL: "baz",
      profileFields: ['email']
  }, function(accessToken, refreshToken, profile, done) {
      return done(null, profile);
  }));
  passport.serializeUser(function(user, done) {
      done(null, user);
  });
  passport.deserializeUser(function(user, done) {
      done(null, user);
  });
  app.use(session({
      secret: 'this is a secret',
      resave: false,
      saveUninitialized: true
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.set('view engine', 'ejs');
  app.get('/', function(req, res) {
      html = JSON.stringify(req.user, null, 4);
      res.render('index', {
          title: 'My Home Page',
          html: html
      });
  });
  //Login
  app.get('/login', function(req, res) {
      res.render('login', {
          title: 'Login to Chordscribble!'
      });
  });
  //Logout
  app.get('/logout', function(req, res) {
      req.logout();
      res.redirect('/');
  });
  // GitHub
  app.get('/auth/github', passport.authenticate('github', {
      scope: ['user:email']
  }));
  app.get('/auth/github/callback', passport.authenticate('github', {
      failureRedirect: '/login'
  }), function(req, res) {
      res.redirect('/');
  });
  app.listen(3000);
  </code></pre>
  
  <p>Everything is working fine except that I am getting a return value of <code>null</code> for the email address. My first question is, is there a way to guarantee that I will always get an email address? And, my second question is, if not, what how should I store this in a database without an email address? Possibly by assigning my own user id field and using their Github ID? Is the GitHub ID always going to be unique?</p>