From 4bcbe992b132dd77ff6f61185b0ad7299a4b7863 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 13 Mar 2023 06:26:14 +0300 Subject: auth: separate user detail migration from data migration Due to the fact that the data migration requires higher privileges than the user details, separate the user details migration endpoint from the data migrations endpoint. --- gn3/auth/authentication/oauth2/models/oauth2client.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'gn3/auth/authentication/oauth2') diff --git a/gn3/auth/authentication/oauth2/models/oauth2client.py b/gn3/auth/authentication/oauth2/models/oauth2client.py index 14f4d5d..5054393 100644 --- a/gn3/auth/authentication/oauth2/models/oauth2client.py +++ b/gn3/auth/authentication/oauth2/models/oauth2client.py @@ -154,3 +154,22 @@ def client(conn: db.DbConnection, client_id: uuid.UUID, the_user))# type: ignore[arg-type] return Nothing + +def client_by_id_and_secret(conn: db.DbConnection, client_id: uuid.UUID, + client_secret: str) -> OAuth2Client: + """Retrieve a client by its ID and secret""" + with db.cursor(conn) as cursor: + cursor.execute( + "SELECT * FROM oauth2_clients WHERE client_id=? AND " + "client_secret=?", + (str(client_id), client_secret)) + row = cursor.fetchone() + if bool(row): + return OAuth2Client( + client_id, client_secret, + datetime.datetime.fromtimestamp(row["client_id_issued_at"]), + datetime.datetime.fromtimestamp(row["client_secret_expires_at"]), + json.loads(row["client_metadata"]), + user_by_id(conn, uuid.UUID(row["user_id"]))) + + raise NotFoundError(f"Could not find client with ID '{client_id}'") -- cgit v1.2.3