API Autenticaci贸n
Aprende a autenticarte con la API de BotLaunch usando tokens JWT. Protege tus solicitudes y gestiona el acceso a tus recursos.
Autenticaci贸n segura sin estado utilizando JSON Web Tokens.
Los tokens de acceso expiran en 1 hora, los tokens de actualizaci贸n en 7 d铆as.
Usa tokens de actualizaci贸n para obtener nuevos tokens de acceso de forma transparente.
Flujo de autenticaci贸n
Sigue estos pasos para autenticarte y realizar solicitudes seguras a la API.
Iniciar sesi贸n
Obtener tokens con credenciales
Almacenar tokens
Almacenar ambos tokens de forma segura
Realizar solicitudes
Incluir token en los encabezados
Actualizar
Obtener nuevo token cuando expire
Endpoints de autenticaci贸n
/api/auth/loginAutenticar un usuario y recibir tokens de acceso y actualizaci贸n.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| string | User's email address | ||
| password | string | User's password |
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/login" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "your-secure-password"
}'Example Response
{
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 3600,
"user": {
"id": "usr_abc123",
"email": "user@example.com",
"role": "CLIENT_OWNER"
}
},
"message": "Login successful"
}/api/auth/registerCrear una nueva cuenta de usuario y organizaci贸n.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| string | Valid email address | ||
| password | string | Min 8 chars, 1 uppercase, 1 number | |
| name | string | User's full name | |
| organizationName | string | Optional | Organization name |
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/register" \
-H "Content-Type: application/json" \
-d '{
"email": "newuser@example.com",
"password": "SecureP@ssw0rd!",
"name": "John Doe",
"organizationName": "My Company"
}'/api/auth/refreshIntercambiar un token de actualizaci贸n por un nuevo token de acceso.
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/refresh" \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "your-refresh-token"
}'Rotaci贸n de tokens
Cada solicitud de actualizaci贸n devuelve un nuevo token de actualizaci贸n. Almacena y usa el 煤ltimo token de actualizaci贸n para las solicitudes posteriores.
/api/auth/logoutInvalidar la sesi贸n actual y revocar tokens.
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/logout" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json"Uso de tokens de acceso
Incluye tu token de acceso en el encabezado Authorization para todas las solicitudes a la API.
// Include the access token in all API requests
const response = await fetch("https://api.botlaunch.io/api/bots", {
headers: {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIs...",
"x-organization-id": "org_xyz789",
"Content-Type": "application/json"
}
});Encabezados requeridos
AuthorizationBearer tokenx-organization-idOrganization IDContent-Typeapplication/jsonMejores pr谩cticas de seguridad
- Almacena los tokens de forma segura (nunca en localStorage para web)
- Usa HTTPS para todas las solicitudes a la API
- Implementa la actualizaci贸n del token antes de que expire
- Revoca los tokens al cerrar sesi贸n o en eventos de seguridad
Errores de autenticaci贸n
Errores comunes de autenticaci贸n y c贸mo manejarlos.
| Status | Error | Description | Solution |
|---|---|---|---|
| 401 | Unauthorized | Missing or invalid token | Check Authorization header |
| 401 | Token Expired | Access token has expired | Use refresh token to get new access token |
| 403 | Forbidden | Insufficient permissions | Check user role and organization access |
| 429 | Too Many Requests | Login rate limit exceeded | Wait and retry after cooldown |
| 400 | Invalid Credentials | Wrong email or password | Verify credentials and try again |