Xác thực
Hai cách xác thực với API s.id — API key cho máy chủ tới máy chủ, OAuth 2.0 để hoạt động thay mặt người dùng.
API Keys
API key xác thực các tích hợp máy chủ tới máy chủ. Tạo một cái tại Dashboard → Developer → API Keys, chọn phạm vi của bạn và truyền nó dưới dạng Bearer token.
Header xác thực
Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxVí dụ yêu cầu
curl https://api.s.id/v2/links \
-H "Authorization: Bearer sk_live_..."
Các phạm vi có sẵn
links:readList and read linkslinks:writeCreate and update links (create, edit, restore)links:archiveArchive linkslinks:analyticsRead per-link click statistics and lifetime countsqr:readRead QR code settings (global and per-link)qr:writeCustomize QR code settings (global and per-link)user:readRead the authenticated user profile and account quotamicrosites:readRead micrositesmicrosites:writeCreate, update, delete and manage components of microsites- •Key bắt đầu bằng sk_live_ và chỉ hiển thị một lần khi tạo.
- •Chỉ yêu cầu phạm vi tối thiểu mà tích hợp của bạn cần.
- •Thu hồi key ngay lập tức nếu bị xâm phạm — tạo cái mới.
- •Không bao giờ để lộ API key phía client (trình duyệt, ứng dụng mobile).
OAuth 2.0
Sử dụng luồng authorization-code để hoạt động thay mặt người dùng s.id. Ứng dụng của bạn chuyển hướng người dùng đến s.id để phê duyệt, sau đó đổi code lấy access token.
Luồng ủy quyền
- 1Chuyển hướng người dùng
GET https://dash.s.id/oauth/authorize ?client_id=YOUR_CLIENT_ID &redirect_uri=https://yourapp.com/callback &response_type=code &scope=links:read links:write &state=RANDOM_STATE &code_challenge=CODE_CHALLENGE &code_challenge_method=S256 - 2Đổi code lấy token
POST https://app.s.id/oauth/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code &code=AUTH_CODE &redirect_uri=https://yourapp.com/callback &client_id=YOUR_CLIENT_ID &client_secret=YOUR_CLIENT_SECRET &code_verifier=CODE_VERIFIER - 3Sử dụng access token
GET https://app.s.id/oauth/userinfo Authorization: Bearer ACCESS_TOKEN
PKCE (S256) là bắt buộc đối với public client — ứng dụng không có client secret (SPA, di động, CLI) — và tùy chọn với confidential client. Thêm code_challenge và code_challenge_method vào bước 1, và code_verifier vào bước 2. Access token nhận được hoạt động như một API key trên bất kỳ endpoint /v2 nào, theo phạm vi mà người dùng đã cấp.