【问题标题】:Getting a 500 Internal server error when redirecting to the callback url using google OAuth2 with Passportjs使用 Google OAuth2 和 Passportjs 重定向到回调 url 时出现 500 内部服务器错误
【发布时间】:2021-05-29 23:24:23
【问题描述】:

应用凭据看起来不错。重定向的 URL 会带回带有 500 内部服务器错误的配置文件对象。因此,get 回调路由中的任何代码都不起作用。任何帮助将不胜感激。

这是我的代码的 sn-ps:

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

passport.use(new GoogleStrategy({
    clientID: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    callbackURL: process.env.GOOGLE_CALLBACK_URL
  },
  function(accessToken, refreshToken, profile, done) {
    return done(profile.id);
  }

app.get('/auth/google/callback', passport.authenticate('google', { successRedirect: '/', failureRedirect: '/login' }),
  // code does not work
  }
)

【问题讨论】:

    标签: javascript node.js express oauth-2.0 passport.js


    【解决方案1】:

    我明白了!

    回调 done 接受两个参数而不是一个。所以,在passport.use()return 语句中将是done(null, profile.id)

    【讨论】:

      猜你喜欢
      • 2017-10-01
      • 2014-01-30
      • 2015-07-05
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 2016-03-26
      • 2020-02-06
      相关资源
      最近更新 更多