gpt4 book ai didi

node.js - Passport -facebook FacebookTokenError : This authorization code has been used

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:08 25 4
gpt4 key购买 nike

这是我的passport.js

var FacebookStrategy = require('passport-facebook').Strategy;


var User = require('./app/models/users');
var config = require('./config');

module.exports = function (passport) {


passport.serializeUser(function (user, done) {
done(null, user.id);
});

passport.deserializeUser(function (id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});



passport.use(new FacebookStrategy({
clientID: config.facebook.appId,
clientSecret: config.facebook.appSecret,
callbackURL: config.facebook.redirectUrl,
profileFields: ['id', 'name', 'displayName', 'emails', 'photos']

},
function (accessToken, refreshToken, profile, done) {
process.nextTick(function () {

User.findOne({'facebook.id': profile.id}, function (err, user) {

console.log(profile);

if (err) {
// console.log("tick errr");
return done(err)
}
;
if (user)
return done(null, user);
else {
var newUser = new User();
newUser.facebook.id = profile.id;
newUser.facebook.token = accessToken;
newUser.facebook.name = profile.displayName;
newUser.facebook.email = profile.emails[0].value;
newUser.facebook.picurl = profile.photos[0].value;
// console.log("access to ken is "+accessToken);
//console.log(newUser.facebook.id);

newUser.save(function (err) {
if (err)
console.log(err);
return done(null, newUser);
})
}
});
});
// done(null, profile);
}
));

api.js

 api.get('/auth/facebook', function (req, res, next) {

passport.authenticate('facebook', {scope: ['email']})(req, res, next);
});


api.get('/auth/facebook/callback',

passport.authenticate('facebook', {


successRedirect: '#/home',
failureRedirect: '#/login'


})

);


};

我在使用 Facebook 登录时遇到问题。我收到以下错误:

FacebookTokenError: This authorization code has been used.
at Strategy.parseErrorResponse (c:\Users\chetan kanjani\WebstormProjects\letsgo\node_modules\passport-facebook\lib\strategy.js:199:12)
at Strategy.OAuth2Strategy._createOAuthError (c:\Users\chetan kanjani\WebstormProjects\letsgo\node_modules\passport-facebook\node_modules\passport-oauth2\lib\strategy.js:345:16)
at c:\Users\chetan kanjani\WebstormProjects\letsgo\node_modules\passport-facebook\node_modules\passport-oauth2\lib\strategy.js:171:43
at c:\Users\chetan kanjani\WebstormProjects\letsgo\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:177:18
at passBackControl (c:\Users\chetan kanjani\WebstormProjects\letsgo\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:123:9)
at IncomingMessage.<anonymous> (c:\Users\chetan kanjani\WebstormProjects\letsgo\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickDomainCallback (node.js:381:11)

我能够登录 Facebook 页面,然后出现此错误。我从 Facebook 获取的详细信息仍然成功存储在我的数据库中;我认为这与 auth/facebook/callback 有关

users.js 文件:

var UserSchema = mongoose.Schema({
local: {

name: String,
username: {type: String, index: {unique: true}},
password: {type: String, select: false}
},
facebook: {
id: String,
token: String,
email: String,
name: String,
picurl: String,
},
favouriteid: [{eventid: String}]

});


UserSchema.pre('save', function(next) {

var user = this;


if (!user.isModified('local.password')) return next();

bcrypt.hash(user.local.password, null, null, function (err, hash) {
if(err) return next(err);

user.local.password = hash;
next();

});
});

UserSchema.methods.comparePassword = function(password) {

var user = this;

var a = bcrypt.compareSync(password, user.local.password);

if (a == true)
return true;
else {
console.log('error in compare password');
return false;
}

}

最佳答案

当您在 Facebook 帐户中留下应用程序登录数据时,会发生此错误。删除您的登录数据即可解决此错误。

  1. 登录 Facebook
  2. 前往设置
  3. 转到应用程序
  4. 搜索您应用的登录数据。
  5. 按下“X”按钮

按照上述步骤操作后,尝试登录Facebook Login。

关于node.js - Passport -facebook FacebookTokenError : This authorization code has been used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34023359/

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