Angularjs不使用Facebook身份验证策略拦截nodejs服务器提供的令牌

时间:2016-04-14 08:08:07

标签: angularjs node.js express

我是nodejs / angularjs的新手,并在我的第一个简单的Web应用程序上工作。我正在为Passport和Node.js使用Facebook身份验证策略。在成功验证后,我想将jwt令牌返回给客户端Angular应用程序。我的服务器代码如下所示:

app.get('/auth/facebook/callback',
        passport.authenticate('facebook', {
            failureRedirect : '/',
            session: false
        }),
        function(req, res){
            res.set("x-access-token", req.user.JWTtoken);
            res.redirect("/#/main");
        }
    );

我的客户端应用程序试图拦截响应以获取上面提供的jwt令牌。

$httpProvider.interceptors.push(function($q) {
      return {
       'request': function(config) {
           return config;

        },

        'response': function(response) {
            console.log(response.headers('x-access-token')); 


           return response;
        }
      };
    });  

通过测试这种情况,我无法在响应头中看到JWT令牌。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您在服务器上设置标头时不需要使用config属性。请改用response.headers;

$httpProvider.interceptors.push(function($q) {
      return {
       'request': function(config) {
           return config;

        },

        'response': function(response) {
           console.log(response.headers('x-access-token')); 
           return response;
        }
      };
    });