Skip to content

Commit

Permalink
Change to :os.system_time to avoid using invalid time while checking …
Browse files Browse the repository at this point in the history
…token expiry (#169)
  • Loading branch information
rajrajhans authored Mar 17, 2024
1 parent 0417723 commit 4b88576
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/goth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ defmodule Goth do
]

defp read_from_ets(name) do
now = System.system_time(:second)
now = System.os_time(:second)

case Registry.lookup(@registry, name) do
[{_pid, %Token{expires: expires}}] when expires <= now -> nil
Expand Down Expand Up @@ -267,7 +267,7 @@ defmodule Goth do

defp store_and_schedule_refresh(state, token) do
put(state.name, token)
time_in_seconds = max(token.expires - System.system_time(:second) - state.refresh_before, 0)
time_in_seconds = max(token.expires - System.os_time(:second) - state.refresh_before, 0)

Process.send_after(self(), :refresh, time_in_seconds * 1000)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/goth/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ defmodule Goth.Token do

defp build_token(%{"access_token" => _} = attrs) do
%__MODULE__{
expires: System.system_time(:second) + attrs["expires_in"],
expires: System.os_time(:second) + attrs["expires_in"],
token: attrs["access_token"],
type: attrs["token_type"],
scope: attrs["scope"],
Expand Down

0 comments on commit 4b88576

Please sign in to comment.