JavaScript GitHub Authentication

Nicholas Noochla-or
Nicholas Noochla-or
979 Points

OAuth2Strategy requires a clientID option

I could use some help with this github authentication. I have run a variety of these commands.

SET GITHUB_CLIENT_ID=MYID & GITHUB_CLIENT_SECRET=MYSECRET & npm start

SET GITHUB_CLIENT_ID=MYID & GITHUB_CLIENT_SECRET=MYSECRET & node ./bin/www

C:\Users\Nicholas\repos\passport\OAuthAllSteps\Project\05_inClass\node_modules\passport-oauth2\lib\strategy.js:82
  if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); }
                           ^

TypeError: OAuth2Strategy requires a clientID option

this is how I have defined the options in my app.js file clientID: process.env.GITHUB_CLIENT_ID, clientSecret: process.env.GITHUB_CLIENT_SECRET,

How would I pass in the clientID option? I am not sure what it is asking of me.

2 Answers

Adam Fields
Adam Fields
31,171 Points

At first glance, it looks like you're adding your environmental variables and starting the app concurrently, which is probably not what you want to do.

& - run all scripts concurrently

&& - run scripts sequentially (the next script won't run until the preceding script finishes)

When setting environmental variables, you typical don't use either & or &&. For example:

NODE_ENV=production node app.js

Regardless of sequential vs parallel execution, the best practice is to use the tiny npm package dotenv.

Simply require it at the top of your app.js:

require('dotenv').config();

And create a .env file in the root of your project (important: make sure you add to your .gitignore):

GITHUB_CLIENT_ID=whatever
GITHUB_CLIENT_SECRET=whatever
Michael Lau
PRO
Michael Lau
Pro Student 25,137 Points

Make sure that you are typing "clientID", not "clientId". That's my mistake in my case. XD