การรับรองความถูกต้อง
สองวิธีในการรับรองความถูกต้องกับ s.id API — API key สำหรับ server-to-server, OAuth 2.0 สำหรับการทำงานแทนผู้ใช้
API Keys
API key รับรองความถูกต้องของการเชื่อมต่อ server-to-server สร้างหนึ่งใน Dashboard → Developer → API Keys เลือกสิทธิ์ของคุณ และส่งเป็น Bearer token
Authorization header
Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxตัวอย่างคำขอ
curl https://api.s.id/v2/links \
-H "Authorization: Bearer sk_live_..."
สิทธิ์ที่มีให้
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 เริ่มต้นด้วย sk_live_ และแสดงเพียงครั้งเดียวเมื่อสร้าง
- •ขอเฉพาะสิทธิ์ขั้นต่ำที่การเชื่อมต่อของคุณต้องการ
- •เพิกถอน key ทันทีหากถูกบุกรุก — สร้างอันใหม่
- •อย่าเปิดเผย API key ฝั่ง client (เบราว์เซอร์, แอปมือถือ)
OAuth 2.0
ใช้ authorization-code flow เพื่อทำงานแทนผู้ใช้ s.id แอปของคุณเปลี่ยนเส้นทางผู้ใช้ไปยัง s.id เพื่อขออนุมัติ จากนั้นแลกเปลี่ยน code กับ access token
Authorization flow
- 1เปลี่ยนเส้นทางผู้ใช้
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แลกเปลี่ยน code กับ 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 - 3ใช้ access token
GET https://app.s.id/oauth/userinfo Authorization: Bearer ACCESS_TOKEN
PKCE (S256) จำเป็นสำหรับ public client — แอปที่ไม่มี client secret (SPA, มือถือ, CLI) — และเป็นทางเลือกสำหรับ confidential client เพิ่ม code_challenge และ code_challenge_method ในขั้นตอนที่ 1 และ code_verifier ในขั้นตอนที่ 2 access token ที่ได้จะทำงานเหมือน API key บน endpoint /v2 ใด ๆ ตาม scope ที่ผู้ใช้อนุญาต