From 125a81de848b7eef8cb572108c32ae1c73b3b741 Mon Sep 17 00:00:00 2001 From: Niccari Date: Thu, 20 Jun 2024 14:05:09 +0900 Subject: [PATCH] fix: refresh access token if expired --- pyfcm/baseapi.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyfcm/baseapi.py b/pyfcm/baseapi.py index 7fb334f..31f220b 100644 --- a/pyfcm/baseapi.py +++ b/pyfcm/baseapi.py @@ -85,7 +85,12 @@ def requests_session(self): self.thread_local.requests_session = requests.Session() self.thread_local.requests_session.mount("http://", adapter) self.thread_local.requests_session.mount("https://", adapter) + self.thread_local.token_expiry = 0 + + current_timestamp = time.time() + if self.thread_local.token_expiry < current_timestamp: self.thread_local.requests_session.headers.update(self.request_headers()) + self.thread_local.token_expiry = current_timestamp + 1800 return self.thread_local.requests_session def send_request(self, payload=None, timeout=None):