From d4b48aef6cca3182559f7479cace3bd77cc1fb40 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 23 Mar 2023 09:18:10 +0300 Subject: auth: Don't try loading the user if no client is found Fix the bug where the system was trying to load a user from a non-existing OAuth2 client, leading to an exception. --- gn3/auth/authentication/oauth2/models/oauth2client.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gn3') diff --git a/gn3/auth/authentication/oauth2/models/oauth2client.py b/gn3/auth/authentication/oauth2/models/oauth2client.py index 5054393..da5ff75 100644 --- a/gn3/auth/authentication/oauth2/models/oauth2client.py +++ b/gn3/auth/authentication/oauth2/models/oauth2client.py @@ -137,12 +137,13 @@ def client(conn: db.DbConnection, client_id: uuid.UUID, "SELECT * FROM oauth2_clients WHERE client_id=?", (str(client_id),)) result = cursor.fetchone() the_user = user - if not bool(the_user): - try: - the_user = user_by_id(conn, result["user_id"]) - except NotFoundError as _nfe: - the_user = None if result: + if not bool(the_user): + try: + the_user = user_by_id(conn, result["user_id"]) + except NotFoundError as _nfe: + the_user = None + return Just( OAuth2Client(uuid.UUID(result["client_id"]), result["client_secret"], -- cgit v1.2.3