Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading