title: Error: invalid_request Missing required parameter: scope (Restify & Passportjs w/ Google OAuth2)
body: <p>So, I've run into a problem with my Node.js app, using Restify and Passportjs (Google OAuth2 strategy). When I use <code>passport.authenticate()</code>, it gives me the following error:</p>
  
  <blockquote>
    <p>400. That’s an error.<br>
    Error: invalid_request<br>
    Missing required parameter: scope</p>
  </blockquote>
  
  <p>I found another question about the same thing from a couple of years ago (<a href="https://stackoverflow.com/questions/34931847/invalid-request-with-missing-scope-using-google-passportjs-on-google-oauth2?newreg=02cf8c8315244b2e8b2a1aefcb4ebc3a">invalid_request with missing: scope using Google Passportjs on Google Oauth2</a>). The author said he finally fixed it himself but didn't post the fix.</p>
  
  <p>Has anyone else run into this and been able to fix it? I can't figure it out. Here is my code:</p>
  
  <p><strong>authController.js</strong></p>
  
  <pre><code>var passport = require('passport');
  var GoogleStrategy = require('passport-google-oauth20').Strategy;
  
  var auth = {
    google: {
      clientID: '&lt;ID&gt;',
      clientSecret: '&lt;SECRET&gt;',
      callbackURL: 'https://localhost:8080/auth/google/return',
      scope: ['profile', 'email']
    }
  };
  
  passport.use(new GoogleStrategy({
      clientID: auth.google.clientID,
      clientSecret: auth.google.clientSecret,
      callbackURL: auth.google.callbackURL
  }, function(accessToken, refreshToken, profile, cb) {
    return cb(null, profile.id);
  }));
  
  module.exports.authenticate = passport.authenticate('google', { scope: auth.google.scope });
  module.exports.isAuthenticated = passport.authenticate('google', { successRedirect: '/hello/succeed', failureRedirect: '/hello/fail' });
  </code></pre>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>var restify = require('restify'),
      fs = require('fs'),
      bodyParser = require('body-parser'),
      authController = require('./controllers/authController');
  
  // Placeholder handler.
  function respond(req, res, next) {
    res.send('hello ' + req.params.name);
    return next();
  }
  
  // Create server.
  var api = restify.createServer({
    certificate: fs.readFileSync('server.crt'),
    key: fs.readFileSync('server.key'),
    name: 'BQ:IQ Question Writer'
  });
  
  // Setup authentication
  api.get('/auth/google', authController.authenticate);
  api.get('/auth/google/return', authController.isAuthenticated);
  
  // Setup routes.
  api.get('/hello/:name', respond);
  api.head('/hello/:name', respond);
  
  api.listen(8080, function() {
    console.log('%s listening at %s', api.name, api.url);
  });
  </code></pre>