SSO fixes
Browse files- app/integrations/core_auth.py +1 -0
- authtest.md +37 -0
- tests/test_core_auth.py +2 -1
app/integrations/core_auth.py
CHANGED
|
@@ -155,6 +155,7 @@ def _login_service_account() -> str | None:
|
|
| 155 |
CORE_ROLE_TO_INTERNAL: dict[str, str] = {
|
| 156 |
"admin_internacion": "ADMINISTRATIVO",
|
| 157 |
"admin": "ADMINISTRATIVO", # super-admin del Core — a confirmar con el equipo M10
|
|
|
|
| 158 |
"Medico": "MEDICO",
|
| 159 |
"limpieza": "LIMPIEZA",
|
| 160 |
}
|
|
|
|
| 155 |
CORE_ROLE_TO_INTERNAL: dict[str, str] = {
|
| 156 |
"admin_internacion": "ADMINISTRATIVO",
|
| 157 |
"admin": "ADMINISTRATIVO", # super-admin del Core — a confirmar con el equipo M10
|
| 158 |
+
"app": "ADMINISTRATIVO", # rol de la cuenta de servicio de M6 en el Core
|
| 159 |
"Medico": "MEDICO",
|
| 160 |
"limpieza": "LIMPIEZA",
|
| 161 |
}
|
authtest.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Opción A — si ENVIRONMENT=development en HF
|
| 2 |
+
|
| 3 |
+
export M6_URL="https://modulo-6-api.hf.space/api/v1"
|
| 4 |
+
|
| 5 |
+
TOKEN=$(curl -s "$M6_URL/auth/token?usuario=ADMINISTRATIVO&password=x" \
|
| 6 |
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
|
| 7 |
+
|
| 8 |
+
curl -s "$M6_URL/_debug/settings" -H "Authorization: Bearer $TOKEN"
|
| 9 |
+
|
| 10 |
+
Si te devuelve 404 en el primer curl, es que el Space está en production y el endpoint de dev
|
| 11 |
+
token está deshabilitado a propósito → usá la opción B.
|
| 12 |
+
|
| 13 |
+
Opción B — vía SSO real contra el Core (M10)
|
| 14 |
+
|
| 15 |
+
export M6_URL="https://modulo-6-api.hf.space/api/v1"
|
| 16 |
+
export CORE_URL="https://api.healthcare.cantero.ar"
|
| 17 |
+
|
| 18 |
+
# 1. Login real en el Core con un usuario ADMINISTRATIVO
|
| 19 |
+
CORE_TOKEN=$(curl -s -X POST "$CORE_URL/auth/login" \
|
| 20 |
+
-H "Content-Type: application/json" \
|
| 21 |
+
-d '{"email": "TU_EMAIL", "password": "TU_PASSWORD"}' \
|
| 22 |
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['token'])")
|
| 23 |
+
|
| 24 |
+
# 2. Pedirle un ticket SSO al Core
|
| 25 |
+
TICKET=$(curl -s -X POST "$CORE_URL/auth/sso-ticket" \
|
| 26 |
+
-H "Authorization: Bearer $CORE_TOKEN" \
|
| 27 |
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['ticket'])")
|
| 28 |
+
|
| 29 |
+
# 3. Canjearlo contra M6
|
| 30 |
+
M6_TOKEN=$(curl -s -X POST "$M6_URL/auth/sso-exchange" \
|
| 31 |
+
-H "Content-Type: application/json" \
|
| 32 |
+
-d '{"ticket": "'"$TICKET"'"}' \
|
| 33 |
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['token'])")
|
| 34 |
+
|
| 35 |
+
# 4. Pegarle al endpoint de debug
|
| 36 |
+
curl -s "$M6_URL/_debug/settings" -H "Authorization: Bearer $M6_TOKEN"
|
| 37 |
+
|
tests/test_core_auth.py
CHANGED
|
@@ -20,8 +20,9 @@ from app.integrations import core_auth
|
|
| 20 |
(["Medico"], "MEDICO"),
|
| 21 |
(["limpieza"], "LIMPIEZA"),
|
| 22 |
(["admin"], "ADMINISTRATIVO"),
|
|
|
|
| 23 |
(["Enfermero"], None),
|
| 24 |
-
(["app", "role_manager"],
|
| 25 |
([], None),
|
| 26 |
(["limpieza", "admin_internacion"], "ADMINISTRATIVO"), # precedencia
|
| 27 |
(["limpieza", "Medico"], "MEDICO"),
|
|
|
|
| 20 |
(["Medico"], "MEDICO"),
|
| 21 |
(["limpieza"], "LIMPIEZA"),
|
| 22 |
(["admin"], "ADMINISTRATIVO"),
|
| 23 |
+
(["app"], "ADMINISTRATIVO"),
|
| 24 |
(["Enfermero"], None),
|
| 25 |
+
(["app", "role_manager"], "ADMINISTRATIVO"),
|
| 26 |
([], None),
|
| 27 |
(["limpieza", "admin_internacion"], "ADMINISTRATIVO"), # precedencia
|
| 28 |
(["limpieza", "Medico"], "MEDICO"),
|