Skip to content

Commit f30200a

Browse files
committed
Possible fix access token handling
1 parent 427101c commit f30200a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lghorizon/lghorizon_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def __init__(
491491
refresh_token: str = "",
492492
username: str = "",
493493
password: str = "",
494+
token_refresh_callback: Callable[str, None] | None = None, # pyright: ignore[reportInvalidTypeForm]
494495
) -> None:
495496
"""Initialize the auth with refresh token."""
496497
self._websession = websession
@@ -504,7 +505,7 @@ def __init__(
504505
self._host = COUNTRY_SETTINGS[country_code]["api_url"]
505506
self._use_refresh_token = COUNTRY_SETTINGS[country_code]["use_refreshtoken"]
506507
self._service_config = None
507-
self._token_refresh_callback = None
508+
self._token_refresh_callback = token_refresh_callback
508509

509510
@property
510511
def websession(self) -> ClientSession:
@@ -624,6 +625,10 @@ async def fetch_access_token(self) -> None:
624625
self._token_refresh_callback(self.refresh_token)
625626
self.username = auth_json["username"]
626627
self.token_expiry = auth_json["refreshTokenExpiry"]
628+
_LOGGER.debug(
629+
"Access token and refresh token fetched. refresh token expires: %s",
630+
datetime.fromtimestamp(int(self.token_expiry)).ctime(),
631+
)
627632

628633
@backoff.on_exception(backoff.expo, LGHorizonApiConnectionError, max_tries=3)
629634
async def request(self, host: str, path: str, params=None, **kwargs) -> Any:

0 commit comments

Comments
 (0)