feat: update company API endpoint, refine pedimento dates model, and adjust Keycloak mapper creation
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
# se actualiza con el ID real del tenant creado en PostgreSQL.
|
||||
###############################################################################
|
||||
|
||||
set -e # Salir si hay algún error
|
||||
# set -e # Comentado para permitir que el script continúe aunque algunos comandos fallen (ej: mapper ya existe)
|
||||
|
||||
# Colores para output
|
||||
RED='\033[0;31m'
|
||||
@@ -309,87 +309,84 @@ echo -e "\n${YELLOW}[5/8] Configurando mappers para tenant_id...${NC}"
|
||||
if [ -n "$BACKEND_CLIENT_ID" ]; then
|
||||
echo "Configurando mapper para Backend..."
|
||||
|
||||
# Obtener el dedicated scope del cliente backend
|
||||
BACKEND_SCOPES=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/clients/${BACKEND_CLIENT_ID}/optional-client-scopes" \
|
||||
# Verificar si el mapper tenant_id ya existe en el cliente
|
||||
MAPPER_TENANT_EXISTS=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/clients/${BACKEND_CLIENT_ID}/protocol-mappers/models" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json")
|
||||
-H "Content-Type: application/json" | grep -o "\"name\":\"tenant-id-mapper\"")
|
||||
|
||||
# Buscar el scope dedicado
|
||||
BACKEND_DEDICATED_SCOPE_ID=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/client-scopes" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json" | grep -o "\"id\":\"[^\"]*\",\"name\":\"anexo76-backend-dedicated\"" | grep -o "\"id\":\"[^\"]*" | sed 's/"id":"//')
|
||||
|
||||
if [ -n "$BACKEND_DEDICATED_SCOPE_ID" ]; then
|
||||
# Verificar si el mapper tenant_id ya existe
|
||||
MAPPER_TENANT_EXISTS=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/client-scopes/${BACKEND_DEDICATED_SCOPE_ID}/protocol-mappers/models" \
|
||||
if [ -z "$MAPPER_TENANT_EXISTS" ]; then
|
||||
# Crear mapper para tenant_id directamente en el cliente
|
||||
CREATE_MAPPER_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/clients/${BACKEND_CLIENT_ID}/protocol-mappers/models" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json" | grep -o "\"name\":\"tenant-id-mapper\"")
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "tenant-id-mapper",
|
||||
"protocol": "openid-connect",
|
||||
"protocolMapper": "oidc-usermodel-attribute-mapper",
|
||||
"config": {
|
||||
"user.attribute": "tenant_id",
|
||||
"claim.name": "tenant_id",
|
||||
"jsonType.label": "String",
|
||||
"id.token.claim": "true",
|
||||
"access.token.claim": "true",
|
||||
"userinfo.token.claim": "true"
|
||||
}
|
||||
}')
|
||||
|
||||
if [ -z "$MAPPER_TENANT_EXISTS" ]; then
|
||||
# Crear mapper para tenant_id
|
||||
curl -s -X POST "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/client-scopes/${BACKEND_DEDICATED_SCOPE_ID}/protocol-mappers/models" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "tenant-id-mapper",
|
||||
"protocol": "openid-connect",
|
||||
"protocolMapper": "oidc-usermodel-attribute-mapper",
|
||||
"config": {
|
||||
"user.attribute": "tenant_id",
|
||||
"claim.name": "tenant_id",
|
||||
"jsonType.label": "String",
|
||||
"id.token.claim": "true",
|
||||
"access.token.claim": "true",
|
||||
"userinfo.token.claim": "true"
|
||||
}
|
||||
}'
|
||||
HTTP_CODE=$(echo "$CREATE_MAPPER_RESPONSE" | tail -n1)
|
||||
if [ "$HTTP_CODE" = "201" ]; then
|
||||
echo -e "${GREEN}✓ Mapper tenant_id creado para Backend${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Mapper tenant_id ya existe para Backend${NC}"
|
||||
echo -e "${YELLOW}⚠ Error al crear mapper para Backend (HTTP ${HTTP_CODE})${NC}"
|
||||
echo "Respuesta: $(echo "$CREATE_MAPPER_RESPONSE" | head -n -1)"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Mapper tenant_id ya existe para Backend${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# 4.2 Configurar mapper para Frontend
|
||||
if [ -n "$FRONTEND_CLIENT_ID" ]; then
|
||||
echo "Configurando mapper para Frontend..."
|
||||
|
||||
# Buscar el scope dedicado del frontend
|
||||
FRONTEND_DEDICATED_SCOPE_ID=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/client-scopes" \
|
||||
# Verificar si el mapper tenant_id ya existe en el cliente
|
||||
MAPPER_TENANT_EXISTS=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/clients/${FRONTEND_CLIENT_ID}/protocol-mappers/models" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json" | grep -o "\"id\":\"[^\"]*\",\"name\":\"anexo76-frontend-dedicated\"" | grep -o "\"id\":\"[^\"]*" | sed 's/"id":"//')
|
||||
-H "Content-Type: application/json" | grep -o "\"name\":\"tenant-id-mapper\"")
|
||||
|
||||
if [ -n "$FRONTEND_DEDICATED_SCOPE_ID" ]; then
|
||||
# Verificar si el mapper tenant_id ya existe
|
||||
MAPPER_TENANT_EXISTS=$(curl -s -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/client-scopes/${FRONTEND_DEDICATED_SCOPE_ID}/protocol-mappers/models" \
|
||||
if [ -z "$MAPPER_TENANT_EXISTS" ]; then
|
||||
# Crear mapper para tenant_id directamente en el cliente
|
||||
CREATE_MAPPER_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/clients/${FRONTEND_CLIENT_ID}/protocol-mappers/models" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json" | grep -o "\"name\":\"tenant-id-mapper\"")
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "tenant-id-mapper",
|
||||
"protocol": "openid-connect",
|
||||
"protocolMapper": "oidc-usermodel-attribute-mapper",
|
||||
"config": {
|
||||
"user.attribute": "tenant_id",
|
||||
"claim.name": "tenant_id",
|
||||
"jsonType.label": "String",
|
||||
"id.token.claim": "true",
|
||||
"access.token.claim": "true",
|
||||
"userinfo.token.claim": "true"
|
||||
}
|
||||
}')
|
||||
|
||||
if [ -z "$MAPPER_TENANT_EXISTS" ]; then
|
||||
# Crear mapper para tenant_id
|
||||
curl -s -X POST "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/client-scopes/${FRONTEND_DEDICATED_SCOPE_ID}/protocol-mappers/models" \
|
||||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "tenant-id-mapper",
|
||||
"protocol": "openid-connect",
|
||||
"protocolMapper": "oidc-usermodel-attribute-mapper",
|
||||
"config": {
|
||||
"user.attribute": "tenant_id",
|
||||
"claim.name": "tenant_id",
|
||||
"jsonType.label": "String",
|
||||
"id.token.claim": "true",
|
||||
"access.token.claim": "true",
|
||||
"userinfo.token.claim": "true"
|
||||
}
|
||||
}'
|
||||
HTTP_CODE=$(echo "$CREATE_MAPPER_RESPONSE" | tail -n1)
|
||||
if [ "$HTTP_CODE" = "201" ]; then
|
||||
echo -e "${GREEN}✓ Mapper tenant_id creado para Frontend${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Mapper tenant_id ya existe para Frontend${NC}"
|
||||
echo -e "${YELLOW}⚠ Error al crear mapper para Frontend (HTTP ${HTTP_CODE})${NC}"
|
||||
echo "Respuesta: $(echo "$CREATE_MAPPER_RESPONSE" | head -n -1)"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Mapper tenant_id ya existe para Frontend${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
###############################################################################
|
||||
# 6. Crear usuario demo en Keycloak
|
||||
###############################################################################
|
||||
|
||||
Reference in New Issue
Block a user