Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook - when does the SDK refresh the auth token?

According to the Facebook docs, mobile SDKs generate long lived tokens which are refreshed once per day when the person using your app makes a request to the Facebook servers. For the javascript SDK, short-lived tokens are generated and are refreshed periodically.

I'm curious as to what is meant by "the person using your app makes a request to the Facebook servers". Which calls specifically will cause the token to be refreshed? Or more importantly, which calls won't? Is it enough to check the login status or is something more active required? What I'm really interested in is keeping the token alive (or getting a new one) without sending the user back through the login flow, or doing anything that's particularly active with Facebooks APIs.

Thanks!

like image 585
Jordan Avatar asked May 08 '15 16:05

Jordan


People also ask

Does Facebook use refresh token?

Facebook does not provide a refresh token. Facebook provides two kinds of access tokens, Short lived access token: A token that is expired after a short period of time (about 2 hours). Short lived access tokens are usually used on web clients.

How do I refresh my authentication token?

To use the refresh token, make a POST request to the service's token endpoint with grant_type=refresh_token , and include the refresh token as well as the client credentials if required.

How long do Facebook access tokens last?

When your app uses Facebook Login to authenticate someone, it receives a User access token. If your app uses one of the Facebook SDKs, this token lasts for about 60 days. However, the SDKs automatically refresh the token whenever the person uses your app, so the tokens expire 60 days after last use.

How do I know if my Facebook access token has expired?

Basically, you can subscribe to updates that will tell you 1) if the user removed the app or 2) if the user removed permissions. You could use this to store the current permissions of the faceboook user. This way, if the user removed your app you would know that the access token is expired.


1 Answers

According to Facebook SDK Docu

Once a token expires ("auto" extend of Facebook SDK Token)

At any point, you can generate a new long-lived token by sending the person back to the login flow used by your web app - note that the person will not actually need to login again, they have already authorized your app, so they will immediately redirect back to your app from the login flow with a refreshed token

THERE IS no keep alive functionality in Facebook SDK.

User access tokens come in two forms: short-lived tokens and long-lived tokens. Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days. You should not depend on these lifetimes remaining the same - the lifetime may change without warning or expire early. See more under handling errors.

long-lived = 60 days

Short-lived = 2 hour

Also according to Facebook SDK Docu

Mobile apps that use Facebook's mobile SDKs get long-lived tokens.

Once you force a user for a new oAuth/login, he will receive a new token. The old one will not expire. You are able to check the loginStatusby FB.getLoginStatus. No need for a keep alive.

like image 194
lin Avatar answered Oct 05 '22 23:10

lin