Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret the oauth expires=4 digit code upon receiving access token

In my application, certain clicks need to generate facebook post. I popup the facebook login screen if I have no access token.

Upon receiving the access token I also receive a "expires=4 digit number" at the end.

e.g. expires=3994

What does that 4 digit code mean?

Is it time in seconds after which the access token will expire?

Or is it the number of ticks after which the access token will expire.

I have seen some facebook api code which expects 12 digit expires code but I am receiving only 4 digits.

The reason I need to know if the access token has expired is that I do not want my post to fail and would like to pop up the login screen if it has expired.

like image 891
CF_Maintainer Avatar asked Nov 27 '10 15:11

CF_Maintainer


People also ask

How do you identify if the OAuth token has expired?

The OAuth 2.0 standard, RFC 6749, defines the expires_in field as the number of seconds to expiration: expires_in: RECOMMENDED. The lifetime in seconds of the access token. For example, the value "3600" denotes that the access token will expire in one hour from the time the response was generated.

What happens when OAuth token expires?

When a token has expired or has been revoked, it can no longer be used to authenticate Git and API requests. It is not possible to restore an expired or revoked token, you or the application will need to create a new token.

What does expired access token mean?

Access tokens can expire for many reasons, such as the user revoking an app, or if the authorization server expires all tokens when a user changes their password. If you make an API request and the token has expired already, you'll get back a response indicating as such.

How do I handle expired access tokens?

For example, once an access token expires, the client application could prompt the user to log in again to get a new access token. Alternatively, the authorization server could issue a refresh token to the client application that lets it replace an expired access token with a new one.


1 Answers

It is the no of seconds before expiry time. i.e.

3994 / 60 / 60 =~ 1 hour

If you see more digits (especially on canvas access link), it is probably a Unix time-stamp which you can convert to seconds easily. Also you can use below scope to get a non expiring token (but it will display an additional warning with the authorization popup window):

scope=offline_access

At my project (http://www.nbusy.com/projects/communicator) I use something like the below to know of the token expiry time:

DateTime eprityTime = DateTime.Now.AddSeconds(3994);

and compare it with DateTime.Now and close the session when token expires.

like image 80
Teoman Soygul Avatar answered Oct 29 '22 10:10

Teoman Soygul