question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access token experation testing

See original GitHub issue

I am in the process of upgrading my current application. While upgrading i have also been optimizing the code a little. I noticed something that made me question my design. Since my application is loosely based upon the Client library I thought i would check and see how we are doing it here. Turns out client library is doing the same. My Question is should it?

Observation:

As you probably know the Google Auth servers are nice and return 3600 for “expires_in” which is basically one hour in seconds. We know that the access token expires after an hour this is a fact, wouldn’t be surprised if its not in the RFC for Oauth but its been a while since i have read that.

This is what I have always done in the past.

  1. Turn it into a date time when I get the response back.
  2. Test before each call to see if its expired.
  3. 5 minutes before expire refresh it.

This appears to be in line with what the client library is currently doing. However the client library appears to wait until there is only one minute left on the access token and then refreshes it.

Is this really the right way to go? Assuming most APIs let you run at a max speed of 10 requests a second.

((10 * 60) 60) = 36,000

So I am potentially comparing the access token expire time with the current time 36,000 times. When you add in the fact that my application will very rarely run more then an hour. My guess would be only 10% of calls will run that long. Is this a waste? Should I just be letting the access token expire then handling that error?

I am not putting this on StackOverflow because its probably primarily opinion-based as its basically design related. However being that the client library is running this check I thought maybe you guys might have an opinion as to why the client library is checking first rather then just letting it expire.

I also realize that testing a date against itself is probably very minor when it comes to code optimization; its more the principle of the thing. I don’t like to be doing work that I don’t really need to be doing.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jskeetcommented, Nov 2, 2016

Thanks 😃

0reactions
LindaLawtoncommented, Nov 2, 2016

@jskeet feel free to close this

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I test refreshing my google access token using a ...
If you're looking to test your code, you don't actually need to invalidate or expire the access token. Simply make a (say) Drive...
Read more >
Get Management API Access Tokens for Testing
By default, the token has an expiration time of 86400 seconds, which is 24 hours. After that period, the token expires and can...
Read more >
How to manually expire token in order to test token renewal?
The only way I have been able to do this is to simply wait 10 minutes between each test. Is there a way...
Read more >
Checking if the access token is valid or expired
The use case would be if there is only 1 second before the expiration time the client will mark it as valid, but...
Read more >
Access Token Lifetime - OAuth 2.0 Simplified
Typically services using this method will issue access tokens that last anywhere from several hours to a couple weeks. When the service issues ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found