Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
plus some todo\'s
Browse files Browse the repository at this point in the history
  • Loading branch information
cstefc committed Mar 3, 2024
1 parent 9febf10 commit 2e0cb4d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/controllers/auth/authentication_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
props: Properties = Properties()


# TODO: Should return a user object instead of a dict
def authenticate_user(ticket: str) -> dict | None:
service = props.get("session", "service")
user_information = httpx.get(f"https://login.ugent.be/serviceValidate?service={service}&ticket={ticket}"
Expand Down
5 changes: 3 additions & 2 deletions backend/controllers/auth/cookie_controller.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from fastapi import Request, Response
from starlette.responses import JSONResponse

from controllers.auth.encryption_controller import encrypt, generate_keys
from controllers.auth.encryption_controller import encrypt
from controllers.properties.Properties import Properties

props: Properties = Properties()


def set_cookies(response: Response, key: str, value: str) -> Response:
def set_session_cookies(response: JSONResponse, key: str, value: str) -> JSONResponse:
value: str = encrypt(value)
max_age: int = int(props.get("session", "max_cookie_age"))
domain: str = props.get("session", "cookie_domain")
Expand Down
10 changes: 4 additions & 6 deletions backend/routes/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from fastapi.responses import JSONResponse

from controllers.auth.authentication_controller import authenticate_user
from controllers.auth.cookie_controller import delete_cookie, set_cookies
from controllers.auth.cookie_controller import delete_cookie, set_session_cookies
from controllers.auth.encryption_controller import delete_key
from controllers.auth.login_controller import verify_session

session_router = APIRouter()


@session_router.get("/api/login")
def login(ticket: str) -> JSONResponse:
def login(ticket: str) -> Response:
"""
This function start a session for the user.
For authentication, it uses the given ticket and the UGent CAS server (https://login.ugent.be).
Expand All @@ -20,13 +20,11 @@ def login(ticket: str) -> JSONResponse:
- Valid Ticket: A JSONResponse with a user object; a cookie will be set with a session_id
- Invalid Ticket: A JSONResponse with status_code 401 and an error message
"""
user: dict = authenticate_user(ticket) # This should be a user object
user: dict = authenticate_user(ticket) # TODO: This should be a user object
if user:
response: JSONResponse = JSONResponse(content=user)
# TODO: Change mail to user id
print("here")
response = set_cookies(response, "session_id", user["mail"])
return response
return set_session_cookies(response, "session_id", user["mail"])
return JSONResponse(status_code=401, content="Invalid Ticket")


Expand Down

0 comments on commit 2e0cb4d

Please sign in to comment.