簡體   English   中英

使用 Google OAuth2 和 Passportjs 重定向到回調 url 時出現 500 內部服務器錯誤

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

應用程序憑據似乎很好。 重定向的 URL 帶回配置文件 object 並顯示 500 內部服務器錯誤。 因此,get 回調路由中的任何代碼都不起作用。 任何幫助將不勝感激。

以下是我的代碼片段:

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

我知道了!

回調 done 接受兩個 arguments 而不是一個。 因此,在passport.use()return語句中將done(null, profile.id)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM