ios - Passport-facebook-token 不断返回 401
<p><p>目前,我正在为我的 iOS 应用程序使用带有 Express 和 Passport-facebook-token 模块的 NodeJS。我遇到了麻烦,因为即使我们通过了 OAuth 逻辑,服务总是返回 401 响应。关于此代码的任何想法,即使它成功通过身份验证并到达我们的 <code>handleAuthentiation</code> 方法但没有达到我有 <code>console.log("这不是被召唤”)</code> 被召唤进来了吗?</p>
<pre><code>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);
</code></pre>
<p>我正在尝试通过其他库跟踪调用,但我似乎找不到任何定义了 <code>success</code> 的方法。我注意到 <code>done</code> 方法被映射到验证,然后调用 <code>success</code>。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>想通了。原来我没有正确初始化 Oauth。我需要设置以下内容:</p>
<pre><code>// 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());
</code></pre></p>
<p style="font-size: 20px;">关于ios - Passport-facebook-token 不断返回 401,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27833011/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27833011/
</a>
</p>
页:
[1]