help icon indicating copy to clipboard operation
help copied to clipboard

TypeError: OAuth2Strategy requires a clientID option

Open saamsam opened this issue 4 years ago • 25 comments

  • Node.js Version: v13.5.0
  • OS: windosws 10
  • Scope (install, code, runtime, meta, other?): code, other
  • Module (and version) (if relevant): ???

I'm implementing Passport for oauth within my nodeJs application, I keep getting below error when I added facebook oauth to the google I already implemented, the google oauth is working fine. Here are the modules version related to this issue: "nodemon": "^2.0.2", "passport": "^0.4.1", "passport-facebook": "^3.0.0", "passport-google-oauth20": "^2.0.0", "passport-twitter": "^1.0.4",

here is the stack trace of the error: C:\codebase\emailApp\server\node_modules\passport-oauth2\lib\strategy.js:86 [0] if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); } [0] ^ [0] [0] TypeError: OAuth2Strategy requires a clientID option [0] at Strategy.OAuth2Strategy (C:\codebase\emailApp\server\node_modules\passport-oauth2\lib\strategy.js:86:34) [0] at new Strategy (C:\codebase\emailApp\server\node_modules\passport-facebook\lib\strategy.js:56:18) [0] at Object. (C:\codebase\emailApp\server\services\passport.js:38:3) at Module._compile (internal/modules/cjs/loader.js:1139:30) [0] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10) [0] at Module.load (internal/modules/cjs/loader.js:988:32) at Function.Module._load (internal/modules/cjs/loader.js:896:14) [0] at Module.require (internal/modules/cjs/loader.js:1028:19) [0] at require (internal/modules/cjs/helpers.js:72:18) at Object. (C:\codebase\emailApp\server\index.js:9:1) [0] at Module._compile (internal/modules/cjs/loader.js:1139:30) [0] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10) [0] at Module.load (internal/modules/cjs/loader.js:988:32) at Function.Module._load (internal/modules/cjs/loader.js:896:14) [0] at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) [0] at internal/main/run_main_module.js:17:47

saamsam avatar Mar 22 '20 16:03 saamsam

As the error says, you need to add clientID to the options object.

Hakerh400 avatar Mar 22 '20 17:03 Hakerh400

of course I pass the clientID to the object. Like I said earlier the google one is working fine..... Here is the code for the facebook one. passport.use( new FacebookStrategy({ clientID: keys.facebookClientAppID, clientSecret: keys.facebookClientSecret, callbackURL: '/auth/facebook/callback', proxy: true }, async (accessToken, refreshToken, profile, done) => { console.log(accessToken); const existingUser = await User.findOne({facebookId: profile.id}); if(existingUser){ done(null, existingUser); } else { const user = await new User({facebookId: profile.id}).save() done(null, user); } } ));

saamsam avatar Mar 22 '20 21:03 saamsam

Since the check if(!options.clientID) fails, it means that keys.facebookClientAppID is not a valid ID (it is probably undefined or null). Try to console.log the keys.facebookClientAppID right before the new FacebookStrategy call.

Hakerh400 avatar Mar 23 '20 00:03 Hakerh400

Thanks, that's it, there was typo error in my clientID variable, musch appreciated. Still not working, will spend more time with it. Sorry, I'm new to JavaScripte, and NodeJS.

saamsam avatar Mar 23 '20 01:03 saamsam

Since the check if(!options.clientID) fails, it means that keys.facebookClientAppID is not a valid ID (it is probably undefined or null). Try to console.log the keys.facebookClientAppID right before the new FacebookStrategy call.

i am having same proble while i am uploading my app to heroku but in localhost it is working properly

Mharshdeep avatar Apr 11 '20 06:04 Mharshdeep

@Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.

samandeepdhindsa18 avatar Jun 29 '20 14:06 samandeepdhindsa18

@Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.

Thank you for your help yes this was the problem i figured it out

Mharshdeep avatar Jun 29 '20 14:06 Mharshdeep

I am glad that it works for u .

I just post it there because it may help others like us.

Cheers! Saman

On Monday, June 29, 2020, Mharshdeep [email protected] wrote:

@Mharshdeep https://github.com/Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.

Thank you for your help yes this was the problem i figured it out

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nodejs/help/issues/2544#issuecomment-651165674, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMKMUJV7X2ZPUDZXCYM4WDRZCRZHANCNFSM4LRLO72Q .

samandeepdhindsa18 avatar Jun 29 '20 16:06 samandeepdhindsa18

@Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.

Hello. I'm getting same Error while deploying my website, how and where can I add the key value pair

bobbysingh17 avatar Jul 12 '20 00:07 bobbysingh17

Might also not work if you didn't configure dotenv package at the top of your file

require('dotenv').config() const dotenv=require('dotenv');

anu10943 avatar Jul 18 '20 07:07 anu10943

Might also not work if you didn't configure dotenv package at the top of your file

require('dotenv').config() const dotenv=require('dotenv');

I was doing this mistake, now it's working from local. But when I deploy in Heroku, it's showing the same error. What I have to do in this case?

gaganshrivastava avatar Aug 05 '20 20:08 gaganshrivastava

Hi, If code works fine locally, it means it works in dev

environment as you mention key-value pair in some config file.

However, to make it work for production environment you need to update the key value pair on your Heroku account.

Steps to follow:

  1. Login to your Heroku account.
  2. Under the personal tab, click the current application you are working on. 3.Go to settings.
  3. Select "Reveal Config vars". 5.Add all the key-value pairs as you entered for your local environment. However, the values would be different for prod environment. (Attached is the screenshot: https://user-images.githubusercontent.com/47752785/89522338-0d438980-d7af-11ea-8d95-ca25a5642afa.png).
  4. Save the values.
  5. Good to go. Redeploy your application.

Hope it helps!

samandeepdhindsa18 avatar Aug 06 '20 10:08 samandeepdhindsa18

create an .env file same as in editor in your app ls in ubuntu it did work for me good luck. make sure is a file not a directory

pascualmcruz avatar Sep 05 '20 16:09 pascualmcruz

Hi, If code works fine locally, it means it works in dev

environment as you mention key-value pair in some config file.

However, to make it work for production environment you need to update the key value pair on your Heroku account.

Steps to follow:

  1. Login to your Heroku account.
  2. Under the personal tab, click the current application you are working on. 3.Go to settings.
  3. Select "Reveal Config vars". 5.Add all the key-value pairs as you entered for your local environment. However, the values would be different for prod environment. (Attached is the screenshot: https://user-images.githubusercontent.com/47752785/89522338-0d438980-d7af-11ea-8d95-ca25a5642afa.png).
  4. Save the values.
  5. Good to go. Redeploy your application.

Hope it helps!

Thank you very much, took me couple of hours of app not working before your post helped me!

MishkaZi avatar Sep 07 '20 09:09 MishkaZi

Hi, If code works fine locally, it means it works in dev

environment as you mention key-value pair in some config file.

However, to make it work for production environment you need to update the key value pair on your Heroku account.

Steps to follow:

  1. Login to your Heroku account.
  2. Under the personal tab, click the current application you are working on. 3.Go to settings.
  3. Select "Reveal Config vars". 5.Add all the key-value pairs as you entered for your local environment. However, the values would be different for prod environment. (Attached is the screenshot: https://user-images.githubusercontent.com/47752785/89522338-0d438980-d7af-11ea-8d95-ca25a5642afa.png).
  4. Save the values.
  5. Good to go. Redeploy your application.

Hope it helps!

You saved my life

viveknotimeojha avatar Sep 18 '20 10:09 viveknotimeojha

Hi, If code works fine locally, it means it works in dev

environment as you mention key-value pair in some config file.

However, to make it work for production environment you need to update the key value pair on your Heroku account.

Steps to follow:

  1. Login to your Heroku account.
  2. Under the personal tab, click the current application you are working on. 3.Go to settings.
  3. Select "Reveal Config vars". 5.Add all the key-value pairs as you entered for your local environment. However, the values would be different for prod environment. (Attached is the screenshot: https://user-images.githubusercontent.com/47752785/89522338-0d438980-d7af-11ea-8d95-ca25a5642afa.png).
  4. Save the values.
  5. Good to go. Redeploy your application.

Hope it helps!

Didn't save my life, but made my day a hell of a lot better!

y2katie avatar Sep 21 '20 19:09 y2katie

Hi, If code works fine locally, it means it works in dev

environment as you mention key-value pair in some config file.

However, to make it work for production environment you need to update the key value pair on your Heroku account.

Steps to follow:

1. Login to your Heroku account.

2. Under the personal tab, click the current application you are working on.
   3.Go to settings.

3. Select "Reveal Config vars".
   5.Add all the key-value pairs as you entered for your local environment. However, the values would be different for prod environment. (Attached is the screenshot: https://user-images.githubusercontent.com/47752785/89522338-0d438980-d7af-11ea-8d95-ca25a5642afa.png).

4. Save the values.

5. Good to go.  Redeploy your application.

Hope it helps!

You are the GOAT

Cubas93 avatar Mar 10 '21 00:03 Cubas93

Hi, If code works fine locally, it means it works in dev

environment as you mention key-value pair in some config file.

However, to make it work for production environment you need to update the key value pair on your Heroku account.

Steps to follow:

1. Login to your Heroku account.

2. Under the personal tab, click the current application you are working on.
   3.Go to settings.

3. Select "Reveal Config vars".
   5.Add all the key-value pairs as you entered for your local environment. However, the values would be different for prod environment. (Attached is the screenshot: https://user-images.githubusercontent.com/47752785/89522338-0d438980-d7af-11ea-8d95-ca25a5642afa.png).

4. Save the values.

5. Good to go.  Redeploy your application.

Hope it helps!

Really thanks, man. Saved my day!!!

ArmandoTargino avatar Mar 17 '21 23:03 ArmandoTargino

Might also not work if you didn't configure dotenv package at the top of your file

require('dotenv').config() const dotenv=require('dotenv');

Why would you need a const for dotenv? It doesn't make any sense

Luvous avatar Nov 29 '21 23:11 Luvous

Here's an idea - why not just keep it moving rather than being a smug jackass? How's that for things that don't make any sense :)

On Mon, Nov 29, 2021 at 6:57 PM Thomas Varela @.***> wrote:

Might also not work if you didn't configure dotenv package at the top of your file

require('dotenv').config() const dotenv=require('dotenv');

Why would you need a const for dotenv? It doesn't make any sense

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nodejs/help/issues/2544#issuecomment-982140410, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7WYYSOGG4PHE5GVCHVGQTUOQHNBANCNFSM4LRLO72Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

y2katie avatar Nov 30 '21 00:11 y2katie

I'm getting the same problem, there's no typo everything is correct

Abbas-Codes avatar Mar 30 '22 16:03 Abbas-Codes

@Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.

Can you please tell me how to add the key value pair on heroku, I'm really facing the issues on it.

pankaj11koundal avatar Apr 15 '22 07:04 pankaj11koundal

Hey Pankaj,

If you read above comments, there are detailed steps how to add these key-value pair on heroku. Hope it helps.

Thanks.

On Fri, Apr 15, 2022 at 3:04 AM Pankaj Singh @.***> wrote:

@Mharshdeep https://github.com/Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.

Can you please tell me how to add the key value pair on heroku, I'm really facing the issues on it.

— Reply to this email directly, view it on GitHub https://github.com/nodejs/help/issues/2544#issuecomment-1099906556, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMKMUKDCZICRLYTNXUY43LVFEIHJANCNFSM4LRLO72Q . You are receiving this because you commented.Message ID: @.***>

samandeepdhindsa18 avatar Apr 15 '22 12:04 samandeepdhindsa18

Here's an idea - why not just keep it moving rather than being a smug jackass? How's that for things that don't make any sense :) On Mon, Nov 29, 2021 at 6:57 PM Thomas Varela @.***> wrote: Might also not work if you didn't configure dotenv package at the top of your file require('dotenv').config() const dotenv=require('dotenv'); Why would you need a const for dotenv? It doesn't make any sense — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2544 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7WYYSOGG4PHE5GVCHVGQTUOQHNBANCNFSM4LRLO72Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Why would you call me jackass? it's just a comment

Luvous avatar Apr 17 '22 17:04 Luvous

Three steps to take important while solving this error.

  1. install dotenv (npm i dotenv)
  2. require it at the top of your app. require('dotenv').config()
  3. your code in the .env file should only contain, the key word in 'CAPITAL letters', 'equal to' and the value. example --- CLIENT_ID=8763756938579285748 Don't mistakenly use ':' instead of '='

etineh avatar Sep 30 '22 14:09 etineh

Recently, I faced the same issue and later I realized that I forgot to require .env configuration. Error TypeError: OAuth2Strategy requires a clientID option Fix npm i dotenv and then require it at the top of your file require(dotenv).config() The issue is caused because your server has no idea that it has to use the environment variable.

Ihtisham-Khattak avatar Apr 27 '23 07:04 Ihtisham-Khattak

Despite the conversation around this issue, it doesn't seem to be an issue with Node itself.

redyetidev avatar Apr 30 '24 23:04 redyetidev

@RedYetiDev This is the help repo.

user7230724 avatar May 01 '24 08:05 user7230724

Yes, but as fair as I can tell, this is an issue with passport, or some other dependency in uae, and not node.js

redyetidev avatar May 01 '24 11:05 redyetidev