首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >护照-facebook-令牌继续返回401

护照-facebook-令牌继续返回401
EN

Stack Overflow用户
提问于 2015-01-08 04:35:06
回答 2查看 1.6K关注 0票数 2

目前,我正在使用NodeJS与快速和护照-facebook-令牌模块为我的iOS应用程序。我在这方面有问题,因为服务总是返回401响应,即使我们正在通过OAuth逻辑。对于为什么它继续返回401,即使它成功地通过了身份验证,并且使用了我们的handleAuthentiation方法,但是没有到达我所调用的console.log("THIS IS NOT BEING CALLED")方法,有什么想法吗?

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-18 16:05:17

弄明白了。原来我没有正确地初始化Oauth。我需要设置以下内容:

代码语言:javascript
复制
// 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());
票数 1
EN

Stack Overflow用户

发布于 2020-07-01 08:56:50

对我来说,我使用了文档中的示例:https://www.npmjs.com/package/passport-facebook-token,所以没有添加'.Strategy'

对于方法"POST“,如问题中所示,I作为主体,从前端发送:

代码语言:javascript
复制
const tokenBlob = new Blob([JSON.stringify({access_token: response.accessToken}, null, 2)], {type : 'application/json'}); 

https://medium.com/@alexanderleon/implement-social-authentication-with-react-restful-api-9b44f4714fa中所解释的那样

祝好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27833011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档