mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
80 lines
1.9 KiB
Python
80 lines
1.9 KiB
Python
from fastapi import Depends, FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
import app.services.user_service
|
|
from app.models.user import User
|
|
|
|
from app.schemas.user import UserCreate, UserRead, UserUpdate
|
|
from app.services.user_service import auth_backend, current_active_verified_user, fastapi_users, get_oauth_provider
|
|
|
|
fastApi = FastAPI()
|
|
|
|
# CORS for frontend dev server
|
|
fastApi.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
"http://localhost:5173",
|
|
"http://127.0.0.1:5173",
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
fastApi.include_router(
|
|
fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"]
|
|
)
|
|
fastApi.include_router(
|
|
fastapi_users.get_register_router(UserRead, UserCreate),
|
|
prefix="/auth",
|
|
tags=["auth"],
|
|
)
|
|
fastApi.include_router(
|
|
fastapi_users.get_reset_password_router(),
|
|
prefix="/auth",
|
|
tags=["auth"],
|
|
)
|
|
fastApi.include_router(
|
|
fastapi_users.get_verify_router(UserRead),
|
|
prefix="/auth",
|
|
tags=["auth"],
|
|
)
|
|
fastApi.include_router(
|
|
fastapi_users.get_users_router(UserRead, UserUpdate),
|
|
prefix="/users",
|
|
tags=["users"],
|
|
)
|
|
|
|
fastApi.include_router(
|
|
fastapi_users.get_oauth_router(
|
|
get_oauth_provider("MojeID"),
|
|
auth_backend,
|
|
"SECRET",
|
|
associate_by_email=True,
|
|
),
|
|
prefix="/auth/mojeid",
|
|
tags=["auth"],
|
|
)
|
|
|
|
fastApi.include_router(
|
|
fastapi_users.get_oauth_router(
|
|
get_oauth_provider("BankID"),
|
|
auth_backend,
|
|
"SECRET",
|
|
associate_by_email=True,
|
|
),
|
|
prefix="/auth/bankid",
|
|
tags=["auth"],
|
|
)
|
|
|
|
|
|
# Liveness/root endpoint
|
|
@fastApi.get("/", include_in_schema=False)
|
|
async def root():
|
|
return {"status": "ok"}
|
|
|
|
|
|
@fastApi.get("/authenticated-route")
|
|
async def authenticated_route(user: User = Depends(current_active_verified_user)):
|
|
return {"message": f"Hello {user.email}!"}
|