问题描述:

I am implementing Passport in a Messenger bot but the callback url never seems to be called and I get the following error in the console

heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/auth/facebook/callback?code=SOMECODE&state=SOMESTATE" host=MYAPP.herokuapp.com request_id=SOMEID fwd="114.134.189.180" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0

I am still redirected to Facebook to grant permission, but the callback redirection freezes afterwards. I have had a look at other issues here but can't figure out where I am wrong. Here is my code (I'm using botkit toolkit for the bot and trying to redirect the user to the Messenger app after login):

In facebook_bot.js

 function testFacebookAuthCallback(req, token, refreshToken, profile, done) {

var providerUserProfile = {

fullName : profile.displayName,

email : profile.emails,

friends : profile.user_friends

};

//Using mongodb (no Mongoose)

responseStore.toDatabase('profile', providerUserProfile ,function(response){ // seems this function doesn't fire

if(err) done(err);

if(user){

done(null,profile);

} else {

done(null);

}

});

}

facebookLoginButton = function(response, convo) {

senderId = currentUser;

pageId = currentPage;

convo.say({

attachment: {

type: 'template',

payload: {

template_type: 'button',

text: 'Please login',

buttons: [

{

type: 'web_url',

title: 'Log in with Facebook',

url: `https://MYAPP.herokuapp.com/auth/facebook/${senderId}/?pageId=${pageId}`

}

]

}

}

});

};

In facebook.js

 var passport = require('passport');

var cookieParser = require('cookie-parser');

var http = require('http');

var express = require('express');

var session = require('express-session');

const path = require('path');

webserver.get('/auth/facebook/:senderId', (req, res, next) => {

req.session.sender = req.params.senderId;

req.session.pageId = req.query.pageId;

passport.authenticate('facebook', {scope: ['email', 'user_friends']}, {

state: {

sender: req.params.senderId,

pageId: req.query.pageId

}

}

)(req, res, next);

});

//This won't fire

webserver.get('/auth/facebook/callback',

passport.authenticate('facebook'), function(req, res, next) {

const ua = req.headers['user-agent'].toLowerCase(),

isMobile = SOME FUNCTION TO CHECK THE DEVICE

req.mobile = !!isMobile;

next();}, (req, res) => {

if (!req.user) {

return res.send('Something gone wrong. Try again.');

}

if (req.mobile) {

res.redirect(`http://m.me/${req.session.pageId}`);

} else {

res.redirect('/closeWindow');

}

});

webserver.get('/closeWindow', (req, res) => {

res.sendFile(path.resolve('static/closeWindow.html'));

});

What am I missing? Why does the callback never fires?

相关阅读:
Top