Skip to content

03.03 Authentication & API Key


📌 At a Glance

รายการรายละเอียด
TopicAuthentication & API Key
Difficulty⭐ Beginner
Reading Time6 นาที
TargetDeveloper
SecurityAPI 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

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/json

Example Request

http
GET /api/v1/products HTTP/1.1
Host: app.sisahygo.online
X-API-Key: sk_live_xxxxxxxxxxxxxxxxx
Accept: application/json

Authentication Flow

  1. Client ส่ง HTTPS Request
  2. ระบบตรวจสอบ API Key
  3. ตรวจสอบสิทธิ์การใช้งาน
  4. อนุญาตให้เข้าถึง API
  5. ส่ง JSON Response

หาก API Key ไม่ถูกต้อง ระบบจะตอบกลับ HTTP 401 Unauthorized


Response Example

json
{
  "success": false,
  "code": "AUTH001",
  "message": "Invalid API Key"
}

Key Points

ItemDescription
AuthenticationAPI Key
TransportHTTPS Only
HeaderX-API-Key
Response FormatJSON
UnauthorizedHTTP 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

SISAHYGO API Integration Guide