---
title: "OAuth 2.0 | Tajo"
description: "การยืนยันตัวตนด้วย OAuth 2.0 สำหรับการเชื่อมต่อกับบริการภายนอกอย่างปลอดภัย"
url: https://tajo.io/th/docs/authentication/oauth/
markdown: https://tajo.io/th/docs/authentication/oauth.md
lang: th-TH
author: "Set Noa"
author_url: https://tajo.io/th/set-noa/
robots: noindex
---

ขอสิทธิ์ใช้งานล่วงหน้า

กรอกชื่อและที่อยู่อีเมลที่ทำงานของคุณ เราจะส่งลิงก์เพื่อยืนยันคำขอเข้าใช้งาน Tajo ทางอีเมล

# OAuth 2.0

[Set Noa](https://tajo.io/th/set-noa/)

OAuth 2.0 ให้การยืนยันตัวตนแบบใช้โทเคนที่ปลอดภัย สำหรับแอปพลิเคชันภายนอกที่เข้าถึง Brevo ในนามของผู้ใช้

## ภาพรวมของ OAuth Flow

1. **คำขอสิทธิ์**: เปลี่ยนเส้นทางผู้ใช้ไปยัง Brevo
2. **การอนุญาตจากผู้ใช้**: ผู้ใช้ให้สิทธิ์การเข้าถึง
3. **รหัสสิทธิ์**: Brevo เปลี่ยนเส้นทางกลับมาพร้อมรหัส
4. **การแลกเปลี่ยน access token**: แลกรหัสเป็นโทเคน
5. **การเข้าถึง API**: ใช้ access token ในการเรียกใช้งาน

## เอนด์พอยต์สำหรับขอสิทธิ์

```
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
```

## การแลกเปลี่ยนโทเคน

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

## การใช้งาน access token

```javascript
const response = await fetch('https://api.brevo.com/v3/account', {
  headers: {
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    'Accept': 'application/json'
  }
});
```

## ขอบเขตสิทธิ์

- `email`: ส่งอีเมล transactional
- `contacts`: จัดการรายชื่อผู้ติดต่อและลิสต์
- `campaigns`: สร้างและส่งแคมเปญ
- `sms`: ส่งข้อความ SMS
- `webhooks`: จัดการ Webhook

## การต่ออายุโทเคน

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