Skip to content

Commit

Permalink
Merge pull request #12 from TheJacksonLaboratory/G3-109-implement-the…
Browse files Browse the repository at this point in the history
…-register-sso-user-in-the-geneweaver-db-package

G3 109 implement the register sso user in the geneweaver db package
  • Loading branch information
bergsalex authored Jan 16, 2024
2 parents 5c0872c + 13b465a commit c9a533e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
22 changes: 6 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-api"
version = "0.0.1a5"
version = "0.0.1a6"
description = "description"
authors = ["Jax Computational Sciences <cssc@jax.org>"]
packages = [
Expand All @@ -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"}
Expand Down
8 changes: 8 additions & 0 deletions src/geneweaver/api/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
22 changes: 19 additions & 3 deletions src/geneweaver/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

0 comments on commit c9a533e

Please sign in to comment.