diff options
author | Frederick Muriuki Muriithi | 2023-03-13 06:26:14 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-03-13 06:26:14 +0300 |
commit | 4bcbe992b132dd77ff6f61185b0ad7299a4b7863 (patch) | |
tree | 77a205b39f6b093f5bbff05847d90f1d8a164bc6 /gn3/auth/authentication/oauth2/models/oauth2client.py | |
parent | 3dee24dc1e05893b49ace052ab61899e49a03bb7 (diff) | |
download | genenetwork3-4bcbe992b132dd77ff6f61185b0ad7299a4b7863.tar.gz |
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.
Diffstat (limited to 'gn3/auth/authentication/oauth2/models/oauth2client.py')
-rw-r--r-- | gn3/auth/authentication/oauth2/models/oauth2client.py | 19 |
1 files changed, 19 insertions, 0 deletions
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}'") |