【发布时间】:2018-02-13 06:06:16
【问题描述】:
基于https://github.com/passport/express-4.x-facebook-example/blob/master/server.js,我正在尝试使用 Passport 和 node.js 实现基本的 Google 身份验证。
我的 Passport 配置如下所示:
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "https://localhost:3000/auth/callback" // not sure if correct.
},
function(accessToken, refreshToken, profile, cb) {
console.log("accessToken: " + accessToken);
console.log("refreshToken: " + refreshToken);
console.log("profile: " + profile);
console.log("cb: " + cb);
cb(accessToken, profile);
}
));
我已经设置了以下 GET 路由:
app.get('/auth/',
passport.authenticate('google', { scope: ['profile'] }));
app.get('/auth/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
console.log("success");
// Successful authentication, redirect home.
res.redirect('/');
});
当我尝试访问身份验证页面时,我得到一个正常的谷歌登录屏幕,但在我登录后,我得到一个net::ERR_CONNECTION_CLOSED 消息。该 URL 看起来像 https://localhost:3000/auth/callback?code=ACCESS_CODE,但不知何故不会导致重定向到 /login(如果失败)或重定向到 /(如果成功)。
感谢任何帮助!我对 Passport 和一般的 oauth 都很陌生。
【问题讨论】:
标签: node.js oauth-2.0 google-authentication passport.js