peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
284 stars 108 forks source link

Replace `:refresh_before` with `:refresh_after` #130

Closed wojtekmach closed 2 years ago

wojtekmach commented 2 years ago

Currently we have:

    * `:refresh_before` - Time in seconds before the token is about to expire
      that it is tried to be automatically refreshed. Defaults to
      `#{@refresh_before_minutes * 60}` (#{@refresh_before_minutes} minutes).
time_in_seconds = max(token.expires - System.system_time(:second) - state.refresh_before, 0)
Process.send_after(self(), :refresh, time_in_seconds * 1000)

let's switch to a much simpler:

    * `:refresh_after` - Time in milliseconds after which the token will be automatically
      refreshed. Defaults to `3_300_000` (55 minutes; 5 minutes before the token, which
      is valid for 1h, expires)
Process.send_after(self(), :refresh, state.refresh_after)