Skip to content

Commit

Permalink
fix credential refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonDane committed May 22, 2024
1 parent 56c1d01 commit bb0ecd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions fennel_invest_api/fennel.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ def _clear_credentials(self):
self.ID_Token = None

def login(self, email, wait_for_code=True, code=None):
# If creds exist, then see if they are valid
if self.Bearer is not None:
if self._verify_login():
return True
self._clear_credentials()
# If creds exist, check if they are valid/try to refresh
if self.Bearer is not None and self._verify_login():
return True
if code is None:
url = self.endpoints.retrieve_bearer_url()
payload = {
Expand Down Expand Up @@ -113,7 +111,6 @@ def login(self, email, wait_for_code=True, code=None):
self.Refresh = response["refresh_token"]
self.ID_Token = response["id_token"]
self.refresh_token()
self._save_credentials()
self.get_account_ids()
return True

Expand All @@ -133,6 +130,7 @@ def refresh_token(self):
self.Bearer = response["access_token"]
self.Refresh = response["refresh_token"]
self.ID_Token = response["id_token"]
self._save_credentials()
return response

def _verify_login(self):
Expand All @@ -142,10 +140,13 @@ def _verify_login(self):
return True
except Exception:
try:
# Try to refresh token
self.refresh_token()
self.get_account_ids()
return True
except Exception:
# Unable to refresh, clear credentials
self._clear_credentials()
return False

@check_login
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="fennel_invest_api",
version="1.0.5",
version="1.0.6",
description="Unofficial Fennel.com Invest API written in Python Requests",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit bb0ecd8

Please sign in to comment.