Search code examples
oauthgoogle-apiin-app-purchasegoogle-oauth

What is the incentive for (re)using Google access token rather than asking a new one every time?


I've been using Google refresh/access token in my in-app purchase verification on server-side.

When refreshing the token, I get a new access token, valid for 3600 secs. Why can't I just re-ask for a new access token when needed, rather than storing and re-using it?


Solution

  • Why can't I just re-ask for a new access token when needed, rather than storing and re-using it?

    Simple answer is you can. Technically speaking you could just ask for a new access token every time you want to make a request. As long as you store your refresh token you will then be able to access the server when ever you need.

    I think a better question would be why wouldn't you want to. Well if you are using an application and that application is running for 30 minutes there is really no reason to request a new access token when you can just use the one that was returned to you the first time. You are making an extra round trip to the server with ever request you make if you are also requesting an access token first.

    However if you have an application that say runs once every five minutes as a cron job or a windows service well then one could argue that its a pain trying to keep track of it. Actually its not you could just add a date to when it was generated and check the date before using it.

    Now google is not going to stop you from requesting a new one every time so feel free. However I cant remember if Google gives you a new access token or if they just return the same one that they generated last time. If they generate a new one every time. Remember that they will all work for an hour so dont leave them laying around.