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

Commit

Permalink
added docs to authentication controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cstefc committed Mar 10, 2024
1 parent 41d5ebb commit 02cf78d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions backend/controllers/auth/authentication_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

import httpx
from defusedxml.ElementTree import fromstring
from sqlalchemy.orm import Session
Expand All @@ -15,6 +13,15 @@

# TODO: Should return a user object instead of a dict
def authenticate_user(session: Session, ticket: str) -> UserDataclass | None:
"""
This function will authenticate the user.
If the use doesn't yet exist in the database, it will create an entry.
a
:param session: Session with the database
:param ticket: A ticket from login.ugent.be/login?service=https://localhost:8080/login
:return: None if the authentication failed, user: UseDataclass is the authentication was successful
"""
service = props.get("session", "service")
user_information = httpx.get(f"https://login.ugent.be/serviceValidate?service={service}&ticket={ticket}")
user_dict: dict | None = parse_cas_xml(user_information.text)
Expand All @@ -32,6 +39,14 @@ def authenticate_user(session: Session, ticket: str) -> UserDataclass | None:


def parse_cas_xml(xml: str) -> dict | None:
"""
The authentication with CAS returns a xml-object.
This function will read the necessary attributes and return them in a dictionary.
:param xml: str: response xml from CAS
:return: None if the authentication failed else dict
"""

namespace = "{http://www.yale.edu/tp/cas}"
root = fromstring(xml)
if root.find(f"{namespace}authenticationSuccess"):
Expand Down

0 comments on commit 02cf78d

Please sign in to comment.