@@ -130,17 +130,17 @@ 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 , Union [str , int , None ]]:
134
134
"""
135
- Returns the refresh token and its expiration datetime
135
+ Returns the refreshed access token and its expiration datetime
136
136
137
137
:return: a tuple of (access_token, token_lifespan)
138
138
"""
139
139
response_json = self ._make_handled_request ()
140
140
self ._ensure_access_token_in_response (response_json )
141
141
142
142
return (
143
- self ._extract_access_token (response_json ),
143
+ str ( self ._extract_access_token (response_json ) ),
144
144
self ._extract_token_expiry_date (response_json ),
145
145
)
146
146
@@ -184,7 +184,7 @@ def _wrap_refresh_token_exception(
184
184
),
185
185
max_time = 300 ,
186
186
)
187
- def _make_handled_request (self ) -> Any :
187
+ def _make_handled_request (self ) -> Mapping [ str , Any ] :
188
188
"""
189
189
Makes a handled HTTP request to refresh an OAuth token.
190
190
@@ -292,41 +292,44 @@ def _extract_access_token(self, response_data: Mapping[str, Any]) -> Any:
292
292
response_data (Mapping[str, Any]): The response data from which to extract the access token.
293
293
294
294
Returns:
295
- str: The extracted access token.
295
+ str: The extracted access token or None if not found .
296
296
"""
297
- return self ._find_and_get_value_from_response (response_data , self .get_access_token_name ())
297
+ access_token = self ._find_and_get_value_from_response (response_data , self .get_access_token_name ())
298
+ return str (access_token ) if access_token is not None else None
298
299
299
- def _extract_refresh_token (self , response_data : Mapping [str , Any ]) -> Any :
300
+ def _extract_refresh_token (self , response_data : Mapping [str , Any ]) -> str | None :
300
301
"""
301
302
Extracts the refresh token from the given response data.
302
303
303
304
Args:
304
305
response_data (Mapping[str, Any]): The response data from which to extract the refresh token.
305
306
306
307
Returns:
307
- str: The extracted refresh token.
308
+ str: The extracted refresh token or None if not found .
308
309
"""
309
- return self ._find_and_get_value_from_response (response_data , self .get_refresh_token_name ())
310
+ refresh_token = self ._find_and_get_value_from_response (response_data , self .get_refresh_token_name ())
311
+ return str (refresh_token ) if refresh_token is not None else None
310
312
311
- def _extract_token_expiry_date (self , response_data : Mapping [str , Any ]) -> Any :
313
+ def _extract_token_expiry_date (self , response_data : Mapping [str , Any ]) -> str | None :
312
314
"""
313
315
Extracts the token_expiry_date, like `expires_in` or `expires_at`, etc from the given response data.
314
316
315
317
Args:
316
318
response_data (Mapping[str, Any]): The response data from which to extract the token_expiry_date.
317
319
318
320
Returns:
319
- str: The extracted token_expiry_date.
321
+ str: The extracted token_expiry_date or None if not found .
320
322
"""
321
- return self ._find_and_get_value_from_response (response_data , self .get_expires_in_name ())
323
+ token_expiry_date = self ._find_and_get_value_from_response (response_data , self .get_expires_in_name ())
324
+ return str (token_expiry_date ) if token_expiry_date is not None else None
322
325
323
326
def _find_and_get_value_from_response (
324
327
self ,
325
328
response_data : Mapping [str , Any ],
326
329
key_name : str ,
327
330
max_depth : int = 5 ,
328
331
current_depth : int = 0 ,
329
- ) -> Any :
332
+ ) -> Any | None :
330
333
"""
331
334
Recursively searches for a specified key in a nested dictionary or list and returns its value if found.
332
335
0 commit comments