help
help copied to clipboard
TypeError: OAuth2Strategy requires a clientID option
- 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.
As the error says, you need to add clientID
to the options object.
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); } } ));
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.
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.
Since the check
if(!options.clientID)
fails, it means thatkeys.facebookClientAppID
is not a valid ID (it is probablyundefined
ornull
). Try toconsole.log
thekeys.facebookClientAppID
right before thenew FacebookStrategy
call.
i am having same proble while i am uploading my app to heroku but in localhost it is working properly
@Mharshdeep You might find error while deploying your app because you did not add your key value pair on heroku.
@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
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 .
@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
Might also not work if you didn't configure dotenv package at the top of your file
require('dotenv').config() const dotenv=require('dotenv');
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?
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:
- Login to your Heroku account.
- Under the personal tab, click the current application you are working on. 3.Go to settings.
- 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).
- Save the values.
- Good to go. Redeploy your application.
Hope it helps!
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
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:
- Login to your Heroku account.
- Under the personal tab, click the current application you are working on. 3.Go to settings.
- 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).
- Save the values.
- 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!
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:
- Login to your Heroku account.
- Under the personal tab, click the current application you are working on. 3.Go to settings.
- 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).
- Save the values.
- Good to go. Redeploy your application.
Hope it helps!
You saved my life
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:
- Login to your Heroku account.
- Under the personal tab, click the current application you are working on. 3.Go to settings.
- 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).
- Save the values.
- Good to go. Redeploy your application.
Hope it helps!
Didn't save my life, but made my day a hell of a lot better!
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
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!!!
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
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.
I'm getting the same problem, there's no typo everything is correct
@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.
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: @.***>
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
Three steps to take important while solving this error.
- install dotenv (npm i dotenv)
- require it at the top of your app. require('dotenv').config()
- 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 '='
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.
Despite the conversation around this issue, it doesn't seem to be an issue with Node itself.
@RedYetiDev This is the help repo.
Yes, but as fair as I can tell, this is an issue with passport, or some other dependency in uae, and not node.js