Improved support for authentication cookies

This commit is contained in:
Lino Mallevaey
2025-08-19 18:20:37 +02:00
parent cdbd58905d
commit 954f73a0f5
3 changed files with 14 additions and 1 deletions

View File

@@ -28,7 +28,7 @@ DEBUG=True
APP_TITLE=MokPyo APP_TITLE=MokPyo
APP_VERSION=1.0.0 APP_VERSION=1.0.0
APP_DESCRIPTION=MokPyo APP_DESCRIPTION=MokPyo
APP_DOMAIN=localhost APP_DOMAIN=localhost # change in production with your domain (ex: mokpyo.com)
# ========================= # =========================
# SERVER CONFIGURATION # SERVER CONFIGURATION

View File

@@ -70,6 +70,10 @@ class Settings(BaseSettings):
def database_url(self) -> str: def database_url(self) -> str:
return f"mysql+<driver>://{self.DATABASE_USER}:{self.DATABASE_PASSWORD}@{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}" return f"mysql+<driver>://{self.DATABASE_USER}:{self.DATABASE_PASSWORD}@{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}"
@property
def app_url(self) -> str:
return f"{'https' if settings.USE_SSL else 'http'}://{settings.APP_DOMAIN}{':' + str(settings.PORT) if (settings.PORT != 80 and settings.ENV == 'dev') else ''}"
@property @property
def access_token_expire(self) -> timedelta: def access_token_expire(self) -> timedelta:
return timedelta(minutes=self.ACCESS_TOKEN_EXPIRE_MINUTES) return timedelta(minutes=self.ACCESS_TOKEN_EXPIRE_MINUTES)

View File

@@ -1,5 +1,6 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.responses import ORJSONResponse, JSONResponse, FileResponse from fastapi.responses import ORJSONResponse, JSONResponse, FileResponse
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from pathlib import Path from pathlib import Path
@@ -22,6 +23,14 @@ app = FastAPI(
redoc_url=None if settings.ENV == "prod" else "/redoc", redoc_url=None if settings.ENV == "prod" else "/redoc",
) )
app.add_middleware(
CORSMiddleware,
allow_origins=[settings.app_url],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ========================= # =========================
# Static files # Static files
# ========================= # =========================