目前,我正在为我的 iOS 应用程序使用带有 Express 和 Passport-facebook-token 模块的 NodeJS。我遇到了麻烦,因为即使我们通过了 OAuth 逻辑,服务总是返回 401 响应。关于此代码的任何想法,即使它成功通过身份验证并到达我们的 handleAuthentiation
方法但没有达到我有 console.log("这不是被召唤”)
被召唤进来了吗?
var http = require("http");
var express = require("express");
var bodyParser = require('body-parser');
var database = require('./database.js');
var passport = require('passport'),
FacebookTokenStrategy = require('passport-facebook-token').Strategy;
var User = require('./User.js');
var app = express();
//setup json parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
//setup facebook authentication
passport.use(new FacebookTokenStrategy({
clientID: "2454efafd33r",
clientSecret: "323245343"
},
function(accessToken, refreshToken, profile, done) {
User.handleAuthentication(accessToken, refreshToken, profile, done, function(err, user) {
console.log("handleAuthentication user is " + JSON.stringify(user));
console.log("handleAuthentication error is " + JSON.stringify(err));
done(err, user);
});
}
));
app.post('/auth/facebook/token',
passport.authenticate('facebook-token'),
function(req, res) {
console.log("THIS IS NOT BEING CALLED");
// do something with req.user
res.status(200);
res.send(user);
}
);
http.createServer(app).listen(3000);
我正在尝试通过其他库跟踪调用,但我似乎找不到任何定义了 success
的方法。我注意到 done
方法被映射到验证,然后调用 success
。
想通了。原来我没有正确初始化 Oauth。我需要设置以下内容:
// Configure Express
app.use(logger('combined'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(session({secret: 'supernova', saveUninitialized: true, resave: true}));
app.use(passport.initialize());
app.use(passport.session());
关于ios - Passport-facebook-token 不断返回 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27833011/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |