gpt4 book ai didi

javascript - Passport 错误 - Strategy.ParseErrorResponse

转载 作者:搜寻专家 更新时间:2023-11-01 00:05:15 25 4
gpt4 key购买 nike

您好,我已经尝试为这个错误找到解决方案 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 身份验证策略:

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

最佳答案

你忘记了一件非常重要的事情。

当你做 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())在您定义 session 的位置下方。

关于javascript - Passport 错误 - Strategy.ParseErrorResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com