peburrows / goth

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

change to :os.system_time to avoid using invalid time while checking token expiry #169

Closed rajrajhans closed 8 months ago

rajrajhans commented 8 months ago

currently System.system_time is used to get current time, which is used for checking whether the token is expired. System.system_time is affected by time warp

note that the lag between :os.system_time and System.system_time was a lot in my case

iex(..)11> :os.system_time(:second) - System.system_time(:second)
96776

due to this, Goth.fetch returns expired tokens which are no longer valid. the only solution when this happens is to reboot the system. This PR changes it to use :os.system_time.

wojtekmach commented 8 months ago

Thank you for the PR. We had a similar PR before, https://github.com/peburrows/goth/pull/158, and I didn't realise there were leftovers. Could you while at it change all the other System.system_time occurrences when it makes sense? Also could you use System.os_time instead? Thank you!

rajrajhans commented 8 months ago

hey @wojtekmach, I have updated the PR. Thanks for the quick response!

wojtekmach commented 8 months ago

Thanks!