2014-02-28 40 views
0

我正在嘗試使用Box.com OAuth2.0對用戶進行身份驗證。我使用授權碼進行初始呼叫和登錄,將其重定向到我的回叫網址。此時,我的服務器使用護照處理回調,但由於某種原因,它返回302並重定向到oauth身份驗證過程的開始。護照授權回調重定向到開始(Box)

//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' 
    }) 
); 

我覈實,我的路線被稱爲用我自己的處理程序,並請求數據似乎是正確的。 Box會返回一個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); 
     }); 
     } 
    }); 
    } 
)); 

希望得到任何見解,以什麼可能會導致這種重定向行爲。

回答

0

它最終成爲PeerServer的一個實例,它以某種方式導致重定向。