首页 > 解决方案 > 错误 400:invalid_request 缺少必需参数:范围

问题描述

从过去两天开始,我一直在这个问题上,一切都在我的本地环境中运行良好,但在生产中它给出了上述错误,

我的 Web 应用程序只能通过 vpn 访问,所以你认为这可能是问题吗?

router.get('/google', passport.authenticate('google', {
    scope: ['openid','profile', 'email']
}));

我为点击和尝试方法添加的openid,但这也不起作用,以前在范围内只有电子邮件和个人资料在那里,我的谷歌startegy在下面


passport.use(
    new GoogleStrategy({
        // options for strategy
        callbackURL: `${baseUrl}/auth/google/redirect`,
        clientID: process.env.PASSPORT_CLIENT_ID,
        clientSecret: process.env.PASSPORT_CLIENTSECRET
    }, (accessToken: string, refreshToken: string, profile: any, done: any) => {
        //code
    })

我正在使用 passport-google-oauth20 npm 包进行谷歌登录,任何帮助将不胜感激

标签: node.jsexpresspassport.jsgoogle-authentication

解决方案


尝试改变这个:

router.get('/google', passport.authenticate('google', {
    scope: ['openid','profile', 'email']
}));

为了这:

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

它对我有用...


推荐阅读