OAuth 2.0
OAuth 2.0은 서드파티 애플리케이션이 사용자를 대신해 Brevo에 접근할 때 사용하는, 토큰 기반의 안전한 인증 방식입니다.
OAuth 흐름 개요
- 인가 요청: 사용자를 Brevo로 리디렉션합니다
- 사용자 인가: 사용자가 권한을 승인합니다
- 인가 코드: Brevo가 코드와 함께 리디렉션합니다
- 액세스 토큰 교환: 코드를 토큰으로 교환합니다
- API 접근: 액세스 토큰으로 요청을 보냅니다
인가 엔드포인트
https://app.brevo.com/oauth/authorize? response_type=code& client_id=YOUR_CLIENT_ID& redirect_uri=YOUR_REDIRECT_URI& scope=email%20contacts& state=random_string토큰 교환
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"액세스 토큰 사용
const response = await fetch('https://api.brevo.com/v3/account', { headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Accept': 'application/json' }});스코프
email: 트랜잭션 이메일 발송contacts: 연락처 및 리스트 관리campaigns: 캠페인 생성 및 발송sms: SMS 메시지 발송webhooks: 웹훅 관리
토큰 갱신
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();};