Pagpapatunay
Dalawang paraan ng pagpapatunay sa s.id API, API key para sa server-to-server, OAuth 2.0 para kumilos sa ngalan ng mga user.
Server-to-server na access
Ang mga API key ay nagpapatunay ng mga server-to-server na integrasyon. Gumawa ng isa sa Dashboard → Developer → API Keys, piliin ang iyong mga scope, at ipasa ito bilang Bearer token.
| Saklaw | Akses |
|---|---|
links:read | Ilista at basahin ang mga link |
links:write | Gumawa at mag-update ng mga link (gumawa, mag-edit, magbalik) |
links:archive | Mag-archive ng mga link |
links:analytics | Basahin ang click statistics at kabuuang bilang para sa bawat link |
qr:read | Basahin ang QR code settings (global at bawat link) |
qr:write | I-customize ang QR code settings (global at bawat link) |
user:read | Basahin ang authenticated user profile at account quota |
microsites:read | Basahin ang mga microsite |
microsites:write | Gumawa, mag-update, at mamahala ng mga microsite component |
microsites:delete | Mag-delete ng mga microsite at component nito |
Authorization: Bearer sk_live_...curl https://api.s.id/v2/links \
-H "Authorization: Bearer sk_live_..."- Ang mga key ay nagsisimula sa sk_live_ at isang beses lamang ipinakikita sa paglikha.
- Humiling lamang ng minimum na mga scope na kailangan ng iyong integrasyon.
- Bawiin agad ang mga key kapag nakompromiso, gumawa ng bago.
- Huwag kailanman ilantad ang mga API key sa client-side (mga browser, mobile app).
Authorization flow
I-redirect ang user sa s.id para sa pahintulot, i-verify ang callback state, at ipagpalit ang single-use code sa access token at umiikot na refresh token.
- Gumawa ng hindi mahuhulaang state value, itago ito sa user session, at tiyaking eksaktong tugma sa callback upang maiwasan ang CSRF.
- Gumamit ng redirect_uri na eksaktong tumutugma sa nakarehistro para sa iyong OAuth application.
Kailangan ang PKCE, walang client secret
Para sa SPA, mobile app, at CLI. Gumawa ng random na code_verifier, ipadala ang S256 challenge nito sa authorize, at ipadala ang orihinal na verifier sa token exchange.
https://api.s.id/oauth/authorize?
response_type=code&
client_id=YOUR_CLIENT_ID&
redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback&
scope=links%3Aread%20links%3Awrite&
state=RANDOM_CSRF_VALUE&
code_challenge=BASE64URL_SHA256_VERIFIER&
code_challenge_method=S256curl -X POST https://api.s.id/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "client_id=YOUR_CLIENT_ID" \
-d "code=AUTHORIZATION_CODE" \
-d "redirect_uri=https://app.example.com/callback" \
-d "code_verifier=ORIGINAL_RANDOM_VERIFIER"Client secret sa pinagkakatiwalaang backend
Para sa server-rendered o backend application na kayang panatilihing lihim ang client_secret. Opsyonal pa rin ang PKCE at inirerekomenda bilang dagdag na depensa.
https://api.s.id/oauth/authorize?
response_type=code&
client_id=YOUR_CLIENT_ID&
redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback&
scope=links%3Aread%20links%3Awrite&
state=RANDOM_CSRF_VALUEcurl -X POST https://api.s.id/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "code=AUTHORIZATION_CODE" \
-d "redirect_uri=https://app.example.com/callback"| Access token | Paglalarawan |
|---|---|
access_token | Mag-e-expire pagkalipas ng 1 oras |
refresh_token | Mag-e-expire pagkalipas ng 30 araw |
code | Isang beses lang magagamit; mag-e-expire pagkalipas ng 10 minuto |
curl -X POST https://api.s.id/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "client_id=YOUR_CLIENT_ID" \
-d "refresh_token=CURRENT_REFRESH_TOKEN"curl -X POST https://api.s.id/oauth/revoke \
-H "Content-Type: application/json" \
-d '{"token":"TOKEN_TO_REVOKE"}'| Discovery at mga token operation | Paglalarawan |
|---|---|
https://api.s.id/.well-known/oauth-authorization-server | Tuklasin ang mga endpoint URL, suportadong scope, at PKCE method sa pamamagitan ng RFC 8414 metadata. |
POST /oauth/introspect | Maaaring tingnan ng confidential resource server kung aktibo ang token at suriin ang mga scope nito. |
POST /oauth/revoke | Bawiin ang access o refresh token kapag idiniskonekta ng user ang iyong integration. |
GET /oauth/userinfo | Basahin ang profile na nauugnay sa OAuth access token na may user:read. |