Autenticación
Base URL
https://b2b.allaria.devUna vez que tu IP esté whitelisteada, utilizá tu client_id y client_secret para obtener un token de acceso (access_token) que te permitirá realizar llamadas autenticadas a la API.
POST
/auth/tokenRequest
Headers
| Campo | Tipo | Requerido | Descripción |
|---|---|---|---|
Content-Type | string | Sí | Debe ser application/x-www-form-urlencoded |
No aplica: Path Parameters, Query Parameters.
Body
| Campo | Tipo | Requerido | Descripción |
|---|---|---|---|
client_id | string | Sí | Tu identificador de cliente proporcionado por Allaria |
client_secret | string | Sí | Tu secreto de cliente (mantenelo confidencial) |
grant_type | string | Sí | Debe ser: client_credentials |
Response
2XX Éxito
| Campo | Tipo | Descripción |
|---|---|---|
access_token | string | Token para autenticar requests posteriores |
expires_in | integer | Tiempo en segundos antes de que el token expire (86400 segundos = 1 día) |
refresh_expires_in | integer | Tiempo de expiración del refresh token (0 = no aplica) |
token_type | string | Tipo de token (siempre Bearer) |
not_before_policy | integer | Política de tiempo mínimo de uso del token |
scope | string | Alcances de permisos del token |
Códigos de error
| Status | Error | Descripción |
|---|---|---|
400 | invalid_request | Parámetros faltantes o inválidos |
401 | invalid_client | client_id o client_secret inválidos |
403 | access_denied | Acceso denegado a la API |
500 | server_error | Error interno del servidor |
Ejemplo de respuesta de error:
{
"error": "invalid_client",
"error_description": "Client authentication failed (e.g. unknown client, no client authentication included, or unsupported authentication method)"
}
Ejemplo de código
- cURL
- JavaScript
- Python
- Node.js
curl -X POST https://b2b.allaria.dev/auth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=TU_CLIENT_ID&client_secret=TU_CLIENT_SECRET&grant_type=client_credentials"
const response = await fetch('https://b2b.allaria.dev/auth/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
client_id: 'TU_CLIENT_ID',
client_secret: 'TU_CLIENT_SECRET',
grant_type: 'client_credentials'
})
});
const data = await response.json();
console.log(data.access_token);
import requests
response = requests.post(
'https://b2b.allaria.dev/auth/token',
headers={'Content-Type': 'application/x-www-form-urlencoded'},
data={
'client_id': 'TU_CLIENT_ID',
'client_secret': 'TU_CLIENT_SECRET',
'grant_type': 'client_credentials'
}
)
data = response.json()
access_token = data['access_token']
const axios = require('axios');
const response = await axios.post('https://b2b.allaria.dev/auth/token',
new URLSearchParams({
client_id: 'TU_CLIENT_ID',
client_secret: 'TU_CLIENT_SECRET',
grant_type: 'client_credentials'
}),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
);
const accessToken = response.data.access_token;
2XX Éxito
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 86400,
"refresh_expires_in": 0,
"token_type": "Bearer",
"not_before_policy": 0,
"scope": ""
}
Using the Token in Requests
Una vez obtenido el access_token, inclúyelo en el header Authorization de tus requests:
- cURL
- JavaScript
- Python
curl -X GET https://b2b.allaria.dev/v1/accounts \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json"
const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
const response = await fetch('https://b2b.allaria.dev/v1/accounts', {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});
const data = await response.json();
import requests
access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
response = requests.get('https://b2b.allaria.dev/v1/accounts', headers=headers)
data = response.json()
Seguridad
Nunca expongas tu client_secret en código de cliente. Siempre genera tokens en tu servidor backend y envíalos de forma segura al cliente.