Quickstart Auth API
Este quickstart muestra cómo obtener un token OAuth2 client_credentials en el sandbox y usarlo para consumir otras APIs.
1) Obtener credenciales
- Solicita
client_idyclient_secretal equipo de integraciones. - Define los scopes mínimos necesarios para el dominio que quieres consumir (ej:
boletas.read). - Audience sugerida:
https://api.sandbox.aveniocloud.com.
2) Pedir token client_credentials
API_BASE="https://api.sandbox.aveniocloud.com"
CLIENT_ID="<tu_client_id>"
CLIENT_SECRET="<tu_client_secret>"
SCOPES="boletas.read"
curl -X POST "$API_BASE/api/v1/connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=$CLIENT_ID" \
-d "client_secret=$CLIENT_SECRET" \
-d "scope=$SCOPES"
Respuesta (envelope común):
{
"success": true,
"data": {
"accessToken": "eyJhbGciOi...",
"expiresIn": 3600,
"scope": "boletas.read"
},
"traceId": "f6b0..."
}
3) Usar el token en otras APIs
- Envía el header
X-Avenio-Authorization: <accessToken>en cada request. - Propaga
X-Correlation-Idpara trazabilidad end-to-end.
Ejemplo (consulta de operaciones Boletas):
TOKEN="<accessToken>"
curl -X GET "$API_BASE/api/v1/bhe/operaciones/<operationId>" \
-H "X-Avenio-Authorization: $TOKEN" \
-H "X-Correlation-Id: 7e9c7c2a-0f56-4c7b-9e5f-8e5b1b98a9b0"
Buenas prácticas
- Usa scopes mínimos necesarios por dominio.
- Rota credenciales ante cualquier sospecha.
- No expongas
client_secreten repositorios o logs.