3

这是我的第一个 StackOverflow 输入,所以请温柔:p

我正在使用 MEAN 堆栈做一个 web 应用程序,但我遇到了一个我似乎无法解决的问题。尝试了我在网上找到的几种解决方案,但似乎没有任何效果。我有这个 Node/Express 后端,它与 facebook 联系,具有:

router.post('/login/facebook', passport.authenticate('facebook');

然后收到来自 facebook 的回调:

router.get('/login/facebook/callback',
    passport.authenticate('facebook', { failureRedirect: '/#' }),
    function (req, res) {
        console.log("in facebook return!");
        console.log(req.user);
    });

我可以在我的 console.log 中看到我得到的数据是我所期望的!到目前为止一切顺利.. 问题是,当我点击我的 facebook 登录按钮时,它会调用我的 satellizer facebook 登录:

   $scope.authenticate = function(provider) {
        $auth.authenticate(provider).then(function(res){
            console.log(res.data);
        });
    };

.. 我在我的 chrome 控制台中收到这条消息:

XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=..... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access.

我想我已经监督了一些事情,但我不知道是什么.. 当我单击它尝试重定向到的链接时,我在终端的控制台中获得了我的信息打印。但我不能被重定向,因为它不允许,显然..

有谁知道解决方案可能是什么?我试图把它放到我的 server.app 中:

app.use(function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
    next();
});

正如我希望的那样,我可以绕过跨源政策,但它也没有奏效。

有什么建议么?:-)

此致!

4

0 回答 0