我有以下Node代码使用护照-a-oauth …
app.get('/auth/google',passport.authenticate('google',{ scope : ['profile','email'] })); app.get('/auth/google/callback',function(req,res) { console.log("callback"); passport.authenticate('google',{ successRedirect : '/signin',failureRedirect : '/signin' }); });
和…
passport.serializeUser(function(user,done) { console.log("ser"); done(null,user.id); }); passport.deserializeUser(function(id,done) { console.log("des"); User.findById(id,function(err,user) { done(err,user); }); }); passport.use(new GoogleStrategy({ clientID : 'id',clientSecret : 'key',callbackURL : 'http://host/auth/google/callback',},function(token,rtoken,profile,done) { console.log("proc"); console.log(profile); done(null,profile); }));
解决方法
我刚刚发现护照google-oauth包出口如下:
exports.Strategy = exports.OAuthStrategy = OAuthStrategy; exports.OAuth2Strategy = OAuth2Strategy;
这意味着,“默认”(即策略)根本不是oauth2 …所以你最好明确地使用OAuth2Strategy.它为我工作.花了我几个小时才发现这是问题…
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。