0

How much the maximal lifetime of the Google drive OAuth2 TokenResponse file?

My target:
If the lifetime is perpetual, I can hard code it (its first state after the authority in browser) to my app, and I can write it to disk for one moment only when GoogleWebAuthorizationBroker.AuthorizeAsync use it.
My oldest token file is 6 days old and automatically refreshed (as it's older than 1 hour).
But if the file is for example 6 years old whether is it automatically refreshed too?

Thanks in advance!

VB.NET code:

'prerequisites: create oauth2 client ids for gmail user and download file client_secret.json
Dim GooSvc As Google.Apis.Drive.v3.DriveService
Dim UserInfo As Google.Apis.Auth.OAuth2.UserCredential
Dim Stream1 = New System.IO.MemoryStream(New System.Text.UTF8Encoding().GetBytes("content_of_client_secret.json"))
UserInfo = Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
    Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(Stream1).Secrets,
    New String() {"https://www.googleapis.com/auth/drive"},
    "user1",
    System.Threading.CancellationToken.None,
    New Google.Apis.Util.Store.FileDataStore("d:\temp", True)).Result
GooSvc = New Google.Apis.Drive.v3.DriveService(New Google.Apis.Services.BaseClientService.Initializer() With {.HttpClientInitializer = UserInfo})

After this, the token file d:\temp\Google.Apis.Auth.OAuth2.Responses.TokenResponse-user1:
- created automatically (after the authority in browser) if it's not exists
- refreshed automatically if it's out of date (after 1 hour)
- nothing happens with it, if it's "fresh" (within 1 hour)

Example content of the token file:

{"access_token":"ya29.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","token_type":"Bearer","expires_in":3600,"refresh_token":"1/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","scope":"https://www.googleapis.com/auth/drive","Issued":"2019-06-02T13:21:54.775+02:00","IssuedUtc":"2019-06-02T11:21:54.775Z"}

UPDATE:
The answer is:
https://developers.google.com/identity/protocols/OAuth2#expiration

LPC65
  • 11
  • 4
  • Possible duplicate of [OAuth2 and Google API: Access token expiration time?](https://stackoverflow.com/questions/13851157/oauth2-and-google-api-access-token-expiration-time) – Jessica Rodriguez Jun 04 '19 at 07:10
  • Thank you for your help! In the linked question's main answer say "This refresh token never expires". There are even more accurate info in this question and its answer: [link](https://stackoverflow.com/questions/38776704/implementing-oauth-refresh-tokens-that-never-expire) [link2](https://developers.google.com/identity/protocols/OAuth2#expiration) The last link lastly answer to my question. Thank you and to referred question's participants! – LPC65 Jun 04 '19 at 19:08

0 Answers0