diff --git a/backend/.env.example b/backend/.env.example index 61b7c01f..23cd9f7b 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -12,7 +12,7 @@ CORE_DB_USER=postgres CORE_DB_PASSWORD=postgres # Keycloak -KEYCLOAK_SERVER_URL=http://localhost:8080 +KEYCLOAK_SERVER_URL=http://localhost:8080/kcauth KEYCLOAK_REALM=master KEYCLOAK_CLIENT_ID=anexo76-backend KEYCLOAK_CLIENT_SECRET=your-client-secret diff --git a/backend/api/v1/modules/core/auth/service.py b/backend/api/v1/modules/core/auth/service.py index 57293605..96153be7 100644 --- a/backend/api/v1/modules/core/auth/service.py +++ b/backend/api/v1/modules/core/auth/service.py @@ -31,7 +31,7 @@ class AuthService: def __init__(self, db: Session): self.db = db self.keycloak_openid = KeycloakOpenID( - server_url=settings.KEYCLOAK_SERVER_URL, + server_url=f"{settings.KEYCLOAK_SERVER_URL}/kcauth", client_id=settings.KEYCLOAK_CLIENT_ID, realm_name=settings.KEYCLOAK_REALM, client_secret_key=settings.KEYCLOAK_CLIENT_SECRET, @@ -64,7 +64,7 @@ class AuthService: # Crear nueva instancia de KeycloakOpenID con el realm del tenant keycloak_client = KeycloakOpenID( - server_url=settings.KEYCLOAK_SERVER_URL, + server_url=f"{settings.KEYCLOAK_SERVER_URL}/kcauth", client_id=settings.KEYCLOAK_CLIENT_ID, realm_name=tenant.keycloak_realm, client_secret_key=settings.KEYCLOAK_CLIENT_SECRET, @@ -78,7 +78,7 @@ class AuthService: # o buscar el usuario por username try: keycloak_admin = KeycloakAdmin( - server_url=settings.KEYCLOAK_SERVER_URL, + server_url=f"{settings.KEYCLOAK_SERVER_URL}/kcauth", username=settings.KEYCLOAK_ADMIN_USERNAME, password=settings.KEYCLOAK_ADMIN_PASSWORD, realm_name=tenant.keycloak_realm, @@ -279,7 +279,7 @@ class AuthService: # Crear instancia de KeycloakAdmin para gestión de usuarios keycloak_admin = KeycloakAdmin( - server_url=settings.KEYCLOAK_SERVER_URL, + server_url=f"{settings.KEYCLOAK_SERVER_URL}/kcauth", username=settings.KEYCLOAK_ADMIN_USERNAME, password=settings.KEYCLOAK_ADMIN_PASSWORD, realm_name=tenant.keycloak_realm, diff --git a/backend/core/config.py b/backend/core/config.py index fb19d6ef..c27954eb 100644 --- a/backend/core/config.py +++ b/backend/core/config.py @@ -24,7 +24,7 @@ class Settings(BaseSettings): CORE_DB_PASSWORD: str = "postgres" # Keycloak - KEYCLOAK_SERVER_URL: str = "http://localhost:8080" + KEYCLOAK_SERVER_URL: str = "http://localhost:8080/kcauth" KEYCLOAK_REALM: str = "master" KEYCLOAK_CLIENT_ID: str = "anexo76-backend" KEYCLOAK_CLIENT_SECRET: str = "" @@ -43,7 +43,7 @@ class Settings(BaseSettings): LICENSE_CHECK_ENABLED: bool = True model_config = SettingsConfigDict( - env_file=".env", case_sensitive=True, extra="ignore" + env_file=".env", case_sensitive=True, extra="ignore", env_file_encoding="utf-8" ) @property diff --git a/backend/core/security.py b/backend/core/security.py index 60834f26..9bb89b8b 100644 --- a/backend/core/security.py +++ b/backend/core/security.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) # Configuración de Keycloak keycloak_openid = KeycloakOpenID( - server_url=settings.KEYCLOAK_SERVER_URL, + server_url=f"{settings.KEYCLOAK_SERVER_URL}/kcauth", client_id=settings.KEYCLOAK_CLIENT_ID, realm_name=settings.KEYCLOAK_REALM, client_secret_key=settings.KEYCLOAK_CLIENT_SECRET, diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 8a6b8f8e..c8f60a7c 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -151,7 +151,7 @@ services: - CORE_DB_NAME=${CORE_DB_NAME:-anexo76_core} - CORE_DB_USER=${CORE_DB_USER:-postgres} - CORE_DB_PASSWORD=${POSTGRES_APP_PASSWORD:-postgres} - - KEYCLOAK_SERVER_URL=${KEYCLOAK_SERVER_URL:-http://keycloak:8080} + - KEYCLOAK_SERVER_URL=${KEYCLOAK_SERVER_URL:-http://keycloak:8080/kcauth} - KEYCLOAK_REALM=${KEYCLOAK_REALM:-master} - KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-anexo76-backend} - KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-dev-secret} @@ -164,8 +164,6 @@ services: keycloak: condition: service_healthy volumes: - - ./backend:/app - - backend_cache:/app/__pycache__ - ./scripts/backend-entrypoint.sh:/entrypoint.sh:ro networks: - backend-net @@ -213,8 +211,6 @@ services: condition: service_healthy entrypoint: ["/frontend-entrypoint.sh"] volumes: - - ./frontend:/app - - frontend_node_modules:/app/node_modules - ./scripts/frontend-entrypoint.sh:/frontend-entrypoint.sh:ro networks: - frontend-net diff --git a/docker-compose.yml b/docker-compose.yml index 18215907..3e73fff6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -94,6 +94,7 @@ services: KC_PROXY_HEADERS: "xforwarded" KC_HEALTH_ENABLED: "true" KC_METRICS_ENABLED: "true" + KC_HOSTNAME_PATH: /kcauth KC_LOG_LEVEL: INFO JAVA_OPTS_APPEND: "-Xms256m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true" command: @@ -156,7 +157,7 @@ services: - CORE_DB_NAME=${CORE_DB_NAME:-anexo76_core} - CORE_DB_USER=${CORE_DB_USER:-postgres} - CORE_DB_PASSWORD=${POSTGRES_APP_PASSWORD:-postgres} - - KEYCLOAK_SERVER_URL=${KEYCLOAK_SERVER_URL:-http://keycloak:8080} + - KEYCLOAK_SERVER_URL=${KEYCLOAK_SERVER_URL:-http://keycloak:8080/kcauth} - KEYCLOAK_REALM=${KEYCLOAK_REALM:-master} - KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-anexo76-backend} - KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-dev-secret}