The condition if expires_at and time.time() >= (expires_at - 60) treats expires_at = 0 as falsy, which means if a token has no expiration or expires_at is missing/0, the function returns access_token without attempting refresh even if it's invalid. Consider handling the case where expires_at is 0 explicitly, or checking if the token has required fields before returning.
expires_at = token.get("expires_at")
# If expires_at is missing or 0, treat token as expired and refresh
if not expires_at or time.time() >= (expires_at - 60):
LOGGER.debug("Token expired, missing expiration, or about to expire, refreshing")
Originally posted by @Copilot in #6 (comment)