diff options
author | Frederick Muriuki Muriithi | 2023-05-29 14:56:24 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-05-29 14:56:24 +0300 |
commit | 2aa7abf383df814f24c88beea733c324cda682d0 (patch) | |
tree | 89a9297a8854aa2759f9bd7c3e8217cd3d23d163 /gn3/auth/authentication/users.py | |
parent | 25c6da03e1639895f0051e8be6502762beefde0b (diff) | |
download | genenetwork3-2aa7abf383df814f24c88beea733c324cda682d0.tar.gz |
auth: Enable registration of OAuth2 clients
Add UI and code to enable the administrative user to register new OAuth2
clients that can access the API server.
Diffstat (limited to 'gn3/auth/authentication/users.py')
-rw-r--r-- | gn3/auth/authentication/users.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gn3/auth/authentication/users.py b/gn3/auth/authentication/users.py index 17e89ae..8b4f115 100644 --- a/gn3/auth/authentication/users.py +++ b/gn3/auth/authentication/users.py @@ -48,6 +48,13 @@ def user_by_id(conn: db.DbConnection, user_id: UUID) -> User: raise NotFoundError(f"Could not find user with ID {user_id}") +def same_password(password: str, hashed: str) -> bool: + """Check that `raw_password` is hashed to `hash`""" + try: + return hasher().verify(hashed, password) + except VerifyMismatchError as _vme: + return False + def valid_login(conn: db.DbConnection, user: User, password: str) -> bool: """Check the validity of the provided credentials for login.""" with db.cursor(conn) as cursor: @@ -61,10 +68,7 @@ def valid_login(conn: db.DbConnection, user: User, password: str) -> bool: if row is None: return False - try: - return hasher().verify(row["password"], password) - except VerifyMismatchError as _vme: - return False + return same_password(password, row["password"]) def save_user(cursor: db.DbCursor, email: str, name: str) -> User: """ |