O
/ Docs
DocsAPI ReferenceAuthentication

API Authentication

Hướng dẫn xác thực khi sử dụng API

Tổng quan

API sử dụng JWT (JSON Web Token) để xác thực. Bạn cần gửi token trong header Authorization cho mỗi request.

Base URLtext
https://api.example.com/v1

Lấy Access Token

POST/auth/login

Sử dụng email và password để lấy access token

Request Body

NameTypeDescription
emailrequiredstringEmail đăng ký tài khoản
passwordrequiredstringMật khẩu
Example Requestbash
curl -X POST https://api.example.com/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "your_password"
  }'
Responsejson
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_in": 86400,
  "token_type": "Bearer"
}

Sử dụng Token

Thêm token vào header Authorization với prefix "Bearer"

Using Token in Requestbash
curl https://api.example.com/v1/vms \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Refresh Token

Token có thời hạn 24 giờ. Sử dụng refresh token để lấy token mới

POST/auth/refresh

Làm mới access token

Request Body

NameTypeDescription
refresh_tokenrequiredstringRefresh token từ login response

API Key (Alternative)

Ngoài JWT, bạn có thể tạo API Key trong Dashboard để sử dụng cho automation scripts. API Key không có thời hạn nhưng có thể bị revoke bất cứ lúc nào.

Using API Keybash
curl https://api.example.com/v1/vms \
  -H "X-API-Key: your_api_key_here"

Error Codes

CodeMessage
401Unauthorized - Token không hợp lệ hoặc đã hết hạn
403Forbidden - Không có quyền truy cập resource
429Too Many Requests - Vượt quá rate limit
Rate Limiting
API có giới hạn 100 requests/phút cho mỗi account. Khi vượt quá, bạn sẽ nhận response 429.