2014-04-25 28 views
5

Tôi đang sử dụng hộ chiếu-twitter để thiết lập kết nối twitter trên trang web của mình. Người dùng có thể kết nối bằng cách nhấp vào 'đăng nhập' hoặc 'thêm mục mới'. Sự khác biệt duy nhất giữa 2 là nếu họ nhấp vào thêm mục mới, một cửa sổ modal là nghĩa vụ phải mở một lần họ đang đăng nhậpHộ chiếu-Twitter - Lỗi: Không thể tìm thấy mã thông báo yêu cầu trong phiên

Để biết vào nút họ nhấp chuột, tôi lưu trữ các url trong req.session.referrer:.

// route for twitter authentication and login 
app.get('/auth/twitter', function(req, res, next){ 
    req.session.referrer = req.url; 
    console.log(req.session); 
    passport.authenticate('twitter')(req, res, next); 
}); 

app.get('/auth/twitter/new', function(req, res, next){ 
    req.session.referrer = req.url; 
    console.log(req.session); 
    passport.authenticate('twitter')(req, res, next); 
}); 

// handle the callback after twitter has authenticated the user 
app.get('/auth/twitter/callback', function(req, res, next){ 
    var options = { 
      successRedirect : '/twitter-user/signin', 
      failureRedirect : '/' 
     }; 

    console.log(req.session); 
    if (req.session.referrer && req.session.referrer.indexOf('new') > -1) options.successRedirect = '/twitter-user/new'; 

    passport.authenticate('twitter', options)(req, res, next) 
}); 

Tất cả mọi thứ hoạt động tốt trong môi trường phát triển của tôi nhưng một khi online tôi nhận được thông báo lỗi này: nhanh

500 Error: Failed to find request token in session 
at Strategy.OAuthStrategy.authenticate (/app/node_modules/passport-twitter/node_modules/passport-oauth1/lib/strategy.js:142:54) 
... 

cài đặt của tôi được thiết lập đúng cách trong Twitter. Dưới đây là những gì tôi nhận được với các bản ghi: Đối với các yêu cầu:

{ cookie: 
    { path: '/', 
     _expires: null, 
     originalMaxAge: null, 
     httpOnly: true }, 
    passport: {}, 
    referrer: '/auth/twitter' } 

Đối với callback:

{ cookie: 
    { path: '/', 
     _expires: null, 
     originalMaxAge: null, 
     httpOnly: true }, 
    passport: {} } 

Có lẽ nó có thể là do vấn đề tên miền phụ (http://example.com vs http://www.example.com) như tôi không có pb cục bộ. Làm cách nào để khắc phục sự cố này?

Rất cám ơn

EDIT: khóa API của tôi được thiết lập như thế này (theo hướng dẫn này: http://scotch.io/tutorials/javascript/easy-node-authentication-twitter):

passport.use(new TwitterStrategy({ 

    consumerKey  : configAuth.twitterAuth.consumerKey, 
    consumerSecret : configAuth.twitterAuth.consumerSecret, 
    callbackURL  : configAuth.twitterAuth.callbackURL 

},function(token, tokenSecret, profile, done) { 
    ... 
    }); 
+0

nơi bạn có thiết lập khóa api twitter tham quan? – Biba

+0

Tôi đã chỉnh sửa câu hỏi của mình với thông tin. Xin vui lòng xem ở trên – Spearfisher

Trả lời

1

Tôi đã nhận các lỗi tương tự, nhưng giải quyết nó .. và đây là những gì tôi vấn đề là giải pháp.

Thực tế, nó không giống như url chuyển hướng của tôi "http: // localhost/auth/twitter/callback". Tôi đã đổi nó thành "http: // 127.0.0.1/auth/twitter/callback". Trong mã thực sự của tôi, tôi phải giữ nó như là localhost hoặc tôi gặp lỗi về một mã thông báo bị thiếu

Các vấn đề liên quan