Appearance
03.03 Authentication & API Key
📌 At a Glance
| รายการ | รายละเอียด |
|---|---|
| Topic | Authentication & API Key |
| Difficulty | ⭐ Beginner |
| Reading Time | 6 นาที |
| Target | Developer |
| Security | API Key Authentication |
🎯 Learning Objectives
หลังจากศึกษาหัวข้อนี้แล้ว ผู้อ่านจะสามารถ
- เข้าใจการยืนยันตัวตนของ SISAHYGO API
- ส่ง API Key ได้ถูกต้อง
- เข้าใจข้อควรปฏิบัติด้านความปลอดภัย
Overview
SISAHYGO API V1.1 ใช้ API Key Authentication สำหรับยืนยันตัวตนของ Client System
ทุก Request ที่เรียกใช้งาน API จะต้องส่ง API Key ที่ถูกต้อง มิฉะนั้นระบบจะปฏิเสธการเชื่อมต่อทันที
API Key ถูกกำหนดให้กับแต่ละ Client และใช้สำหรับระบุสิทธิ์ในการเข้าถึงบริการของระบบ
Figure 3-3 Authentication Flow
(แทรกรูป Figure 3-3 : Authentication Flow)

Figure 3-3 แสดงขั้นตอนการตรวจสอบ API Key ตั้งแต่ Client System ส่ง Request ไปยัง SISAHYGO API การตรวจสอบสิทธิ์ และการตอบกลับผลลัพธ์
Authentication Header
Client ต้องส่ง API Key ผ่าน HTTP Header
http
X-API-Key: YOUR_API_KEY
Accept: application/json
Content-Type: application/jsonExample Request
http
GET /api/v1/products HTTP/1.1
Host: app.sisahygo.online
X-API-Key: sk_live_xxxxxxxxxxxxxxxxx
Accept: application/jsonAuthentication Flow
- Client ส่ง HTTPS Request
- ระบบตรวจสอบ API Key
- ตรวจสอบสิทธิ์การใช้งาน
- อนุญาตให้เข้าถึง API
- ส่ง JSON Response
หาก API Key ไม่ถูกต้อง ระบบจะตอบกลับ HTTP 401 Unauthorized
Response Example
json
{
"success": false,
"code": "AUTH001",
"message": "Invalid API Key"
}Key Points
| Item | Description |
|---|---|
| Authentication | API Key |
| Transport | HTTPS Only |
| Header | X-API-Key |
| Response Format | JSON |
| Unauthorized | HTTP 401 |
Best Practices
- เก็บ API Key ไว้ใน Environment Variables
- ไม่ Hardcode API Key ใน Source Code
- ไม่เปิดเผย API Key ผ่าน Git Repository
- ใช้ HTTPS ทุกครั้ง
- เปลี่ยน API Key ทันทีหากสงสัยว่ารั่วไหล
Summary
API Key เป็นกลไกการยืนยันตัวตนหลักของ SISAHYGO API V1.1 โดยทุก Request ต้องส่ง API Key ผ่าน HTTP Header และเชื่อมต่อผ่าน HTTPS เพื่อรักษาความปลอดภัยของข้อมูล
Next Step
➡️ 03.04 HTTP Methods
