Получение ОШИБКИ 400 (ошибка OAuth2) - отсутствует обязательный параметр: область действия - PullRequest
0 голосов
/ 01 апреля 2020

Я получаю ошибку "400 Bad Request" при использовании Google+ API для входа в систему. Я следую основному руководству c OAuth (паспорт. js). Всякий раз, когда я пытаюсь запустить приложение и попытаться войти в систему с помощью Google Api, он возвращает следующую ошибку:

400. That’s an error.
Error: invalid_request
Missing required parameter: scope

Код маршрута:

    router.get('/google',passport.authenticate('google',{
    scope:['https://www.googleapis.com/auth/userinfo.profile'],
}));

//callback for google to redirect to
router.get('/google/redirect',passport.authenticate('google'),(req,res) =>{
    res.send('you reached the callback URL');
    console.log(res.send);
});

Стратегия Google:

passport.use(
    new GoogleStrategy({
    //options for the gooogle strategy

        clientID: keys.google.clientID,
        clientSecret: keys.google.clientSecret,
        callbackURL:'http://localhost:3000/auth/google/redirect'
    },(accessToken,refreshToken,profile,done) => {
        // passport callback function
        console.log('passport callback function fired');
        console.log(profile);

        new User({
          username: profile.displayName,
          googleId: profile.id 
        }).save().then((newUser) =>{
           console.log('new user created' , newUser);
        });
    })
);
...