Skip to content

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

Quan 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:

OperationEndpointMethod
Liệt kê media servers/media-servers/availableGET
Tạo livestream/livestreamPOST
Lấy thông tin livestream/livestream/:idGET
Liệt kê livestreams/livestreamGET
Cập nhật livestream/livestream/:idPATCH
Xóa livestream/livestream/:idDELETE
Tạo push token/livestream/generate-push-tokenPOST

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

Error Responses

StatusErrorMô tả
401UNAUTHORIZEDThiếu hoặc API Key không hợp lệ
403FORBIDDENAPI 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

  1. Lưu trữ an toàn - Sử dụng environment variables hoặc secret managers
  2. Không commit - Thêm .env vào .gitignore
  3. Chỉ server-side - Không bao giờ để lộ trong client-side code
  4. Giám sát sử dụng - Kiểm tra hoạt động API bất thường
  5. Báo cáo vấn đề - Liên hệ admin ngay lập tức nếu key bị lộ

Released under the MIT License.