s.id Logo
Platform Developer

Autentikasi

Dua cara autentikasi dengan API s.id — API key untuk server-ke-server, OAuth 2.0 untuk bertindak atas nama pengguna.

API Key

API key mengautentikasi integrasi server-ke-server. Buat satu di Dashboard → Developer → API Keys, pilih scope Anda, dan kirimkan sebagai token Bearer.

Header Otorisasi

Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Contoh permintaan

curl https://api.s.id/v2/links \
  -H "Authorization: Bearer sk_live_..."

Scope yang tersedia

links:readList and read links
links:writeCreate and update links (create, edit, restore)
links:archiveArchive links
links:analyticsRead per-link click statistics and lifetime counts
qr: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 quota
microsites:readRead microsites
microsites:writeCreate, update, delete and manage components of microsites
  • Kunci diawali sk_live_ dan hanya ditampilkan sekali saat pembuatan.
  • Minta hanya scope minimum yang dibutuhkan integrasi Anda.
  • Cabut kunci segera jika dikompromi — buat yang baru.
  • Jangan pernah mengekspos API key di sisi klien (browser, aplikasi mobile).

OAuth 2.0

Gunakan alur authorization-code untuk bertindak atas nama pengguna s.id. Aplikasi Anda mengarahkan pengguna ke s.id untuk persetujuan, lalu menukarkan kode dengan token akses.

Alur otorisasi

  1. 1Alihkan pengguna
    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. 2Tukarkan kode dengan 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. 3Gunakan access token
    GET https://app.s.id/oauth/userinfo
      Authorization: Bearer ACCESS_TOKEN

PKCE (S256) wajib digunakan untuk public client — aplikasi tanpa client secret (SPA, mobile, CLI) — dan opsional untuk confidential client. Tambahkan code_challenge dan code_challenge_method pada langkah 1, serta code_verifier pada langkah 2. Access token yang dihasilkan bekerja seperti API key pada endpoint /v2 mana pun, sesuai scope yang diberikan pengguna.

Platform Developer