Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Passport授权回调重定向到开始(框)_Javascript_Node.js_Oauth 2.0_Passport.js - Fatal编程技术网

Javascript Passport授权回调重定向到开始(框)

Javascript Passport授权回调重定向到开始(框),javascript,node.js,oauth-2.0,passport.js,Javascript,Node.js,Oauth 2.0,Passport.js,我正在尝试使用Box.com OAuth2.0对用户进行身份验证。我进行了初始呼叫和登录,并使用授权码重定向到我的回调url。此时,我的服务器使用passport处理回调,但出于某种原因,它返回302并重定向到oauth身份验证过程的开始 //box authentication routes app.get('/api/box', passport.authorize('box')); // the callback after box has authorized the us

我正在尝试使用Box.com OAuth2.0对用户进行身份验证。我进行了初始呼叫和登录,并使用授权码重定向到我的回调url。此时,我的服务器使用passport处理回调,但出于某种原因,它返回302并重定向到oauth身份验证过程的开始

  //box authentication routes
  app.get('/api/box', passport.authorize('box'));

  // the callback after box has authorized the user
  app.get('/api/box/callback', passport.authorize('box', {
      successRedirect: '/',
      failureRedirect: '/login'
    })
  );
我使用自己的处理程序验证了正在调用我的路由,并且请求数据似乎是正确的。框返回一个200,url包含授权代码

app.get('/api/box/callback', function(req, res) {
    console.log('auth called')
  });
这是我的护照策略:

passport.use(new BoxStrategy({
    clientID: config.box.clientID,
    clientSecret: config.box.clientSecret,
    callbackURL: config.box.callbackURL,
    passReqToCallback: true
  },
  function(req, accessToken, refreshToken, profile, done) {

    process.nextTick(function() {

      if(!req.user) {
          // try to find the user based on their google id
        User.findOne({ 'box.id' : profile.id }, function(err, user) {
          if (err)
            return done(err);

          if (user) {
            // if a user is found, log them in
            return done(null, user);
          } else {
            // if the user isnt in our database, create a new user
            var newUser = new User();

            // set all of the relevant information
            newUser.box.id = profile.id;
            newUser.box.accessToken = accessToken;
            newUser.box.refreshToken = refreshToken;
            newUser.box.name  = profile.name;
            newUser.box.email = profile.login;

            // save the user
            newUser.save(function(err) {
              if (err)
                throw err;
              return done(null, newUser);
            });
          }
        });
      } else {
        // user already exists and is logged in, we have to link accounts
        var user = req.user;

        // update the current users box credentials
        user.box.id = profile.id;
        user.box.accessToken = accessToken;
        user.box.refreshToken = refreshToken;
        user.box.name  = profile.name;
        user.box.email = profile.login;

        // save the user
        user.save(function(err) {
          if (err)
            throw err;
          return done(null, user);
        });
      }
    });
  }
));

如果您能深入了解导致此重定向行为的原因,我们将不胜感激。

它最终是PeerServer的一个实例,不知何故导致了此重定向