From 2579ed2bc8f801bc0b4cf9c1363963823ef705e7 Mon Sep 17 00:00:00 2001 From: rikuke <33894149+rikuke@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:14:44 +0200 Subject: [PATCH] fix: token expiry based on refresh token expiry (#3603) --- .../benefit/applications/services/ahjo_authentication.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/benefit/applications/services/ahjo_authentication.py b/backend/benefit/applications/services/ahjo_authentication.py index 16347e58b1..3a5a28efc8 100644 --- a/backend/benefit/applications/services/ahjo_authentication.py +++ b/backend/benefit/applications/services/ahjo_authentication.py @@ -14,13 +14,14 @@ AUTH_TOKEN_GRANT_TYPE = "authorization_code" REFRESH_TOKEN_GRANT_TYPE = "refresh_token" +REFRESH_TOKEN_EXPIRES_IN = 1296000 # 15 days @dataclass class AhjoToken: access_token: str = "" refresh_token: str = "" - expires_in: int = (0,) + expires_in: int = REFRESH_TOKEN_EXPIRES_IN # 15 days created_at: datetime = (None,) def expiry_datetime(self) -> datetime: @@ -30,7 +31,7 @@ def has_expired(self) -> bool: return self.expiry_datetime() < datetime.now(timezone.utc) def __str__(self) -> str: - return f"Ahjo access token, expiry date: {self.expiry_datetime()}" + return f"Ahjo access token, refresh_token expiry date: {self.expiry_datetime()}" class AhjoConnector: @@ -111,13 +112,12 @@ def do_token_request(self, payload: Dict[str, str]) -> Union[AhjoToken, None]: if response.status_code == 200: # Extract the access token from the JSON response access_token = response.json().get("access_token", "") - expires_in = int(response.json().get("expires_in", "")) refresh_token = response.json().get("refresh_token", "") token_from_api = AhjoToken( access_token=access_token, refresh_token=refresh_token, - expires_in=expires_in, + expires_in=REFRESH_TOKEN_EXPIRES_IN, ) return self.create_token(token_from_api)