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

Fix authentication bugs #226

Merged
merged 9 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions backend/project/endpoints/authentication/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def microsoft_authentication():
res = requests.post(f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token",
data=data,
timeout=5)
if res.status_code != 200:
abort(make_response((
{"message":
"An error occured while trying to authenticate your access token"},
500)))
# hier wel nog if om error zelf op te vangen
token = res.json()["access_token"]
profile_res = requests.get("https://graph.microsoft.com/v1.0/me",
headers={"Authorization":f"Bearer {token}"},
Expand Down
2 changes: 1 addition & 1 deletion backend/project/init_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def expired_token_callback(jwt_header, jwt_payload):
401)

@jwt.invalid_token_loader
def invalid_token_callback(jwt_header, jwt_payload):
def invalid_token_callback(jwt_header):
return (
{"message":("The server cannot recognize this access token cookie, "
"please log in again if you think this is an error")},
Expand Down
28 changes: 10 additions & 18 deletions frontend/src/components/Courses/CourseDetailTeacher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Link, useNavigate, NavigateFunction, useLoaderData } from "react-router
import { Title } from "../Header/Title";
import ClearIcon from '@mui/icons-material/Clear';
import { timeDifference } from "../../utils/date-utils";
import { authenticatedFetch } from "../../utils/authenticated-fetch";

interface UserUid{
uid: string
Expand All @@ -18,12 +19,8 @@ interface UserUid{
* @param uid - The UID of the admin.
*/
function handleDeleteAdmin(navigate: NavigateFunction, courseId: string, uid: string): void {
fetch(`${apiHost}/courses/${courseId}/admins`, {
authenticatedFetch(`${apiHost}/courses/${courseId}/admins`, {
method: 'DELETE',
credentials: 'include',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"admin_uid": uid
})
Expand All @@ -40,11 +37,10 @@ function handleDeleteAdmin(navigate: NavigateFunction, courseId: string, uid: st
* @param uid - The UID of the admin.
*/
function handleDeleteStudent(navigate: NavigateFunction, courseId: string, uids: string[]): void {
fetch(`${apiHost}/courses/${courseId}/students`, {
authenticatedFetch(`${apiHost}/courses/${courseId}/students`, {
method: 'DELETE',
credentials: 'include',
headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
},
body: JSON.stringify({
"students": uids
Expand All @@ -61,9 +57,8 @@ function handleDeleteStudent(navigate: NavigateFunction, courseId: string, uids:
* @param courseId - The ID of the course.
*/
function handleDeleteCourse(navigate: NavigateFunction, courseId: string): void {
fetch(`${apiHost}/courses/${courseId}`, {
authenticatedFetch(`${apiHost}/courses/${courseId}`, {
method: 'DELETE',
credentials: 'include',
}).then((response) => {
if(response.ok){
navigate(-1);
Expand Down Expand Up @@ -289,9 +284,8 @@ function JoinCodeMenu({courseId,open,handleClose, anchorEl}: {courseId:string, o
};

const getCodes = useCallback(() => {
fetch(`${apiHost}/courses/${courseId}/join_codes`, {
authenticatedFetch(`${apiHost}/courses/${courseId}/join_codes`, {
method: 'GET',
credentials: 'include',
})
.then(response => response.json())
.then(data => {
Expand All @@ -317,24 +311,22 @@ function JoinCodeMenu({courseId,open,handleClose, anchorEl}: {courseId:string, o
bodyContent.expiry_time = expiry_time.toISOString();
}

fetch(`${apiHost}/courses/${courseId}/join_codes`, {
authenticatedFetch(`${apiHost}/courses/${courseId}/join_codes`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
},
body: JSON.stringify(bodyContent)
})
.then(() => getCodes())
}

const handleDeleteCode = (joinCode: string) => {
fetch(`${apiHost}/courses/${courseId}/join_codes/${joinCode}`,
authenticatedFetch(`${apiHost}/courses/${courseId}/join_codes/${joinCode}`,
{
method: 'DELETE',
credentials: 'include',
headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
},
body: JSON.stringify({
"join_code": joinCode
Expand Down
Loading
Loading