Xác Thực API Key
Xác thực API Key là phương thức chuẩn cho tất cả tích hợp đối tác.
Tổng Quan
- Header:
ls-api-key - Format:
ls_proj_v1_<random_string> - Scope: Tất cả operations trong project của bạn
- Expiration: Không bao giờ (được quản lý bởi admin Lunar Stream)
Nhận API Key Của Bạn
API Key và Project ID sẽ được cung cấp bởi admin Lunar Stream. Bạn sẽ nhận được:
API Key: ls_proj_v1_ydi3lLihcIW0Z9ZAkGz2BjV6caLYqzK41TQAGblW-4E
Project ID: ce4b77e3-3ed0-47ee-a307-ade5f3fbef91Quan trọng
Lưu trữ API Key của bạn một cách an toàn. Liên hệ admin Lunar Stream nếu bạn cần tạo lại.
Sử Dụng API Key
Thêm API Key vào header ls-api-key:
bash
curl -X GET "https://api.xxxxxx.xxx/api/v1/livestream?projectId=YOUR_PROJECT_ID" \
-H "ls-api-key: ls_proj_v1_ydi3lLihcIW0Z9ZAkGz2BjV6caLYqzK41TQAGblW-4E" \
-H "Content-Type: application/json"javascript
const axios = require('axios');
const client = axios.create({
baseURL: 'https://api.xxxxxx.xxx/api/v1',
headers: {
'ls-api-key': process.env.LUNAR_STREAM_API_KEY,
'Content-Type': 'application/json'
}
});
const response = await client.get('/livestream', {
params: { projectId: process.env.LUNAR_STREAM_PROJECT_ID }
});python
import requests
import os
headers = {
'ls-api-key': os.environ['LUNAR_STREAM_API_KEY'],
'Content-Type': 'application/json'
}
response = requests.get(
'https://api.xxxxxx.xxx/api/v1/livestream',
headers=headers,
params={'projectId': os.environ['LUNAR_STREAM_PROJECT_ID']}
)Quyền Hạn API Key
Với API Key của bạn, bạn có thể thực hiện các operations sau:
| Operation | Endpoint | Method |
|---|---|---|
| Liệt kê media servers | /media-servers/available | GET |
| Tạo livestream | /livestream | POST |
| Lấy thông tin livestream | /livestream/:id | GET |
| Liệt kê livestreams | /livestream | GET |
| Cập nhật livestream | /livestream/:id | PATCH |
| Xóa livestream | /livestream/:id | DELETE |
| Tạo push token | /livestream/generate-push-token | POST |
Cấu Hình Môi Trường
Lưu trữ thông tin xác thực trong environment variables:
bash
# .env file
LUNAR_STREAM_API_URL=https://api.xxxxxx.xxx/api/v1
LUNAR_STREAM_API_KEY=ls_proj_v1_ydi3lLihcIW0Z9ZAkGz2BjV6caLYqzK41TQAGblW-4E
LUNAR_STREAM_PROJECT_ID=ce4b77e3-3ed0-47ee-a307-ade5f3fbef91Error Responses
| Status | Error | Mô tả |
|---|---|---|
| 401 | UNAUTHORIZED | Thiếu hoặc API Key không hợp lệ |
| 403 | FORBIDDEN | API Key không có quyền truy cập tài nguyên |
json
{
"statusCode": 401,
"message": "Invalid API Key",
"error": "Unauthorized"
}Thực Hành Bảo Mật Tốt Nhất
- Lưu trữ an toàn - Sử dụng environment variables hoặc secret managers
- Không commit - Thêm
.envvào.gitignore - Chỉ server-side - Không bao giờ để lộ trong client-side code
- Giám sát sử dụng - Kiểm tra hoạt động API bất thường
- Báo cáo vấn đề - Liên hệ admin ngay lập tức nếu key bị lộ