【发布时间】:2013-06-29 19:09:18
【问题描述】:
我第一次尝试设置护照,只使用一个谷歌登录选项。我注册了 google apis,所以我有所有的设置。相关代码如下,但是当我的应用程序调用'/auth/google/' 时,它只是失败,没有响应或错误消息。我已经改变了配置的一堆方法无济于事。我还将passport.authenticate('google') 替换为带有console.log 的匿名函数,以仔细检查我的Web 服务是否正常运行。所以我知道它正在到达passport.authenticate('google')。
// serialize session
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(function (obj, done) {
done(null, obj);
});
// use google strategy
passport.use(new googleStrategy({
clientID: config.google.clientID,
clientSecret: config.google.clientSecret,
callbackURL: config.google.callbackURL,
scope: 'https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
},
function(accessToken, refreshToken, profile, done) {
console.log(profile);
}
));
app.use(passport.initialize());
app.use(passport.session());
app.get('/auth/google', passport.authenticate('google'));
app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/', scope: 'https://www.google.com/m8/feeds' }), signin);
编辑: 这是我的 http 请求,我正在使用 angular,此功能与 ng-click 按钮相关联。
$scope.signIn = function () {
$http({method: 'GET', url: '/auth/google'}).
success(function (data, status, headers, config) {
console.log('success');
}).
error(function (data, status, headers, config) {
console.log(data);
console.log(status);
console.log(headers);
console.log(config);
});
};
那些日志什么也没有返回
【问题讨论】:
-
你真的没有错误信息吗?可能是超时?它是如何失败的?
-
我无法捕捉或取回任何东西。它似乎失败了,没有任何类型的回报。也许该调用配置错误。我也会添加我的 ajax 代码以防万一。
标签: javascript node.js express passport.js