Tôi đang sử dụng nút, hiển thị và hộ chiếu có xác thực facebook.
tôi có các tuyến đường sau (khi /facebook/auth/callback
là url callback):Lỗi xác thực hộ chiếu dẫn đến vòng chuyển hướng
function render(page, req, res) {
var user = null;
if (req.user) {
user = req.user.toObject();
user.isLoggedIn = true;
}
res.render(page, { user: user });
}
app.get('/auth-failure', function (req, res) {
res.render('auth-failure');
});
app.get('/auth-success', function (req, res) {
render('auth-success', req, res);
});
app.get('/facebook/auth', passport.authenticate('facebook', { scope: [ 'email', 'user_about_me', 'publish_actions']}));
app.get('/facebook/auth/callback', passport.authenticate('facebook', { failureRedirect: '/auth-failure', successRedirect: '/auth-success' }));
Khi xác thực thành công tôi đã xem trang auth-success
như tôi mong đợi. Nhưng khi xác thực thất bại và facebook quay trở lại: http://localhost:3000/facebook/auth/callback?error_code=2102&error_message=User+is+not+a+test+user+owned+by+the+application#=
Tôi không có chế độ xem auth-failure
! Thay vào đó, firefox trả về cho tôi trang:
Khi chạy trong chrome, tôi nhận được thông báo:
tôi cố gắng để kiểm tra mọi thứ và tôi thay thế các bộ định tuyến thất bại trong việc:
app.get('/facebook/auth/callback', function (req, res) {
res.redirect('/auth-failure');
});
Và điều này hiển thị thành công chế độ xem auth-failure
.
Sự cố với xác thực thất bại trên Facebook Passport.js là gì?
Tại sao nó trả lại cho tôi trang lỗi đó?
Về @ Matt Bakaitis bình luận:
Đây là tôi serialize và deserialize chức năng:
// serialize sessions
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findOne({ _id: id }, function (err, user) {
done(err, user);
});
});
Nó xuất hiện các công trình ví dụ trong Firefox mặc dù. – jhtong
@toiletfreak: Tôi đính kèm hình ảnh về hành vi sai trái này trong Firefox. – Naor
Bạn có thay đổi mã passport.serialize hoặc passport.deserialize không? –