@@ -130,7 +130,7 @@ def build_refresh_request_headers(self) -> Mapping[str, Any] | None:
130130 headers = self .get_refresh_request_headers ()
131131 return headers if headers else None
132132
133- def refresh_access_token (self ) -> Tuple [str , Union [str , int ]]:
133+ def refresh_access_token (self ) -> Tuple [str , Optional [str ]]:
134134 """
135135 Returns the refresh token and its expiration datetime
136136
@@ -147,6 +147,15 @@ def refresh_access_token(self) -> Tuple[str, Union[str, int]]:
147147 # ----------------
148148 # PRIVATE METHODS
149149 # ----------------
150+
151+ def _default_token_expiry_date (self ) -> str :
152+ """
153+ Returns the default token expiry date
154+ """
155+ if self .token_expiry_is_time_of_expiration :
156+ return str (ab_datetime_now () + timedelta (hours = 1 ))
157+ else :
158+ return "3600"
150159
151160 def _wrap_refresh_token_exception (
152161 self , exception : requests .exceptions .RequestException
@@ -316,9 +325,15 @@ def _extract_token_expiry_date(self, response_data: Mapping[str, Any]) -> Any:
316325 response_data (Mapping[str, Any]): The response data from which to extract the token_expiry_date.
317326
318327 Returns:
319- str: The extracted token_expiry_date.
328+ The extracted token_expiry_date or None if not found .
320329 """
321- return self ._find_and_get_value_from_response (response_data , self .get_expires_in_name ())
330+ expires_in = self ._find_and_get_value_from_response (response_data , self .get_expires_in_name ())
331+ # If the access token expires in is None, we do not know when the token will expire
332+ # 1 hour was chosen as a middle ground to avoid unnecessary frequent refreshes and token expiration
333+ if expires_in is None :
334+ return self ._default_token_expiry_date ()
335+ else :
336+ return expires_in
322337
323338 def _find_and_get_value_from_response (
324339 self ,
0 commit comments