title: Google drive OAuth2: maximal lifetime of TokenResponse file?
body: <p>How much the maximal lifetime of the Google drive OAuth2 TokenResponse file?</p>
  
  <p>My target:<br>
  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 <code>GoogleWebAuthorizationBroker.AuthorizeAsync</code> use it.<br>
  My oldest token file is 6 days old and automatically refreshed (as it's older than 1 hour).<br>
  But if the file is for example 6 years old whether is it automatically refreshed too?</p>
  
  <p>Thanks in advance!</p>
  
  <p>VB.NET code:</p>
  
  <pre><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})
  </code></pre>
  
  <p>After this, the token file <code>d:\temp\Google.Apis.Auth.OAuth2.Responses.TokenResponse-user1</code>:<br>
  - created automatically (after the authority in browser) if it's not exists<br>
  - refreshed automatically if it's out of date (after 1 hour)<br>
  - nothing happens with it, if it's "fresh" (within 1 hour)</p>
  
  <p>Example content of the token file:</p>
  
  <pre><code>{"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"}
  </code></pre>
  
  <p><strong>UPDATE:</strong><br>
  The answer is:<br>
  <a href="https://developers.google.com/identity/protocols/OAuth2#expiration" rel="nofollow noreferrer">https://developers.google.com/identity/protocols/OAuth2#expiration</a></p>