简体   繁体   English

使用 Google OAuth2 和 Passportjs 重定向到回调 url 时出现 500 内部服务器错误

[英]Getting a 500 Internal server error when redirecting to the callback url using google OAuth2 with Passportjs

The app credentials seem fine.应用程序凭据似乎很好。 The redirected URL brings back the profile object with 500 Internal server error.重定向的 URL 带回配置文件 object 并显示 500 内部服务器错误。 Due to this any code inside the get callback route does not work.因此,get 回调路由中的任何代码都不起作用。 Any help will be appreciated.任何帮助将不胜感激。

Here are snippets of my code:以下是我的代码片段:

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

I got it!我知道了!

The callback done accepts two arguments instead of one.回调 done 接受两个 arguments 而不是一个。 So, in the return statement of the passport.use() will be done(null, profile.id) .因此,在passport.use()return语句中将done(null, profile.id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM