Skip to content

Commit

Permalink
fix: token expiry based on refresh token expiry (#3603)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Nov 27, 2024
1 parent 96dd4f3 commit 2579ed2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/benefit/applications/services/ahjo_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2579ed2

Please sign in to comment.