[英]Passport.js authenticate not working
I'm trying to set up passport for the first time and going with just a single google sign-in option. 我正试图第一次设置护照,只需要一个谷歌登录选项。 I registered with google apis so i have all that setup. 我在谷歌apis注册,所以我有所有设置。 the relavant code is below, but when my app makes the '/auth/google/'
call it just fails with no response or error message. 相关代码在下面,但当我的应用程序进行'/auth/google/'
调用时,它就会失败而没有响应或错误消息。 I've switched up the configuration a bunch of ways to no avail. 我已经开启配置了很多方法都无济于事。 I've also replaced the passport.authenticate('google')
with an anonymous function with a console.log to double check my web service is operating correctly and it is. 我还用一个带有console.log的匿名函数替换了passport.authenticate('google')
来仔细检查我的web服务是否正常运行。 So I know it is getting to the passport.authenticate('google')
. 所以我知道它已经到了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);
EDIT: Here is my http request, I'm using angular and this function is tied to a ng-click on a button. 编辑:这是我的http请求,我正在使用角度,这个功能与按钮上的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);
});
};
Those logs return nothing 那些日志什么都没有
You need to call done()
inside the middleware for the GoogleStrategy
您需要在GoogleStrategy
的中间件中调用done()
passport.use(new GoogleStrategy({
...
},
function(accessToken, refreshToken, profile, done) {
console.log(profile);
// Add this
done(null, profile);//profile contains user information
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.