---
title: "OAuth 2.0 | Tajo"
description: "Xác thực OAuth 2.0 cho các tích hợp bên thứ ba an toàn"
url: https://tajo.io/vi/docs/authentication/oauth/
markdown: https://tajo.io/vi/docs/authentication/oauth.md
lang: vi-VN
author: "Set Noa"
author_url: https://tajo.io/vi/set-noa/
robots: noindex
---

Đăng ký quyền truy cập sớm

Nhập tên và địa chỉ email công việc của bạn. Chúng tôi sẽ gửi liên kết để xác nhận yêu cầu truy cập Tajo.

# OAuth 2.0

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

OAuth 2.0 cung cấp cơ chế xác thực an toàn dựa trên token cho các ứng dụng bên thứ ba truy cập Brevo thay mặt người dùng.

## Tổng quan luồng OAuth

1. **Yêu cầu ủy quyền**: Chuyển hướng người dùng sang Brevo
2. **Người dùng ủy quyền**: Người dùng cấp quyền truy cập
3. **Mã ủy quyền**: Brevo chuyển hướng trở lại kèm theo mã
4. **Đổi lấy access token**: Đổi mã ủy quyền lấy token
5. **Truy cập API**: Dùng access token cho các yêu cầu

## Endpoint ủy quyền

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

## Đổi lấy token

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

## Cách dùng access token

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

## Các scope

- `email`: Gửi email giao dịch
- `contacts`: Quản lý liên hệ và danh sách
- `campaigns`: Tạo và gửi chiến dịch
- `sms`: Gửi tin nhắn SMS
- `webhooks`: Quản lý webhook

## Làm mới token

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