Initial commit: OAuth 2.0 인증 시스템 with APISIX API Gateway
- FastAPI 백엔드 + MongoDB + Redis 구성 - React + Vite + TypeScript + shadcn/ui 프론트엔드 - Apache APISIX API Gateway 통합 - Docker Compose 기반 개발 환경 - 3단계 권한 체계 (System Admin, Group Admin, User) - 동적 테마 지원 - 환경별 설정 (dev/vei/prod) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
49
oauth/backend/app/core/config.py
Normal file
49
oauth/backend/app/core/config.py
Normal file
@ -0,0 +1,49 @@
|
||||
from typing import List, Union
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic import field_validator
|
||||
import os
|
||||
|
||||
class Settings(BaseSettings):
|
||||
PROJECT_NAME: str = "OAuth Authentication System"
|
||||
VERSION: str = "1.0.0"
|
||||
API_V1_STR: str = "/api/v1"
|
||||
|
||||
SECRET_KEY: str = os.getenv("SECRET_KEY", "0198fda4-294e-77b0-a95d-2b601d2c594d")
|
||||
ALGORITHM: str = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
||||
REFRESH_TOKEN_EXPIRE_DAYS: int = 7
|
||||
|
||||
MONGODB_URL: str = os.getenv("MONGODB_URL", "mongodb://localhost:27017")
|
||||
DATABASE_NAME: str = os.getenv("DATABASE_NAME", "oauth_db")
|
||||
|
||||
REDIS_URL: str = os.getenv("REDIS_URL", "redis://localhost:6379")
|
||||
|
||||
BACKEND_CORS_ORIGINS: List[str] = ["http://localhost:3000", "http://localhost:5173"]
|
||||
|
||||
ENVIRONMENT: str = os.getenv("ENVIRONMENT", "dev")
|
||||
|
||||
BACKUP_PATH: str = os.getenv("BACKUP_PATH", "/var/backups/oauth")
|
||||
ARCHIVE_PATH: str = os.getenv("ARCHIVE_PATH", "/var/archives/oauth")
|
||||
|
||||
SMTP_HOST: str = os.getenv("SMTP_HOST", "")
|
||||
SMTP_PORT: int = int(os.getenv("SMTP_PORT", "587"))
|
||||
SMTP_USER: str = os.getenv("SMTP_USER", "")
|
||||
SMTP_PASSWORD: str = os.getenv("SMTP_PASSWORD", "")
|
||||
|
||||
NEXUS_URL: str = os.getenv("NEXUS_URL", "")
|
||||
NEXUS_REPOSITORY: str = os.getenv("NEXUS_REPOSITORY", "")
|
||||
|
||||
@field_validator("BACKEND_CORS_ORIGINS", mode="before")
|
||||
@classmethod
|
||||
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
||||
if isinstance(v, str) and not v.startswith("["):
|
||||
return [i.strip() for i in v.split(",")]
|
||||
elif isinstance(v, (list, str)):
|
||||
return v
|
||||
raise ValueError(v)
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
settings = Settings()
|
||||
38
oauth/backend/app/core/database.py
Normal file
38
oauth/backend/app/core/database.py
Normal file
@ -0,0 +1,38 @@
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from app.core.config import settings
|
||||
import redis.asyncio as redis
|
||||
from typing import Optional
|
||||
|
||||
class Database:
|
||||
client: Optional[AsyncIOMotorClient] = None
|
||||
database = None
|
||||
redis_client: Optional[redis.Redis] = None
|
||||
|
||||
db = Database()
|
||||
|
||||
async def init_db():
|
||||
db.client = AsyncIOMotorClient(settings.MONGODB_URL)
|
||||
db.database = db.client[settings.DATABASE_NAME]
|
||||
db.redis_client = await redis.from_url(settings.REDIS_URL, decode_responses=True)
|
||||
|
||||
await create_indexes()
|
||||
|
||||
async def close_db():
|
||||
if db.client:
|
||||
db.client.close()
|
||||
if db.redis_client:
|
||||
await db.redis_client.close()
|
||||
|
||||
async def create_indexes():
|
||||
await db.database.users.create_index("email", unique=True)
|
||||
await db.database.users.create_index("username", unique=True)
|
||||
await db.database.applications.create_index("client_id", unique=True)
|
||||
await db.database.applications.create_index("app_name", unique=True)
|
||||
await db.database.auth_history.create_index([("user_id", 1), ("created_at", -1)])
|
||||
await db.database.auth_history.create_index("created_at")
|
||||
|
||||
def get_database():
|
||||
return db.database
|
||||
|
||||
def get_redis():
|
||||
return db.redis_client
|
||||
Reference in New Issue
Block a user