![](/img/trans.png)
[英]Getting CORS error when using PassportJS for Google OAuth in React/Express
[英]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.