【发布时间】:2015-06-30 10:23:24
【问题描述】:
我有以下程序可以使用 Google 登录:
app.get('/oauth/google', function(req, res) {
res.redirect(<OAUTH2_URL>);
});
app.get('/oauth/google/callback', function(req, res, next) {
var code = req.query.code;
if(!code || !_.isString(code)) {
return next(new Error(400, 'Invalid code'));
}
.
.
.
// I try the code to see if it is valid.
});
如何只允许 Google 重定向回应用程序以访问回调路由,并阻止普通用户使用它?
【问题讨论】:
-
你用什么进行谷歌身份验证?护照?
-
@laggingreflex 只需使用我想要的范围简单地重定向到“accounts.google.com/o/oauth2/auth”。当用户接受时,Google 会将他们发送回我在开发者控制台中提供的重定向 URL,即“/oauth/google/callback”。