@@ -130,7 +130,7 @@ def build_refresh_request_headers(self) -> Mapping[str, Any] | None:
130
130
headers = self .get_refresh_request_headers ()
131
131
return headers if headers else None
132
132
133
- def refresh_access_token (self ) -> Tuple [str , Union [str , int ]]:
133
+ def refresh_access_token (self ) -> Tuple [str , Optional [str ]]:
134
134
"""
135
135
Returns the refresh token and its expiration datetime
136
136
@@ -147,6 +147,15 @@ def refresh_access_token(self) -> Tuple[str, Union[str, int]]:
147
147
# ----------------
148
148
# PRIVATE METHODS
149
149
# ----------------
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"
150
159
151
160
def _wrap_refresh_token_exception (
152
161
self , exception : requests .exceptions .RequestException
@@ -316,9 +325,15 @@ def _extract_token_expiry_date(self, response_data: Mapping[str, Any]) -> Any:
316
325
response_data (Mapping[str, Any]): The response data from which to extract the token_expiry_date.
317
326
318
327
Returns:
319
- str: The extracted token_expiry_date.
328
+ The extracted token_expiry_date or None if not found .
320
329
"""
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
322
337
323
338
def _find_and_get_value_from_response (
324
339
self ,
0 commit comments