OAuth 2.0
OAuth 2.0 offre un’autenticazione sicura basata su token per le applicazioni di terze parti che accedono a Brevo per conto degli utenti.
Panoramica del flusso OAuth
- Richiesta di autorizzazione: reindirizza l’utente a Brevo
- Autorizzazione dell’utente: l’utente concede i permessi
- Codice di autorizzazione: Brevo reindirizza con il codice
- Scambio del token di accesso: scambia il codice con i token
- Accesso all’API: usa il token di accesso per le richieste
Endpoint di autorizzazione
https://app.brevo.com/oauth/authorize? response_type=code& client_id=YOUR_CLIENT_ID& redirect_uri=YOUR_REDIRECT_URI& scope=email%20contacts& state=random_stringScambio del token
curl -X POST "https://api.brevo.com/v3/oauth/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code&code=AUTH_CODE&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&redirect_uri=YOUR_REDIRECT_URI"Utilizzo del token di accesso
const response = await fetch('https://api.brevo.com/v3/account', { headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Accept': 'application/json' }});Scope
email: invio di e-mail transazionalicontacts: gestione di contatti ed elenchicampaigns: creazione e invio di campagnesms: invio di messaggi SMSwebhooks: gestione dei webhook
Refresh del token
const refreshToken = async () => { const response = await fetch('https://api.brevo.com/v3/oauth/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: 'YOUR_REFRESH_TOKEN', client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' }) }); return response.json();};