Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G3 109 implement the register sso user in the geneweaver db package #12

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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