From 4b885767502632c4f347953933afa388858f0085 Mon Sep 17 00:00:00 2001 From: Raj Rajhans Date: Sun, 17 Mar 2024 20:33:20 +0530 Subject: [PATCH] Change to :os.system_time to avoid using invalid time while checking token expiry (#169) --- lib/goth.ex | 4 ++-- lib/goth/token.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/goth.ex b/lib/goth.ex index 787faf0..6e41f22 100644 --- a/lib/goth.ex +++ b/lib/goth.ex @@ -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 @@ -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 diff --git a/lib/goth/token.ex b/lib/goth/token.ex index 17e6912..8b52bce 100644 --- a/lib/goth/token.ex +++ b/lib/goth/token.ex @@ -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"],