ошибка с OAuth2Strategy, которая требует CLIENTID - PullRequest
0 голосов
/ 22 декабря 2019

У меня возникла ошибка при запуске приложения:

/api # yarn start
yarn run v1.21.1
$ nodemon server-express.js
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server-express.js`
/api/node_modules/passport-oauth2/lib/strategy.js:86
  if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); }
                           ^

TypeError: OAuth2Strategy requires a clientID option
    at Strategy.OAuth2Strategy (/api/node_modules/passport-oauth2/lib/strategy.js:86:34)
    at new Strategy (/api/node_modules/passport-google-oauth20/lib/strategy.js:52:18)
    at Object.<anonymous> (/api/helpers/authHelper.js:26:5)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1028:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/api/server-express.js:13:23)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...

Это мой идентификатор файла .env:

# NODE TODO
NODE_ENV=production
PORT=3001
HOST=localhost
# MONGO TODO
MONGO_USER=...
MONGO_DB=....
MONGO_PASS=....
MONGO_HOST=localhost
#GOOGLE_AUTH TODO
GOOGLE_CLIENTID = "....-......apps.googleusercontent.com"
GOOGLE_CLIENTSECRET = ".....-....."
GOOGLE_REDIRECT = "http://localhost:3001/auth/google/callback"
#FACEBOOK_AUTH TODO
FACEBOOK_CLIENTID = ....
FACEBOOK_CLIENTSECRET = "....."
FACEBOOK_CALLBACKURL = "http://localhost:3001/auth/facebook/callback"
FACEBOOK_TEST_EMAIL = "s....@gmail.com"
#LOCAL_URL TODO
CLIENT = "localhost:3000"
CLIENTURL = "http://localhost:3000"
SCHEMES = "http://"
SERVERAPI = "http://localhost:3001"
#GMAIL
SECRETKEY = ".....="
GMAILPSW = "....!"
SUPPORTEMAIL = "...@gmail.com"
#JWT
JWTSECRET = "...."
#COOKIE
COOKIEKEY = "...."

Не могли бы вы помочь мне решить эту проблему, яна самом деле не знаю, откуда возникла ошибка

Спасибо Спасибо Спасибо Спасибо Спасибо Спасибо Спасибо Спасибо Спасибо Спасибо Спасибо

1 Ответ

0 голосов
/ 22 декабря 2019

вам нужно перейти на

https://console.developers.google.com/

здесь вам нужно настроить приложение. Включите Google API, затем найдите Google+, а затем нажмите Включить API. Затем создайте учетные данные API. как только вы закончите, вы получите clientId и SecretId.

, когда вы настроите свой файл passport.js, вы должны передать эти учетные данные в стратегию Google. для безопасности поместите эти учетные данные в другой файл в вашем приложении и импортируйте их.

module.exports = {
  googleClientID:
    "mygooogleclientIdHERE.apps.googleusercontent.com",
  googleClientSecret: "secretIdHERE"


};

в файле passport.js

const keys = require("../config/keys.js");
const passport = require("passport");


passport.use(
  new GoogleStrategy(
    {
      clientID: keys.googleClientID,
      clientSecret: keys.googleClientSecret,
      callbackURL: "/auth/google/callback"
    },
    (accessToken, refreshToken, profile, done) => {
      //this is where you implement the communication between server and database

    }
  )
);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...