passport-google-oauth20: GooglePlusAPIError: API Legacy People не использовался в проекте Ask - PullRequest
0 голосов
/ 11 апреля 2020

Я пытаюсь добавить вход в Google, используя passport-google-oauth20, но когда я пытаюсь войти в систему, возникает следующая ошибка.

GooglePlusAPIError: Legacy People API has not been used in project xxxxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project=xxxxxxxthen retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
    at E:\my dp\webp\advancedNodeStarter\AdvancedNodeStarter\node_modules\passport-google-oauth20\lib\strategy.js:95:21
    at passBackControl (E:\my dp\webp\advancedNodeStarter\AdvancedNodeStarter\node_modules\oauth\lib\oauth2.js:132:9)
    at IncomingMessage.<anonymous> (E:\my dp\webp\advancedNodeStarter\AdvancedNodeStarter\node_modules\oauth\lib\oauth2.js:157:7)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Ниже приводится паспорт Js код конфигурации для проекта я использую passport-google-oauth20. Мне нужно только проверить пользователя и получить профиль basi c во время аутентификации.

const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const mongoose = require('mongoose');
const keys = require('../config/keys');

const User = mongoose.model('User');

passport.serializeUser((user, done) => {
  done(null, user.id);
});

passport.deserializeUser((id, done) => {
  User.findById(id).then(user => {
    done(null, user);
  });
});

passport.use(
  new GoogleStrategy(
    {
      callbackURL: '/auth/google/callback',
      clientID: keys.googleClientID,
      clientSecret: keys.googleClientSecret,
      proxy: true
    },
    async (accessToken, refreshToken, profile, done) => {
      try {
        const existingUser = await User.findOne({ googleId: profile.id });
        if (existingUser) {
          return done(null, existingUser);
        }
        const user = await new User({
          googleId: profile.id,
          displayName: profile.displayName
        }).save();
        done(null, user);
      } catch (err) {
        done(err, null);
      }
    }
  )
);

И вот мой код маршрута для обработки входа в систему, выхода из системы.

const passport = require('passport');

module.exports = app => {
  app.get(
    '/auth/google',
    passport.authenticate('google', {
      scope: ['profile', 'email']
    })
  );

  app.get(
    '/auth/google/callback',
    passport.authenticate('google'),
    (req, res) => {
      res.redirect('/blogs');
    }
  );

  app.get('/auth/logout', (req, res) => {
    req.logout();
    res.redirect('/');
  });

  app.get('/api/current_user', (req, res) => {
    res.send(req.user);
  });
};

...