Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions auth/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,20 +866,31 @@ async def get_userinfo(request: web.Request, auth_token: str) -> UserData:
flow_client = request.app[AppKeys.FLOW_CLIENT]
client_session = request.app[AppKeys.CLIENT_SESSION]

db = request.app[AppKeys.DB]
userdata = await get_userinfo_from_hail_session_id(request, auth_token)
if userdata:
db = request.app[AppKeys.DB]
await db.just_execute("UPDATE sessions SET created = NOW() WHERE session_id = %s", (auth_token,))
else:
hailctl_oauth_client = request.app[AppKeys.HAILCTL_CLIENT_CONFIG]
uid = await flow_client.get_identity_uid_from_access_token(
client_session, auth_token, oauth2_client=hailctl_oauth_client
)
if uid:
userdata = await get_userinfo_from_login_id_or_hail_identity_id(request, uid)

if userdata:
if userdata['state'] == 'active':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we hit this then I assume we got some non-None thing back from either get_userinfo_from_login_id_or_hail_identity_id() or get_userinfo_from_hail_session_id()? It looks like both of those functions already check/query for users.state = 'active', so it may be alright to drop this check.

current_uid = userdata['id']
await db.execute_update(
"""
UPDATE users
SET last_activated = CURRENT_TIMESTAMP(3)
WHERE id = %s;
""",
current_uid,
)
return userdata

hailctl_oauth_client = request.app[AppKeys.HAILCTL_CLIENT_CONFIG]
uid = await flow_client.get_identity_uid_from_access_token(
client_session, auth_token, oauth2_client=hailctl_oauth_client
)
if uid:
return await get_userinfo_from_login_id_or_hail_identity_id(request, uid)

raise web.HTTPUnauthorized()


Expand Down Expand Up @@ -929,17 +940,6 @@ async def get_userinfo_from_hail_session_id(request: web.Request, session_id: st
if len(users) != 1:
return None

if users[0]['state'] == 'active':
current_uid = users[0]['id']
await db.execute_update(
"""
UPDATE users
SET last_activated = CURRENT_TIMESTAMP(3)
WHERE id = %s;
""",
current_uid,
)

return typing.cast(UserData, users[0])


Expand Down