You need to enable JavaScript to run this app. 使用passport-google-oauth20实现谷歌登录生产环境缺scope报错,是否与VPN有关
优惠活动
大模型
产品
解决方案
定价
更多

使用passport-google-oauth20实现谷歌登录生产环境缺scope报错,是否与VPN有关

生产环境Google登录异常排查

异常概况

  • 该问题已持续近2天,排查过程无明显进展
  • 本地开发环境所有功能运行正常
  • 生产环境部署完成后,触发Google登录流程时直接抛出错误:Error 400: invalid_request Missing required parameter: scope
  • 待验证疑问:当前Web应用仅支持VPN访问,怀疑该网络特性可能是异常产生的原因

代码配置

Google登录跳转路由

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

GoogleStrategy 初始化配置

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
    })
);

已开展的排查动作

  • 初始版本的scope配置仅包含email、profile两个授权范围
  • 为定位问题,临时在scope数组中新增openid参数,重新部署后异常仍未解决

技术实现说明

  • 基于passport-google-oauth20 npm包封装实现Google登录能力
  • 寻求社区技术协助,定位该生产环境专属异常的根本成因

内容的提问来源于stack exchange,提问作者Farman Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.05 04:45:05