OAuth และการยืนยันตัวตน
ใช้ OAuth authorization code flow เพื่อขอสิทธิ์ แลก token และหมุน refresh token อย่างปลอดภัย
1. สร้าง authorize URL
ส่งครีเอเตอร์ไปยัง URL ต่อไปนี้จาก browser:
https://furipay.me/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=https%3A%2F%2Fyourapp.com%2Fcallback&scope=profile.read+tips.read&state=RANDOM_CSRF_TOKEN
- redirect_uri ต้องตรงกับ HTTPS URL ที่ลงทะเบียนไว้ทุกตัวอักษร
- scope คั่นด้วยช่องว่าง และควรขอเฉพาะสิทธิ์ที่ใช้งานจริง
- state ต้องเป็นค่าสุ่มต่อคำขอ เก็บไว้ฝั่ง server และตรวจสอบแบบ constant-time หลัง redirect กลับ
เมื่อครีเอเตอร์อนุมัติ Furipay จะ redirect กลับพร้อม code และ state โดย authorization code มีอายุ 5 นาทีและใช้ได้ครั้งเดียว
2. แลก code เป็น token
เรียก endpoint นี้จาก server เท่านั้น:
POST https://api.furipay.me/v1/oauth/token
Content-Type: application/json
{
"grant_type": "authorization_code",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"code": "RETURNED_CODE",
"redirect_uri": "https://yourapp.com/callback"
}
POST
/v1/oauth/tokenPOST /v1/oauth/token
curl -X POST \
'https://api.furipay.me/v1/oauth/token' \
-H 'Authorization: Bearer <token>'View OpenAPI JSONผลลัพธ์สำเร็จมีรูปแบบดังนี้:
{
"access_token": "eyJ...",
"refresh_token": "fp_ref_...",
"token_type": "Bearer",
"expires_in": 31536000,
"scope": "profile.read tips.read"
}
ใช้ค่า expires_in จาก response เป็นแหล่งอ้างอิงอายุ token และเก็บ token ทั้งสองแบบเข้ารหัส
3. รีเฟรช token
POST https://api.furipay.me/v1/oauth/token
Content-Type: application/json
{
"grant_type": "refresh_token",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"refresh_token": "fp_ref_..."
}
ทุกครั้งที่รีเฟรช ระบบจะคืน refresh token ค่าใหม่ ให้บันทึกค่าใหม่แบบ atomic และเลิกใช้ค่าเดิมทันที
Scopes
| Scope | ใช้สำหรับ |
|---|---|
| profile.read | อ่านโปรไฟล์สาธารณะและสถานะช่องทางรับทิป |
| tips.read | อ่านประวัติและสถิติทิป |
| tips.create | สร้างทิปผ่าน API |
| alerts.create | ส่ง alert ทดสอบไปยัง overlay |
| events.subscribe | รับ event ทิปผ่าน Webhook หรือ socket |
Endpoint GET /me ไม่ต้องขอ scope เพิ่ม แต่ยังต้องใช้ access token ที่ถูกต้อง