'throw new TypeError('OAuth2Strategy requires a clientID option'); }
This is the error coming what to do.I have created a socket.io chat application.
This is a chat application using nodejs.socket.io and with package.json as -
Package.json
"dependencies": {
"body-parser": "~1.15.1",
"connect-flash": "^0.1.1",
"connect-mongo": "^1.3.2",
"cookie-parser": "^1.4.3",
"debug": "~2.3.2",
"escape-html": "^1.0.3",
"express": "~4.14.0",
"express-session": "^1.14.2",
"hbs": "~4.0.0",
"mongoose": "^4.6.8",
"morgan": "~1.7.0",
"passport": "^0.3.2",
"passport-facebook": "^2.1.1",
"passport.socketio": "^3.7.0",
"serve-favicon": "~2.3.0",
"shortid": "^2.2.6",
"socket.io": "^1.5.1",
"twemoji": "^2.2.0"
},
"devDependencies": {
"babel-preset-es2015": "^6.18.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-babel": "^6.1.2",
"gulp-clean-css": "^2.0.13",
"gulp-htmlmin": "^3.0.0",
"gulp-imagemin": "^3.1.1",
"gulp-sass": "*",
"gulp-uglify": "^2.0.0"
}
}
C:\Users\AAKASH\Desktop\Follower-Github\Chat-app-all-F-2\Babble-master\B
abble-master\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
at Strategy.OAuth2Strategy (C:\Users\AAKASH\Desktop\Follower-Github\
Chat-app-all-F-2\Babble-master\Babble-master\node_modules\passport-oauth
2\lib\strategy.js:82:34)
at new Strategy (C:\Users\AAKASH\Desktop\Follower-Github\Chat-app-al
l-F-2\Babble-master\Babble-master\node_modules\passport-facebook\lib\str
ategy.js:54:18)
at Object.<anonymous> (C:\Users\AAKASH\Desktop\Follower-Github\Chat-
app-all-F-2\Babble-master\Babble-master\config\passport.js:11:14)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\AAKASH\Desktop\Follower-Github\Chat-
app-all-F-2\Babble-master\Babble-master\routes\index.js:9:14)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\AAKASH\Desktop\Follower-Github\Chat-
app-all-F-2\Babble-master\Babble-master\app.js:23:16)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additi
onal logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AAKASH\AppData\Roaming\npm-cache\_logs\2018-06-08T
03_18_29_207Z-debug.log
Below is of no use.......
This is the error coming what to do.I have created a socket.io chat application.
This is a chat application using nodejs.socket.io and with package.jsonThis is the error coming what to do.I have created a socket.io chat application.
This is a chat application using nodejs.socket.io and with package.jsonThis is the error coming what to do.I have created a socket.io chat application.
This is a chat application using nodejs.socket.io and with package.json
Solution 1:[1]
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.
Solution 2:[2]
I had the same error yesterday. error was
TypeError: OAuth2Strategy requires a clientID option
I renamed client id as clientID instead of clientId
passport.use(new FacebookStrategy({
clientID: FACEBOOK_CLIENT_ID, // previously was clientId
clientSecret: FACEBOOK_CLIENT_SECRET,
callbackURL: FACEBOOK_CALLBACK_URL,
profileFields: ['id', 'email', 'first_name', 'last_name'],
},
UserControllers.facebookCallback,
));
Solution 3:[3]
I have had a kind of similar scenario with Passport for GoogleOAuth2 with Google. Precisely the same error which eventually turned out to be something trivial. Somewhere in my code, where the portion cliendID keys are inserted, (in my case it was under keys.js) instead of exportS I had a typo - export.
module.exports = require('./something');
Fixing that solved the issue. Hope somebody may find it useful.
Solution 4:[4]
Same thing had happened to me and then I added
require('dotenv').config()
in the header and everything worked.
I read my clientID from .env file.
Solution 5:[5]
I had faced the same problem. Then I save clientId and clientSecret in .env file
GOOGLE_CLIENT_ID = xxxxxxxxxxxxxxxxxx
GOOGLE_CLIENT_SECRET = xxxxxxxxxxxxxxxxxx
passport.js
passport.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: "/auth/google/callback",
},
(accessToken, refreshToken, profile, done) => {
console.log(profile);
done(null, profile);
}
)
);
user.js
router.get('/auth/google',
passport.authenticate('google', { scope: ['profile'] }));
router.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/article');
});
Solution 6:[6]
Please be sure that your app can properly read your "clientID" variable. Try to read your variable "clientID" printing the value to the console. In my case the result was:
console.log(`${clientID}`);
undefined
I forgot to include the module
require('dotenv').config()
So I was not reading the actual clientID value. Hope this could help you.
Solution 7:[7]
Make sure you set up the environment variable properly in your main file. Add this before including the passport.js file in your server or app.js file
require('dotenv').config()
Solution 8:[8]
Apparently this error says, it cannot find the clientID value, which was expected to come from .env definitions.
Working with nodejs and using for equal often : instead of = as expected in .env causes this issue as well.
So ... clientID=12345..... then was Ok for me.
Solution 9:[9]
Your dependencies do not help. You need to post your code where you create your Passport Facebook Strategy object. (I would XXXX out your personal codes/keys/ClientId)
I had this error as well literally just now, which is why I am here on this question. I solved mine, and it may help you to hear how my issue came up.
It is very bad practice to put security codes/keys/whatever in a source code repository exposed to the wild. It is a good practice to keep a file with your codes, and include it with the build as a reference, and use the keys out of it, but not check it in to the repo, but instead manually copy it from development computer to computer. In a much larger environment, you may just have it located on a common network drive instead. Or much more likely have it on a source code repository not hosted in the wild.
In my case, I was hopping from my main dev computer, a laptop, to my much faster desktop. I have not been on the desktop in months, and just did a plain check out then compile/run. I got this error. I had forgotten to copy over the key file to run dev. (Interestingly, I could absolutely run a build and push to live server, since it runs on a prod key file that sits on the server.)
If this is not your specific situation, then you need to either post your code (feel free to PM me if you want) or look at your code on how you are enacting your FacebookStrategy and your problem lies there. You are probably just forgetting to include your Facebook ClientID in the call.
Cheers and good luck!
Solution 10:[10]
Changing consumer to client, solved the issue.
passport.use(
new GoogleStrategy(
{
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://www.example.com/auth/google/callback"
},
function(token, tokenSecret, profile, done) {
authUser(profile, done)
}
)
);
Solution 11:[11]
This error might also occur if you are placing multiple strategies under the same file 'passport.js', try making a different file for different strategies, try this when everything else is fine and the code still doesn't work.
Solution 12:[12]
Steps to follow:
Login to your Heroku account. Under the personal tab, click the current application you are working on.
Go to settings.
Select "Reveal Config vars".
Add all the key-value pairs as you entered for your local environment.
Save the values.
Redeploy your application.
After putting hours finally it helped me.
Solution 13:[13]
Remember to add new Config vars for GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in Heroku or any other providers if you have not. I had this error too and realized I forgot to add new Config vars to Heroku.
Solution 14:[14]
You haven't posted your code along with your error, but as per the error message I am seeing it seems like your code can't properly access the clientID. If you are using storing your clientID in a .env file use the dotenv module and configure it in your file by module require("dotenv").config(). I hope this will solve your problem.
Another reason can be, maybe you are not passing it as a string. The clientID key in the options expects a string as it's value.
Solution 15:[15]
I had the same issue due to the fact that I set the key of the key-value pair of the environment variables in heroku as env.process.VARIABLE_KEY and not just as VARIABLE_KEY.
Solution 16:[16]
I just had the same error.
I fixed it by simply changing my ".env" file to the project path
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
