diff --git a/poetry.lock b/poetry.lock index dc67b0d..cd03643 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "anyio" @@ -503,13 +503,13 @@ pydantic = {version = ">=1.10.7,<2.0.0", extras = ["dotenv"]} [[package]] name = "geneweaver-db" -version = "0.2.0a0" +version = "0.2.1a2" description = "Database Interaction Services for GeneWeaver" optional = false python-versions = ">=3.9,<4.0" files = [ - {file = "geneweaver_db-0.2.0a0-py3-none-any.whl", hash = "sha256:9d13bac879d68d3e471e1f795b9f0f71602f61335a1392c60bae33b150f42e6e"}, - {file = "geneweaver_db-0.2.0a0.tar.gz", hash = "sha256:a595260738bbf85a5d880f9b4c57032b98c5369ecd10a9623524b1b2f737c01e"}, + {file = "geneweaver_db-0.2.1a2-py3-none-any.whl", hash = "sha256:1312c06cfd3ffebfb4af58cc4e9e7f42b303fb6e42aeaa177d2a5038ddeb7741"}, + {file = "geneweaver_db-0.2.1a2.tar.gz", hash = "sha256:349f83247cc6f9e4eeb75e7ed0e071706fdcc796fbab02c9393020b4807d1705"}, ] [package.dependencies] @@ -731,16 +731,6 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -989,8 +979,8 @@ files = [ [package.dependencies] numpy = [ {version = ">=1.20.3", markers = "python_version < \"3.10\""}, + {version = ">=1.21.0", markers = "python_version >= \"3.10\""}, {version = ">=1.23.2", markers = "python_version >= \"3.11\""}, - {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, ] python-dateutil = ">=2.8.2" pytz = ">=2020.1" @@ -1894,4 +1884,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "0ea43acd3f3f058a7640f58d5183d834b88b2da78c07d593beb572892d3d59b5" +content-hash = "cae6f54e57292b2269f04c5841188588494b5c95b06bd9bc90d5680113aceac8" diff --git a/pyproject.toml b/pyproject.toml index 79e2618..58a1596 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "geneweaver-api" -version = "0.0.1a5" +version = "0.0.1a6" description = "description" authors = ["Jax Computational Sciences "] packages = [ @@ -10,10 +10,10 @@ packages = [ [tool.poetry.dependencies] python = "^3.9" -geneweaver-core = "^0.8.0a0" +geneweaver-core = "^0.8.0a1" fastapi = {extras = ["all"], version = "^0.99.1"} uvicorn = {extras = ["standard"], version = "^0.24.0"} -geneweaver-db = "^0.2.0a0" +geneweaver-db = "^0.2.1a2" psycopg-pool = "^3.1.7" requests = "^2.31.0" python-jose = {extras = ["cryptography"], version = "^3.3.0"} diff --git a/src/geneweaver/api/core/exceptions.py b/src/geneweaver/api/core/exceptions.py index 997412d..684140c 100644 --- a/src/geneweaver/api/core/exceptions.py +++ b/src/geneweaver/api/core/exceptions.py @@ -10,6 +10,14 @@ def __init__(self, **kwargs) -> None: # noqa: ANN003 super().__init__(401, **kwargs) +class AuthenticationMismatch(HTTPException): + """Exception for mismatched authentication.""" + + def __init__(self, **kwargs) -> None: # noqa: ANN003 + """Initialize the exception.""" + super().__init__(401, **kwargs) + + class Auth0UnauthorizedException(HTTPException): """Exception for unauthorized requests.""" diff --git a/src/geneweaver/api/dependencies.py b/src/geneweaver/api/dependencies.py index 774f4cd..c2e7a1a 100644 --- a/src/geneweaver/api/dependencies.py +++ b/src/geneweaver/api/dependencies.py @@ -5,8 +5,9 @@ import psycopg from fastapi import Depends from geneweaver.api.core.config import settings +from geneweaver.api.core.exceptions import AuthenticationMismatch from geneweaver.api.core.security import Auth0, UserInternal -from geneweaver.db.user import by_sso_id +from geneweaver.db import user as db_user from psycopg.rows import dict_row auth = Auth0( @@ -30,6 +31,21 @@ def full_user( cursor: Cursor = Depends(cursor), user: UserInternal = Depends(auth.get_user_strict), ) -> UserInternal: - """Get the full user object.""" - user.id = by_sso_id(cursor, user.sso_id)[0]["usr_id"] + """Get the full user object.""" "" + try: + user.id = db_user.by_sso_id_and_email(cursor, user.sso_id, user.email)[0][ + "usr_id" + ] + except IndexError as e: + if db_user.sso_id_exists(cursor, user.sso_id): + raise AuthenticationMismatch( + detail="Email and SSO ID Mismatch. Please contact and administrator." + ) from e + elif db_user.email_exists(cursor, user.email): + user.id = db_user.link_user_id_with_sso_id(cursor, user.id, user.sso_id) + else: + user.id = db_user.create_sso_user( + cursor, user.name, user.email, user.sso_id + ) + yield user