我正在尝试使用Box.com OAuth2.0对用户进行身份验证。我进行初始调用和登录,使用授权码重定向到我的回调URL。此时,我的服务器使用护照处理回调,但由于某种原因,它返回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'
})
);
我验证了我的路由是通过使用我自己的处理程序调用的,并且请求数据似乎是正确的。 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 :(得分:0)
它最终成为PeerServer的一个实例,它以某种方式导致重定向。