Skip to content

Commit

Permalink
Do not try to refresh non Check-in users
Browse files Browse the repository at this point in the history
  • Loading branch information
enolfc committed Jan 8, 2024
1 parent 2a4cf18 commit 9db69af
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions egi_notebooks_hub/egiauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,16 @@ async def authenticate(self, handler, data=None):
# Refresh auth data for user
async def refresh_user(self, user, handler=None):
auth_state = await user.get_auth_state()
if not auth_state or "refresh_token" not in auth_state:
self.log.warning("Cannot refresh user info without refresh token")
return False
if not auth_state:
self.log.debug("No auth state, assuming user is not managed with Check-in")
return True

access_token = auth_state.get('access_token', None)
refresh_token = auth_state.get('refresh_token', None)

if not access_token:
self.log.debug("No access token, assuming user is not managed with Check-in")
return True

now = time.time()
refresh_info = auth_state.get("refresh_info", {})
Expand All @@ -132,6 +139,10 @@ async def refresh_user(self, user, handler=None):
self.log.debug("Credentials still valid, time left: %f", time_left)
return True

if not refresh_token:
self.log.debug("No refresh token, cannot refresh user")
return False

# performing the refresh token call
self.log.debug("Perform refresh call to Check-in")
http_client = AsyncHTTPClient()
Expand All @@ -144,7 +155,7 @@ async def refresh_user(self, user, handler=None):
client_id=self.client_id,
client_secret=self.client_secret,
grant_type="refresh_token",
refresh_token=auth_state["refresh_token"],
refresh_token=refresh_token,
scope=" ".join(self.scope),
)
)
Expand Down

0 comments on commit 9db69af

Please sign in to comment.