Using everyauth for connect + fb graph calls.

190 views
Skip to first unread message

Rajat Mittal

unread,
May 22, 2012, 1:50:43 AM5/22/12
to ever...@googlegroups.com
I have successfully used everyauth to implement Facebook connect on my app. 

// configure facebook authentication
everyauth.facebook
.appId(config.appId)
.appSecret(config.appSecret)
.handleAuthCallbackError( function (req, res) {
// If a user denies your app, Facebook will redirect the user to
// /auth/facebook/callback?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.
// This configurable route handler defines how you want to respond to
// that.
// If you do not configure this, everyauth renders a default fallback
// view notifying the user that their authentication failed and why.
console.log(res);
})
.findOrCreateUser( function (session, accessToken, accessTokExtra, fbUserMetadata) {
// console.log('session:', session);
// console.log('accessToken:', accessToken);
// console.log('fbUserMetaData:', fbUserMetadata);
return {};
})
.redirectPath('/manager/');

After that, I want to make a few fb graph calls to retrieve some data, for example:

function getFeed(access_token){
var options = {
host: 'graph.facebook.com',
path: '/me/feed/access_token=' + access_token,
method: 'GET'
};
var req = https.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
}

If I I call the above fn after user signs in with fb-connect, I expect to be be able to make that call. However, this is the response that I get from FB.

HEADERS: {"access-control-allow-origin":"*","cache-control":"no-store","content-type":"text/javascript; charset=UTF-8","expires":"Sat, 01 Jan 2000 00:00:00 GMT","pragma":"no-cache","www-authenticate":"OAuth \"Facebook Platform\" \"invalid_request\" \"An active access token must be used to query information about the current user.\"","x-fb-rev":"560879","x-fb-debug":"EHNfOK8FGucb250baBLc75M1Id3OY7l+4BxPgj/ZRN0=","date":"Tue, 22 May 2012 05:37:11 GMT","content-length":"140","connection":"keep-alive"}
BODY: {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

message":"An active access token must be used to query information about the current user. 

I dont understand this. I have the access_token as the user authenticated my app with facebook-connect. Yet I am unable to retrieve user's feed.

Any explanation would be really helpful.

Rajat Mittal

unread,
May 22, 2012, 3:25:38 AM5/22/12
to ever...@googlegroups.com
I noticed the expires header of the response is set to:

"expires":"Sat, 01 Jan 2000 00:00:00 GMT"

which means its already expired. This confuses me even more. How is everyauth able to keep the user logged in my app if the access token is already expired ?

This partially explains why I am unable to make further graph calls. I am still unsure of the potential answer though.
Reply all
Reply to author
Forward
0 new messages