Skip to content

Commit 06ac4aa

Browse files
committed
fix: CORS header and made cookie cache the samesite and domain value
1 parent 2c0c854 commit 06ac4aa

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/auth/urls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import database
1313
from auth import crud
1414
from auth.models import LoginBodyModel
15-
from constants import IS_PROD
15+
from constants import DOMAIN, IS_PROD, SAMESITE
1616
from utils.shared_models import DetailModel
1717

1818
_logger = logging.getLogger(__name__)
@@ -40,7 +40,7 @@ def generate_session_id_b64(num_bytes: int) -> str:
4040
"/login",
4141
description="Create a login session.",
4242
response_description="Successfully validated with SFU's CAS",
43-
response_model=None,
43+
response_model=str,
4444
responses={
4545
307: { "description": "Successful validation, with redirect" },
4646
400: { "description": "Origin is missing.", "model": DetailModel },
@@ -87,8 +87,8 @@ async def login_user(
8787
value=session_id,
8888
secure=IS_PROD,
8989
httponly=True,
90-
samesite=None if IS_PROD else "lax",
91-
domain=".sfucsss.org" if IS_PROD else None
90+
samesite=SAMESITE,
91+
domain=DOMAIN
9292
) # this overwrites any past, possibly invalid, session_id
9393
return response
9494

src/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@
2626

2727
# https://docs.github.com/en/enterprise-server@3.10/admin/identity-and-access-management/iam-configuration-reference/username-considerations-for-external-authentication
2828
GITHUB_USERNAME_LEN = 39
29+
30+
# COOKIE
31+
SAMESITE=None if IS_PROD else "lax"
32+
DOMAIN=".sfucsss.org" if IS_PROD else None

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if not IS_PROD:
2121
print("Running local environment")
2222
origins = [
23-
"http://localhost:*", # default Angular
23+
"http://localhost:4200", # default Angular
2424
"http://localhost:8080", # for existing applications/sites
2525
]
2626
app = FastAPI(

0 commit comments

Comments
 (0)