Search code examples
facebook-ios-sdkfacebook-android-sdktrigger.ioparse-platform

forge.facebook.authorize returning incorrect Facebook token expiry time


I've been using forge.facebook.authorize() successfully for several months in my app to get FB auth tokens.

However since a certain point last week I've been unable to validate any of the tokens it's been returning, due to an incorrect expiry time, and thus unable to sign-up or log-in any Facebook users since.

I must make clear that none of my code changed - this FB login was working fine previously and then suddenly stopped and hasn't since. A deployed live app suddenly stopped letting users log in with Facebook.

reponse from forge.facebook.authorize:

[FORGE] '"successfully authorized with FB", 

{"access_token":"....","access_expires":1367922592459}'

I then turn the expiry seconds into a JS date object with this function:

function toDateTime(secs) {
    var t = new Date();
    t.setSeconds(secs * -1);
    return t;
}

toDateTime(1367922592459);
> Sun Jun 11 -41335 12:22:41 GMT+0100 (BST)

See here the year is showing something crazy, definitely before Facebook was invented.

So anyway, then my code passes the FB auth data to Parse.com to log in a user, and Parse.com obviously throws it back for having an invalid expiry time.

The problem is occurring on iOS and Android apps built with trigger.io v1.4.29 and v1.4.33

Note: I have a working FB javascript login on my webpage (http://wewana.com/) which is connecting to the same Facebook app and the same Parse.com application. This page is not exhibiting any problems, so it seems the FB app is fine.


Solution

  • var d = new Date(1367922592459);
    

    There you go, simple and easy.

    (Since JavaScript handles Date in milliseconds, there’s no need to do /1000 or something.)