diff --git a/.gitignore b/.gitignore index 6932fd8..fe9544d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ -# --- GLOBAL --- -.env -*.env -.env.* -!.env.example - # --- PYTHON BACKEND --- __pycache__/ diff --git a/backend/.env.example b/backend/.env.example index c6b9fe5..3e798fc 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,81 +1,26 @@ -# ============================================================ -# ENVIRONMENT -# ============================================================ -ENVIRONMENT=development +ENVIRONMENT=production DEBUG=false -# ============================================================ -# DATABASE / CACHE -# ============================================================ -DATABASE_URL=postgresql://postgres:postgres@db:5432/orcid_db +ORCID_CLIENT_ID=APP-XXXX +ORCID_CLIENT_SECRET= +ORCID_REDIRECT_URI=https://app.tudominio.com/callback +ORCID_OAUTH_STATE_ENABLED=true + +API_KEY_NAME=X-API-Key +API_KEY_VALUE= + +DATABASE_URL=postgresql://:@db:5432/orcid_db REDIS_URL=redis://redis:6379/0 -# ============================================================ -# BASE URL (uso interno del scheduler) -# ============================================================ -BASE_URL=http://localhost:8000/api +BASE_URL=https://api.tudominio.com/api -# ============================================================ -# CORS — lista blanca estricta separada por comas -# Nunca uses "*" si allow_credentials=true. -# ============================================================ -CORS_ALLOWED_ORIGINS=http://localhost:5173 +CORS_ALLOWED_ORIGINS=https://app.tudominio.com +TRUSTED_HOSTS=api.tudominio.com -# ============================================================ -# Trusted Hosts — anti Host-header injection (en prod, sé explícito) -# ============================================================ -TRUSTED_HOSTS=* - -# ============================================================ -# JWT (login ORCID) -# Genera un secreto fuerte: `openssl rand -base64 64` -# ============================================================ -JWT_SECRET=change_me_to_a_long_random_value_at_least_32_chars +JWT_SECRET= JWT_ALGORITHM=HS256 JWT_EXPIRES_MINUTES=720 JWT_ISSUER=orcid-sword-backend JWT_AUDIENCE=orcid-sword-frontend -# ============================================================ -# API key máquina-a-máquina (scheduler interno) -# Genera con: `python -c "import secrets;print(secrets.token_urlsafe(48))"` -# ============================================================ -API_KEY_NAME=X-API-Key -API_KEY_VALUE=replace_with_a_strong_random_value_min_24_chars - -# ============================================================ -# ORCID OAuth 3-legged (authorization code) -# ============================================================ -ORCID_CLIENT_ID=APP-XXXXXXXXXXXXXXXX -ORCID_CLIENT_SECRET=replace_me -ORCID_REDIRECT_URI=http://localhost:8000/api/auth/orcid/callback -ORCID_OAUTH_STATE_ENABLED=true - -# ============================================================ -# Rate limits (formato slowapi: "/") -# ============================================================ -RATE_LIMIT_DEFAULT=60/minute -RATE_LIMIT_AUTH=10/minute -RATE_LIMIT_SEARCH_ANON=5/minute -RATE_LIMIT_SEARCH_AUTH=30/minute -RATE_LIMIT_EXPORT=20/minute -RATE_LIMIT_SYNC=5/minute - -# ============================================================ -# Tope de tamaños (anti DoS) -# ============================================================ -MAX_ORCID_BATCH=25 -MAX_PUB_IDS_BATCH=500 -MAX_REQUEST_BODY_BYTES=1048576 - -# ============================================================ -# Documentación interactiva (deshabilita en producción si no es necesaria) -# ============================================================ -DOCS_ENABLED=true - -# ============================================================ -# HSTS -# ============================================================ -SECURITY_HSTS_SECONDS=31536000 -SECURITY_HSTS_INCLUDE_SUBDOMAINS=true -SECURITY_HSTS_PRELOAD=false +DOCS_ENABLED=false \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 96075b0..31f0586 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: container_name: orcid-backend restart: unless-stopped ports: - - "127.0.0.1:8072:8000" + - "0.0.0.0:8072:8000" env_file: - ./backend/.env environment: @@ -25,7 +25,7 @@ services: security_opt: - no-new-privileges:true healthcheck: - test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8000/health"] + test: ["CMD", "curl", "-fsS", "http://0.0.0.0:8000/health"] interval: 30s timeout: 5s retries: 3 @@ -36,7 +36,7 @@ services: container_name: orcid-frontend restart: unless-stopped ports: - - "127.0.0.1:8073:5173" + - "0.0.0.0:8073:5173" depends_on: - backend env_file: @@ -75,4 +75,4 @@ services: - no-new-privileges:true volumes: - postgres_data: + postgres_data: \ No newline at end of file diff --git a/frontend/.env.example b/frontend/.env.example index 159ff5a..f61b7bf 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,45 +1,4 @@ -# URL base del backend FastAPI (sin barra final). -# -# En desarrollo puedes dejarlo en blanco y el proxy de Vite -# (ver vite.config.js) reenviará todo lo que cuelgue de /api al -# destino indicado en VITE_API_PROXY_TARGET. Esto evita problemas -# de CORS sin exponer el host del backend al navegador. -VITE_API_URL=http://localhost:8000/api - -# Solo para dev: destino al que el proxy de Vite reenvía las peticiones -# que empiecen por /api. Cambia a http://backend:8000 si ejecutas el -# frontend dentro de docker-compose. -VITE_API_PROXY_TARGET=http://localhost:8000 - -# Clave compartida con el backend. Se inyecta como header `X-API-Key` -# en TODAS las peticiones salientes (ver src/services/api.js). Debe -# coincidir con `API_KEY_VALUE` del .env del backend. -VITE_API_KEY=12ao.9-8a7b-4c&d-9e,f-?89abc - -# Pon "true" SOLO si el backend no está disponible y quieres trabajar -# con los fixtures de src/services/mocks.js. En producción debe estar a "false". -VITE_USE_MOCKS=false - -# ── Autenticación OAuth ORCID ──────────────────────────────────────────────── -# -# El flujo real es: -# 1. Frontend abre popup → GET /api/auth/orcid/authorize -# 2. Backend redirige a sandbox.orcid.org (o pub.orcid.org en producción) -# 3. Usuario se autentica en ORCID -# 4. ORCID redirige a ORCID_REDIRECT_URI (debe apuntar a esta app) -# 5. /auth/callback extrae el code y llama al backend para obtener el JWT -# -# Para que el callback vuelva al frontend, el backend necesita: -# ORCID_REDIRECT_URI=http://localhost:5173/callback -# (en backend/.env — debe coincidir con el redirect URI del app ORCID sandbox) -# En producción con ngrok u otro túnel, el formato sería: -# ORCID_REDIRECT_URI=https:///callback -# -# ── Modo bypass (solo desarrollo sin credenciales OAuth configuradas) ───────── -# Cuando está a "true", el botón "Iniciar sesión" genera un token simulado -# a partir del ORCID introducido en el campo de texto, sin abrir popup ni -# contactar al backend de auth. Útil para probar la UI autenticada -# (badges "Nuevo", botón "Descargar lo nuevo") sin OAuth real. -# ADVERTENCIA: el token simulado NO es válido en el backend, por lo que -# downloaded_by_me siempre será null (sin datos reales de "novedad"). -VITE_AUTH_BYPASS=false +VITE_API_URL=https://api.tudominio.com/api +VITE_API_PROXY_TARGET= +VITE_API_KEY= +VITE_USE_MOCKS=false \ No newline at end of file