Skip to content

Commit

Permalink
[project] Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BeastlyMC956 committed Oct 29, 2024
1 parent c3f9c01 commit 0642ce9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
4 changes: 3 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from utility.database import db
from utility.authorization import jwt, oauth
from utility.authorization import jwt, oauth, oidc
from utility.csrf import csrf
from routes import register_routes
import secrets
Expand Down Expand Up @@ -65,6 +65,8 @@
},
)

oidc.init_app(app)

# Register routes (blueprints)
register_routes(app)

Expand Down
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Flask
Flask-SQLAlchemy
Flask-CORS
Flask-Limiter
Flask-OIDC
Flask-WTF
Flask-JWT-Extended
authlib
Expand Down
20 changes: 6 additions & 14 deletions backend/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
All routes are registered here via the `register_routes` function.
"""

from http import HTTPStatus
import os
import secrets
from datetime import datetime, timedelta
Expand Down Expand Up @@ -257,7 +258,10 @@ def oidc_auth():
"""
OIDC route.
"""
token = oauth.kth.authorize_access_token()
try:
token = oauth.kth.authorize_access_token()
except Exception as e:
return jsonify({"error": str(e)}), HTTPStatus.INTERNAL_SERVER_ERROR

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

if not token:
return jsonify({"error": "Invalid credentials"}), 401
Expand Down Expand Up @@ -288,26 +292,14 @@ def oidc_auth():
db.session.add(student)
db.session.commit()

permissions_and_role, additional_claims, committees, committee_positions = (
retrieve_extra_claims(student=student)
)
response = make_response(
{
"student": student.to_dict(is_public_route=False),
"committees": committees,
"committee_positions": committee_positions,
"permissions": permissions_and_role.get("permissions"),
"role": permissions_and_role.get("role"),
}
)
response = make_response({"student": student.to_dict(is_public_route=False)})

response.status_code = 302
set_access_cookies(
response=response,
encoded_access_token=create_access_token(
identity=student,
fresh=timedelta(minutes=20),
additional_claims=additional_claims,
),
max_age=timedelta(hours=1),
)
Expand Down
10 changes: 8 additions & 2 deletions backend/services/core/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,23 @@ def retrieve_extra_claims(
).all()

for membership in student_memberships:
position: CommitteePosition = CommitteePosition.query.get_or_404(
position: CommitteePosition = CommitteePosition.query.get(
membership.committee_position_id
)

if not position:
continue

committee_positions.append(
position.to_dict(
provided_languages=provided_languages, is_public_route=False
)
)

committee: Committee = Committee.query.get_or_404(position.committee_id)
committee: Committee = Committee.query.get(position.committee_id)

if not committee:
continue

committee_dict = committee.to_dict(provided_languages=provided_languages)

Expand Down
3 changes: 2 additions & 1 deletion backend/utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The utility package. Imports all the utility modules.
"""

from .authorization import jwt, oauth
from .authorization import jwt, oauth, oidc
from .csrf import csrf, validate_csrf

from .constants import API_VERSION
Expand All @@ -24,6 +24,7 @@
__all__ = [
"jwt",
"oauth",
"oidc",
"csrf",
"validate_csrf",
"API_VERSION",
Expand Down
2 changes: 2 additions & 0 deletions backend/utility/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Utility for authorization variables.
"""

from flask_oidc import OpenIDConnect
from authlib.integrations.flask_client import OAuth
from flask_jwt_extended import JWTManager

oidc = OpenIDConnect()
oauth = OAuth()
jwt = JWTManager()
4 changes: 0 additions & 4 deletions frontend/src/providers/AuthenticationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ const createAuthFunctions = (
if (response.ok) {
const json = (await response.json()) as AuthenticationResponse
dispatch({ type: 'SET_STUDENT', payload: json.student })
dispatch({ type: 'SET_ROLE', payload: json.role })
dispatch({ type: 'SET_PERMISSIONS', payload: json.permissions })
dispatch({ type: 'SET_COMMITTEES', payload: json.committees })
dispatch({ type: 'SET_POSITIONS', payload: json.positions })
dispatch({ type: 'LOGIN' })
success = true
} else {
Expand Down
3 changes: 3 additions & 0 deletions frontend/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"installCommand": "npm install --force --include=optional sharp"
}

0 comments on commit 0642ce9

Please sign in to comment.