您好,我一直在努力为这个错误找到解决方案2天,但无济于事!我已经在Stack Overflow上搜索过了。这些错误与我的错误无关。这是我收到的堆栈跟踪。
Error
at Strategy.parseErrorResponse (/Users/jeremy/projects/thinkful_capstone_2/node_modules/passport-facebook/lib/strategy.js:196:12)
at Strategy.OAuth2Strategy._createOAuthError (/Users/jeremy/projects/thinkful_capstone_2/node_modules/passport-oauth2/lib/strategy.js:376:16)
at /Users/jeremy/projects/thinkful_capstone_2/node_modules/passport-oauth2/lib/strategy.js:166:45
at /Users/jeremy/projects/thinkful_capstone_2/node_modules/oauth/lib/oauth2.js:191:18
at passBackControl (/Users/jeremy/projects/thinkful_capstone_2/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage.<anonymous> (/Users/jeremy/projects/thinkful_capstone_2/node_modules/oauth/lib/oauth2.js:157:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
这里也是我的代码:
const path = require('path');
// const Strategy = require('passport-facebook').Strategy;
const bodyParser = require('body-parser');
const passport = require('passport');
// const { User } = require('../models/usermodel.js');
const express = require('express');
const cookieParser = require('cookie-parser');
const router = express.Router();
const app = express();
app.use(passport.initialize());
app.use(passport.session());
app.use(cookieParser());
app.use(require('body-parser').urlencoded({ extended: true }));
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (user, done) {
done(null, user);
});
router.get('/', passport.authenticate('facebook'), function (req, res) {
console.log(req.isAuthenticated());
console.log(req.user);
res.sendFile(path.resolve('./public/adwall.html'));
});
module.exports = router;
任何帮助将不胜感激!谢谢!
编辑:我也在我的服务器文件中添加了这个策略:
这是我在另一个名为server.js的文件中使用的facebook auth的策略:
passport.use(new Strategy({
clientID: process.env.FACEBOOK_APP_ID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackURL: 'http://localhost:8080/facebook/auth/cb'
},
function (accessToken, refreshToken, profile, cb) {
return cb(null, profile);
}));
以下是github项目的链接: https://github.com/jeremytaylor7/wallaby-ads-project
答案 0 :(得分:0)
你忘记了非常重要的事情。
执行passport.authenticate('facebook')...
它将查找您尚未定义的Facebook策略。
http://passportjs.org/docs/facebook查看此处配置新策略。
var passport = require('passport')
, FacebookStrategy = require('passport-facebook').Strategy;
passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://www.example.com/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate(..., function(err, user) {
if (err) { return done(err); }
done(null, user);
});
}
));
也可能在您定义会话的位置下方有app.use(passport.initialize())
和app.use(passport.session())
。