Skip to content Skip to sidebar Skip to footer

Node.js: Oauth2strategy Requires A Clientid Option

I am setuping the MERN stack project, which was created by another developer and I am getting the error: node_modules/passport-oauth2/lib/strategy.js:82 [0] if (!options.clientID

Solution 1:

For me, I did something like this

passport.use(
    new FacebookStrategy(
        {
            clientID: config.FACEBOOK_APP_ID,
            clientSecret: config.FACEBOOK_CONSUMER_SECRET,
            callbackURL: config.FACEBOOK_REDIRECT_URL,
            profileFields: ['id', 'displayName', 'email']
        },

But I forgot to add my FACEBOOK_APP_ID in my config file. Just make sure that your clientId being passed is not null or undefined

Solution 2:

Be sure to npm install dotenv, and add require('dotenv').config(); to the top of your app.js file.

Solution 3:

Be sure to npm install dotenv, and add require('dotenv').config(); to the top of your app.js file.

While the answer from @ColsonRice wasn't exactly the reason I received the above error OAuth2Strategy requires a clientID option, it did point me in the right direction. In trying to get my Typescript version of my NodeJs express server working on Heroku I had changed (10 commits back), my package.json start script from

"start":"node -r dotenv/config ./dist/index.js",

to

"start":"node dist/index.js",

Change the development start up to use an alternative start command with the dotenv/config option back in resolved my issue. The last 4 lines of my scripts section of package.json are as follows:

"dev":"nodemon --exec npm run restart","restart":"rimraf dist && npm run build && npm run devstart","devstart":"node -r dotenv/config ./dist/index.js","start":"node dist/index.js",

So for me, the negative score for Colson is unjustified as it indirectly helped me resolve my issue.

Solution 4:

The Problem is config.FACEBOOK_CLIENT_ID instead of config.FACEBOOK_APP_ID

Error Strategy:

passport.use(
    new FacebookStrategy(
        {
            clientID: config.FACEBOOK_CLIENT_ID,
            clientSecret: config.FACEBOOK_CONSUMER_SECRET,
            callbackURL: config.FACEBOOK_REDIRECT_URL,
            profileFields: ['id', 'displayName', 'email']
        },

Correct Strategy:

passport.use(
    new FacebookStrategy(
        {
            clientID: config.FACEBOOK_APP_ID,
            clientSecret: config.FACEBOOK_CONSUMER_SECRET,
            callbackURL: config.FACEBOOK_REDIRECT_URL,
            profileFields: ['id', 'displayName', 'email']
        },

Post a Comment for "Node.js: Oauth2strategy Requires A Clientid Option"