API Autenticazione
Scopri come autenticarti con l'API di BotLaunch utilizzando i token JWT. Proteggi le tue richieste e gestisci l'accesso alle tue risorse.
Autenticazione sicura e stateless tramite JSON Web Token.
I token di accesso scadono in 1 ora, i token di refresh in 7 giorni.
Usa i token di refresh per ottenere nuovi token di accesso senza interruzioni.
Flusso di Autenticazione
Segui questi passaggi per autenticarti ed effettuare richieste API sicure.
Login
Ottieni i token con le credenziali
Archivia i Token
Archivia entrambi i token in modo sicuro
Effettua Richieste
Includi il token negli header
Refresh
Ottieni un nuovo token alla scadenza
Endpoint di Autenticazione
/api/auth/loginAutentica un utente e ricevi token di accesso e di refresh.
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/registerCrea un nuovo account utente e organizzazione.
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/refreshScambia un token di refresh per un nuovo token di accesso.
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/refresh" \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "your-refresh-token"
}'Rotazione Token
Ogni richiesta di refresh restituisce un nuovo token di refresh. Archivia e utilizza il token di refresh più recente per le richieste successive.
/api/auth/logoutInvalida la sessione corrente e revoca i token.
Example Request
curl -X POST "https://api.botlaunch.io/api/auth/logout" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json"Utilizzo dei Token di Accesso
Includi il tuo token di accesso nell'header Authorization per tutte le richieste 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"
}
});Header Obbligatori
AuthorizationBearer tokenx-organization-idOrganization IDContent-Typeapplication/jsonBest Practice di Sicurezza
- Archivia i token in modo sicuro (mai nel localStorage per il web)
- Usa HTTPS per tutte le richieste API
- Implementa il refresh del token prima della scadenza
- Revoca i token al logout o in caso di eventi di sicurezza
Errori di Autenticazione
Errori di autenticazione comuni e come gestirli.
| 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 |