Autenticazione

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.

Token JWT

Autenticazione sicura e stateless tramite JSON Web Token.

Scadenza Token

I token di accesso scadono in 1 ora, i token di refresh in 7 giorni.

Refresh Automatico

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.

1

Login

Ottieni i token con le credenziali

2

Archivia i Token

Archivia entrambi i token in modo sicuro

3

Effettua Richieste

Includi il token negli header

4

Refresh

Ottieni un nuovo token alla scadenza

Endpoint di Autenticazione

POST/api/auth/login

Autentica un utente e ricevi token di accesso e di refresh.

Request Body

FieldTypeRequiredDescription
emailstringUser's email address
passwordstringUser'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"
  }'
bash

Example Response

{
  "data": {
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "expiresIn": 3600,
    "user": {
      "id": "usr_abc123",
      "email": "user@example.com",
      "role": "CLIENT_OWNER"
    }
  },
  "message": "Login successful"
}
json
POST/api/auth/register

Crea un nuovo account utente e organizzazione.

Request Body

FieldTypeRequiredDescription
emailstringValid email address
passwordstringMin 8 chars, 1 uppercase, 1 number
namestringUser's full name
organizationNamestringOptionalOrganization 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"
  }'
bash
POST/api/auth/refresh

Scambia 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"
  }'
bash

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.

POST/api/auth/logout

Invalida 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"
bash

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"
  }
});
javascript

Header Obbligatori

AuthorizationBearer token
x-organization-idOrganization ID
Content-Typeapplication/json

Best 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.

StatusErrorDescriptionSolution
401UnauthorizedMissing or invalid tokenCheck Authorization header
401Token ExpiredAccess token has expiredUse refresh token to get new access token
403ForbiddenInsufficient permissionsCheck user role and organization access
429Too Many RequestsLogin rate limit exceededWait and retry after cooldown
400Invalid CredentialsWrong email or passwordVerify credentials and try again