สารบัญหน้านี้ (29)
- ภาพรวม
- Workflow: เปิดแอป MAYARIN Fit ครั้งแรก: Authorization Code + PKCE + หน้ายินยอม
- Workflow: ดูตั๋วบนจอทีวีห้องรับรอง VIP ด้วย Device flow
- Workflow: Refresh token rotation + ตรวจจับ token ถูกขโมย
- The Client object
- The Introspection object
- The Consent object
- Endpoints (15)
- GETเริ่มขอสิทธิ์ (Authorization endpoint)
- POSTออก token (Token endpoint)
- POSTเพิกถอน token
- POSTตรวจสถานะ token (Introspection)
- POSTขอรหัสอุปกรณ์ (Device flow)
- GETOpenID Connect discovery
- GETข้อมูลผู้ใช้ (UserInfo)
- GETออกจากระบบที่ issuer (RP-initiated logout)
- GETรายการแอป (client)
- POSTลงทะเบียนแอป
- GETดูแอป
- PATCHแก้ค่าแอป
- POSTหมุน client secret
- GETความยินยอมของผู้ใช้
- DELETEถอนความยินยอม
- Grant types — ตัวอย่างแบบ form
- Webhooks (6)
- Errors
- Rate limit
- เวอร์ชันและ Changelog
- เครื่องมือ: ตัวสร้าง PKCE + URL authorize
- KUNJAE ID
- Docs
- Identity API
- OAuth
KUNJAE Identity API · OAuth
OAuth 2.0 + OpenID Connect
ออก token ให้ทั้ง 4 แอปของเครือ จอทีวีในโรงภาพยนตร์ และระบบหลังบ้าน ตามมาตรฐาน OAuth 2.0 / OpenID Connect — Authorization Code + PKCE, Client Credentials, Refresh token rotation, Device flow, หน้ายินยอม (PDPA), เพิกถอน และ introspection
- 15 endpoint
- 3 workflow
- 3 object
- 6 webhook event
- เวอร์ชัน
2026-08-01

ทำอะไร ใช้เมื่อไร
- แอปมือถือ/SPA ล็อกอินผ่านเบราว์เซอร์ของระบบด้วย Authorization Code + PKCE (แอปไม่เห็นรหัสผ่าน)
- ระบบหลังบ้าน (POS ระบบแต้ม) ขอ token ของตัวเองด้วย Client Credentials + private_key_jwt
- จอทีวี/ตู้ในโรงภาพยนตร์ใช้ Device flow — ผู้ใช้อนุญาตจากมือถือ
- ต่ออายุอัตโนมัติด้วย refresh token ที่หมุนทุกครั้ง + ตรวจจับการใช้ซ้ำ (token ถูกขโมย)
- ความยินยอม PDPA แยกต่อแอป/นิติบุคคลในเครือ ผู้ใช้ดูและถอนได้เอง
Base path
| path | ใช้ทำอะไร |
|---|---|
/oauth/* | authorize token revoke introspect device userinfo logout (มาตรฐาน) |
/.well-known/openid-configuration | discovery |
/v1/clients | ลงทะเบียน/จัดการแอป |
/v1/users/{user_id}/consents | ความยินยอมของผู้ใช้ |
Base URL: https://api.kunjae.example · Sandbox https://sandbox.api.kunjae.example · หัวเลือกเวอร์ชัน Kunjae-Version: 2026-08-01
การยืนยันตัวตนและ scope
- /oauth/* และ /.well-known/* ใช้ issuer https://id.mayarin.example (โดเมนของเครือชี้มาที่ KUNJAE · sandbox: https://id.sandbox.mayarin.example) — ในตัวอย่างโค้ดแสดงเป็น base URL ของ API ซึ่งให้ผลเดียวกัน
- public client ไม่มี secret (ยืนยันด้วย PKCE) · confidential ใช้ client_secret_basic หรือ private_key_jwt · /v1/clients ใช้ management key
| scope | ให้ทำอะไร | ใครใช้ |
|---|---|---|
openid | จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub | ทุกแอปที่ใช้ OIDC |
profile | ชื่อ ชื่อเล่น ภาษา เขตเวลา | ทุกแอปที่ใช้ OIDC |
email | อีเมล + email_verified | ทุกแอปที่ใช้ OIDC |
phone | เบอร์โทร E.164 + phone_number_verified | ทุกแอปที่ใช้ OIDC |
offline_access | ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด) | ทุกแอปที่ใช้ OIDC |
mall:orders.read | อ่านคำสั่งซื้อของตัวเองในห้าง | MAYARIN Mall |
mall:orders.write | สั่งซื้อ/ยกเลิกคำสั่งซื้อในห้าง | MAYARIN Mall |
cinema:tickets.read | ดูตั๋วภาพยนตร์ที่ซื้อแล้ว | MAYARIN Cinema |
cinema:tickets.write | จอง/ซื้อตั๋วภาพยนตร์ | MAYARIN Cinema |
fit:checkin | เช็กอินประตูฟิตเนส | MAYARIN Fit |
fit:classes.book | จองคลาสออกกำลังกาย | MAYARIN Fit |
points:read | ดูยอดแต้มและประวัติ | MAYARIN Mall, MAYARIN Cinema, MAYARIN Points |
points:redeem | แลกแต้มเป็นคูปอง/ส่วนลด | MAYARIN Mall, MAYARIN Points |
staff:portal | เข้าพอร์ทัลพนักงาน (สิทธิ์จริงตามบทบาท) | MAYARIN Staff Portal |
clients:read / clients:write | ดู/จัดการแอป (management key) | ทีมแพลตฟอร์ม |
introspect | เรียก /oauth/introspect | API ปลายทาง (resource server) |
Object หลัก
Clientแอปที่ลงทะเบียน (public / confidential)Introspectionสถานะของ token ที่ API ปลายทางถามConsentความยินยอมของผู้ใช้ต่อแอป 1 ตัว (PDPA)
เกี่ยวข้องกับโมดูลอื่น
- Authentication แอปของเครือล็อกอินผ่าน /v1/auth/* ได้ authorization_code มาแลกที่ /oauth/token เหมือนกัน
- JWT access_token/id_token เป็น JWT ลงลายเซ็น RS256 — ตรวจด้วย JWKS
- Authorization token แบบ client_credentials (scope authz:check) ใช้เรียกตรวจสิทธิ์พนักงาน
- Role/Permission token ของพอร์ทัลพนักงานมี claim roles/branch_ids จากบทบาท
- error ของ /oauth/* เป็นรูปแบบมาตรฐาน { "error": "invalid_grant", "error_description": "…" } · /v1/* ใช้ { "error": { "code" … } }
- code ใช้ครั้งเดียว อายุ 60 วินาที · access token 15 นาที · refresh token 30 วัน (หมุนทุกครั้ง) · id_token 1 ชม.
- PKCE บังคับ S256 ทุก public client (plain ไม่รองรับ) · redirect_uri ตรงทุกตัวอักษร
- เวลาใน token เป็น unix (วินาที) ตามมาตรฐาน · เวลาใน /v1/* เป็น ISO 8601 +07:00
- PDPA: แต่ละแอปเป็นนิติบุคคลแยกในเครือ → ยินยอมแยก · ถอนแล้ว token ของแอปนั้นถูกเพิกถอนทันที
Workflow — ลำดับการทำงานจริง (3 เรื่อง)
แต่ละเรื่องมี 2 มุมมอง: ภาพรวม อธิบายทีละขั้นสำหรับทุกคนในทีม และ Sequence กดเล่นทีละขั้นเพื่อดูคำขอ/ผลลัพธ์จริงของ endpoint ในหน้านี้ · ลูกศรประ = ไม่รอผล (webhook/คิว)
เปิดแอป MAYARIN Fit ครั้งแรก: Authorization Code + PKCE + หน้ายินยอม
คุณธนกฤตสมัครฟิตเนส (2 มิ.ย. 2569) — แอปพาไปล็อกอินด้วยบัญชีเดิมของห้างในเบราว์เซอร์ของระบบ ยินยอมให้แอปใช้เบอร์โทรและเช็กอิน แล้วกลับแอปพร้อม code
- คุณธนกฤต
- MAYARIN Fitแอปมือถือ
- เบราว์เซอร์ของระบบแท็บเบราว์เซอร์ในแอป
- KUNJAE OAuthid.mayarin.example
- คิว webhook
- 1
คุณธนกฤต → MAYARIN Fit
เปิดแอปฟิตเนสครั้งแรก
- 2
MAYARIN Fit → MAYARIN Fit
สุ่ม code_verifier เก็บในหน่วยความจำ แล้วคำนวณ code_challenge = SHA-256
- 3
MAYARIN Fit → เบราว์เซอร์ของระบบ
เปิดเบราว์เซอร์ของระบบ (เห็นแถบที่อยู่ id.mayarin.example — ผู้ใช้ตรวจได้ว่าไม่ใช่หน้าปลอม)
- 4
เบราว์เซอร์ของระบบ → KUNJAE OAuth
ขอ code พร้อม code_challenge
GET /oauth/authorize?response_type=code&client_id=kjc_fit_9Lw4&redirect_uri=com.mayarin.fit%3A%2Foauth%2Fcallback&scope=openid%20profile%20phone%20offline_access%20fit%3Acheckin&state=st_7Rk2Qw9Lp&nonce=n-4Yx8Qp2Rk&code_challenge=0ford-LDLpJi-LOmioyxobl29EMd4IMMmWSCvic-l8A&code_challenge_method=S256 - 5
KUNJAE OAuth → เบราว์เซอร์ของระบบ
ล็อกอินด้วยอีเมล + รหัส + OTP (ดูหน้า Authentication)
- 6
KUNJAE OAuth → เบราว์เซอร์ของระบบ
“MAYARIN Fit (บริษัท มายาริน ฟิตเนส จำกัด) ขอใช้: ชื่อ เบอร์โทร เช็กอินประตู”
- 7
คุณธนกฤต → เบราว์เซอร์ของระบบ
ยินยอมตามประกาศความเป็นส่วนตัวเวอร์ชัน 2026-03
- 8
KUNJAE OAuth → MAYARIN Fit
กลับแอปพร้อม code (ใช้ครั้งเดียว 60 วินาที) แอปเทียบ state ว่าตรง
- 9
MAYARIN Fit → KUNJAE OAuth
แลก code + code_verifier
POST /oauth/token - 10
MAYARIN Fit → KUNJAE OAuth
ดึงชื่อมาแสดง “สวัสดีคุณกฤต”
GET /oauth/userinfo - 11
KUNJAE OAuth → คิว webhook
แจ้งระบบสมาชิกของเครือว่ามีการยินยอมใหม่
ไม่รอผล (async)
สมัคร/ล็อกอินเสร็จใน 2 นาทีโดยไม่ตั้งรหัสใหม่ · ความยินยอม PDPA บันทึกแยกนิติบุคคล · แอปไม่เคยเห็นรหัสผ่าน · code ถูกขโมยก็ใช้ไม่ได้เพราะไม่มี code_verifier
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 คุณธนกฤต MAYARIN Fit
แตะ “เข้าสู่ระบบด้วย MAYARIN ID”
เปิดแอปฟิตเนสครั้งแรก
2 MAYARIN Fit MAYARIN Fit
สร้าง code_verifier + state + nonce
สุ่ม code_verifier เก็บในหน่วยความจำ แล้วคำนวณ code_challenge = SHA-256
3 MAYARIN Fit เบราว์เซอร์ของระบบ
เปิด URL authorize
เปิดเบราว์เซอร์ของระบบ (เห็นแถบที่อยู่ id.mayarin.example — ผู้ใช้ตรวจได้ว่าไม่ใช่หน้าปลอม)
4 เบราว์เซอร์ของระบบ KUNJAE OAuth
GET /oauth/authorize
ขอ code พร้อม code_challenge
GET /oauth/authorize?response_type=code&client_id=kjc_fit_9Lw4&redirect_uri=com.mayarin.fit%3A%2Foauth%2Fcallback&scope=openid%20profile%20phone%20offline_access%20fit%3Acheckin&state=st_7Rk2Qw9Lp&nonce=n-4Yx8Qp2Rk&code_challenge=0ford-LDLpJi-LOmioyxobl29EMd4IMMmWSCvic-l8A&code_challenge_method=S256 HTTP/1.15 KUNJAE OAuth เบราว์เซอร์ของระบบ
หน้าล็อกอิน
ล็อกอินด้วยอีเมล + รหัส + OTP (ดูหน้า Authentication)
6 KUNJAE OAuth เบราว์เซอร์ของระบบ
หน้ายินยอม
“MAYARIN Fit (บริษัท มายาริน ฟิตเนส จำกัด) ขอใช้: ชื่อ เบอร์โทร เช็กอินประตู”
7 คุณธนกฤต เบราว์เซอร์ของระบบ
กด “อนุญาต”
ยินยอมตามประกาศความเป็นส่วนตัวเวอร์ชัน 2026-03
8 KUNJAE OAuth MAYARIN Fit
302 → callback?code&state
กลับแอปพร้อม code (ใช้ครั้งเดียว 60 วินาที) แอปเทียบ state ว่าตรง
HTTP/1.1 302 Found
{
"Location": "com.mayarin.fit:/oauth/callback?code=kjac_Q8mL2xV7pR4tN9wZ&state=st_7Rk2Qw9Lp"
}9 MAYARIN Fit KUNJAE OAuth
POST /oauth/token
แลก code + code_verifier
POST /oauth/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
{
"grant_type": "authorization_code",
"code": "kjac_Q8mL2xV7pR4tN9wZ",
"redirect_uri": "com.mayarin.fit:/oauth/callback",
"code_verifier": "Vx3kQ9mZ2pL7rT0aB5nW8cE1yH4uJ6sD-fG_iK2oM3q",
"client_id": "kjc_fit_9Lw4"
}HTTP/1.1 200 OK
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5…X72YyjMV",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "kjr_PFC0CztCRX395ZF9dyoI…OLTOKp1G",
"id_token": "eyJhbGciOiJSUzI1NiIsInR5…S_q3GzFF"
}10 MAYARIN Fit KUNJAE OAuth
GET /oauth/userinfo
ดึงชื่อมาแสดง “สวัสดีคุณกฤต”
GET /oauth/userinfo HTTP/1.1
Authorization: Bearer eyJhbGciOiJSUzI1NiIs…HTTP/1.1 200 OK
{
"sub": "usr_8Nf2",
"name": "ธนกฤต ศรีวงศ์ทอง",
"nickname": "กฤต",
"phone_number": "+66800000412",
"phone_number_verified": true
}11 KUNJAE OAuth คิว webhookasync
consent.granted
แจ้งระบบสมาชิกของเครือว่ามีการยินยอมใหม่
สมัคร/ล็อกอินเสร็จใน 2 นาทีโดยไม่ตั้งรหัสใหม่ · ความยินยอม PDPA บันทึกแยกนิติบุคคล · แอปไม่เคยเห็นรหัสผ่าน · code ถูกขโมยก็ใช้ไม่ได้เพราะไม่มี code_verifier
ดูตั๋วบนจอทีวีห้องรับรอง VIP ด้วย Device flow
จอทีวีในห้องรับรองโรง 5 พิมพ์อีเมลยาก — จอแสดงรหัส 8 ตัว + QR คุณธนกฤตสแกนด้วยมือถือ อนุญาต แล้วจอแสดงตั๋วรอบ 19:30 ของเขา (11 ต.ค. 2569)
- จอทีวี VIPMAYARIN Cinema
- KUNJAE OAuth
- คุณธนกฤต
- มือถือ (เบราว์เซอร์)
- API ตั๋วภาพยนตร์
- 1
จอทีวี VIP → KUNJAE OAuth
จอขอรหัสอุปกรณ์
POST /oauth/device/code - 2
จอทีวี VIP → คุณธนกฤต
จอขึ้นรหัสและ QR ให้สแกน
- 3
จอทีวี VIP → KUNJAE OAuth
ถามทุก 5 วินาที
POST /oauth/token - 4
จอทีวี VIP → KUNJAE OAuth
เครือข่ายกระตุกทำให้ถามถี่ → ถูกขอให้ช้าลง
- 5
คุณธนกฤต → มือถือ (เบราว์เซอร์)
เปิดหน้า id.mayarin.example/device?user_code=MYRN-4KQT
- 6
มือถือ (เบราว์เซอร์) → KUNJAE OAuth
ล็อกอินแล้วตรวจว่ารหัสบนมือถือตรงกับบนจอ จึงกด “อนุญาตจอนี้”
- 7
จอทีวี VIP → KUNJAE OAuth
poll รอบถัดไปได้ token
- 8
จอทีวี VIP → API ตั๋วภาพยนตร์
จอดึงตั๋วด้วย access token (scope cinema:tickets.read)
- 9
API ตั๋วภาพยนตร์ → จอทีวี VIP
แสดงตั๋วรอบ 19:30 โรง 5 ที่นั่ง F7–F8
เชื่อมจอได้ใน 74 วินาที (จอถาม 14 ครั้ง ช้าลงเองเมื่อได้ slow_down) · ไม่ต้องพิมพ์รหัสผ่านบนจอสาธารณะ · session ses_7Mq1Hd ถอนได้จากมือถือ
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 จอทีวี VIP KUNJAE OAuth
POST /oauth/device/code
จอขอรหัสอุปกรณ์
POST /oauth/device/code HTTP/1.1
Content-Type: application/x-www-form-urlencoded
{
"client_id": "kjc_cine_3Hp8",
"scope": "openid profile cinema:tickets.read"
}HTTP/1.1 200 OK
{
"user_code": "MYRN-4KQT",
"verification_uri": "https://id.mayarin.example/device",
"expires_in": 600,
"interval": 5
}2 จอทีวี VIP คุณธนกฤต
แสดง MYRN-4KQT + QR
จอขึ้นรหัสและ QR ให้สแกน
3 จอทีวี VIP KUNJAE OAuth
POST /oauth/token (poll)
ถามทุก 5 วินาที
POST /oauth/token HTTP/1.1
Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w
{
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
"device_code": "kjd_Q_5LtRBMX7Z0q6Xn_7oA…0YjDqcbY",
"client_id": "kjc_cine_3Hp8"
}HTTP/1.1 400 Bad Request
{
"error": "authorization_pending",
"error_description": "ผู้ใช้ยังไม่ยืนยัน"
}4 จอทีวี VIP KUNJAE OAuth
poll เร็วเกิน
เครือข่ายกระตุกทำให้ถามถี่ → ถูกขอให้ช้าลง
เพิ่ม interval เป็น 10 วินาทีตามมาตรฐาน RFC 8628
HTTP/1.1 400 Bad Request
{
"error": "slow_down",
"error_description": "เพิ่ม interval อีก 5 วินาที"
}5 คุณธนกฤต มือถือ (เบราว์เซอร์)
สแกน QR
เปิดหน้า id.mayarin.example/device?user_code=MYRN-4KQT
6 มือถือ (เบราว์เซอร์) KUNJAE OAuth
ล็อกอิน + ยืนยันรหัส
ล็อกอินแล้วตรวจว่ารหัสบนมือถือตรงกับบนจอ จึงกด “อนุญาตจอนี้”
7 จอทีวี VIP KUNJAE OAuth
POST /oauth/token
poll รอบถัดไปได้ token
HTTP/1.1 200 OK
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5…X72YyjMV",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "kjr_…(อายุ 12 ชม.)"
}8 จอทีวี VIP API ตั๋วภาพยนตร์
GET ตั๋วของฉัน
จอดึงตั๋วด้วย access token (scope cinema:tickets.read)
9 API ตั๋วภาพยนตร์ จอทีวี VIP
200 ตั๋ว 2 ใบ
แสดงตั๋วรอบ 19:30 โรง 5 ที่นั่ง F7–F8
เชื่อมจอได้ใน 74 วินาที (จอถาม 14 ครั้ง ช้าลงเองเมื่อได้ slow_down) · ไม่ต้องพิมพ์รหัสผ่านบนจอสาธารณะ · session ses_7Mq1Hd ถอนได้จากมือถือ
Refresh token rotation + ตรวจจับ token ถูกขโมย
แอปห้างต่ออายุ token อัตโนมัติ — refresh token ตัวเก่าที่หลุดไปกับไฟล์สำรองข้อมูลถูกนำมาใช้ ระบบตรวจพบการใช้ซ้ำ เพิกถอนทั้งตระกูล และให้เจ้าของล็อกอินใหม่
- MAYARIN Mallแอปของผู้ใช้
- KUNJAE OAuth
- ตระกูล refresh tokenrtf_4Gk8Lm
- ผู้ไม่หวังดีได้ token เก่าไป
- คิว webhook
- 1
MAYARIN Mall → KUNJAE OAuth
access token ใกล้หมด แอปใช้ refresh token #1
POST /oauth/token - 2
KUNJAE OAuth → ตระกูล refresh token
ออก #2 ในตระกูลเดียวกัน
- 3
KUNJAE OAuth → MAYARIN Mall
แอปเก็บ #2 ทับ #1 ทันที
- 4
ผู้ไม่หวังดี → KUNJAE OAuth
มีคนนำ #1 ที่หลุดไปมาใช้
POST /oauth/token - 5
KUNJAE OAuth → ตระกูล refresh token
refresh #2 และ session ใช้ไม่ได้ทันที
- 6
KUNJAE OAuth → คิว webhook
แจ้งทีมความปลอดภัย + ส่งอีเมล/LINE เตือนเจ้าของบัญชี
ไม่รอผล (async) - 7
MAYARIN Mall → KUNJAE OAuth
แอปต่ออายุรอบถัดไป
POST /oauth/token - 8
MAYARIN Mall → MAYARIN Mall
แอปแจ้ง “เพื่อความปลอดภัย กรุณาเข้าสู่ระบบอีกครั้ง” แล้วใช้ passkey
ผู้ไม่หวังดีได้ token 0 ครั้ง · เพิกถอนทั้งตระกูลภายใน 1 วินาทีหลังตรวจพบ · ผู้ใช้ล็อกอินใหม่ด้วย passkey 3 วินาที
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 MAYARIN Mall KUNJAE OAuth
POST /oauth/token (refresh)
access token ใกล้หมด แอปใช้ refresh token #1
POST /oauth/token HTTP/1.1
Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w
{
"grant_type": "refresh_token",
"refresh_token": "kjr_PFC0CztCRX395ZF9dyoI…OLTOKp1G",
"client_id": "kjc_mall_7Qx2"
}2 KUNJAE OAuth ตระกูล refresh token
ทำเครื่องหมาย #1 ใช้แล้ว
ออก #2 ในตระกูลเดียวกัน
3 KUNJAE OAuth MAYARIN Mall
200 token ใหม่ + refresh #2
แอปเก็บ #2 ทับ #1 ทันที
HTTP/1.1 200 OK
{
"access_token": "eyJhbGciOiJSUzI1NiIs…",
"expires_in": 900,
"refresh_token": "kjr_PLu2tjI9yaUp3VUbmz8B…MytJBeuQ"
}4 ผู้ไม่หวังดี KUNJAE OAuth
POST /oauth/token (refresh #1)
มีคนนำ #1 ที่หลุดไปมาใช้
POST /oauth/token HTTP/1.1
Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w
{
"grant_type": "refresh_token",
"refresh_token": "kjr_PFC0CztCRX395ZF9dyoI…OLTOKp1G",
"client_id": "kjc_mall_7Qx2"
}HTTP/1.1 400 Bad Request
{
"error": "invalid_grant",
"error_description": "refresh_token_reused: ตรวจพบการใช้ซ้ำ เพิกถอนทั้งตระกูลแล้ว"
}5 KUNJAE OAuth ตระกูล refresh token
เพิกถอนทั้งตระกูล
refresh #2 และ session ใช้ไม่ได้ทันที
6 KUNJAE OAuth คิว webhookasync
token.reuse_detected
แจ้งทีมความปลอดภัย + ส่งอีเมล/LINE เตือนเจ้าของบัญชี
7 MAYARIN Mall KUNJAE OAuth
POST /oauth/token (refresh #2)
แอปต่ออายุรอบถัดไป
POST /oauth/token HTTP/1.1
Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w
{
"grant_type": "refresh_token",
"refresh_token": "kjr_PLu2tjI9yaUp3VUbmz8B…MytJBeuQ",
"client_id": "kjc_mall_7Qx2"
}HTTP/1.1 400 Bad Request
{
"error": "invalid_grant",
"error_description": "refresh token ถูกเพิกถอน"
}8 MAYARIN Mall MAYARIN Mall
ล้าง token → หน้าล็อกอิน
แอปแจ้ง “เพื่อความปลอดภัย กรุณาเข้าสู่ระบบอีกครั้ง” แล้วใช้ passkey
ผู้ไม่หวังดีได้ token 0 ครั้ง · เพิกถอนทั้งตระกูลภายใน 1 วินาทีหลังตรวจพบ · ผู้ใช้ล็อกอินใหม่ด้วย passkey 3 วินาที
Objects
The Client object
แอปที่ลงทะเบียนกับ KUNJAE ID — ตัวอย่างคือ MAYARIN Fit (public client บนมือถือ)
idstringไม่บังคับอ่านอย่างเดียวclient_id
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
namestringจำเป็นชื่อที่ผู้ใช้เห็นบนหน้ายินยอม
appstringจำเป็นรหัสแอปในเครือ
typeenumจำเป็นpublic = แอปมือถือ/SPA (เก็บความลับไม่ได้) · confidential = เซิร์ฟเวอร์
platformstringไม่บังคับแพลตฟอร์ม
logo_uristring · uriไม่บังคับโลโก้บนหน้ายินยอม (https)
grant_typesarray<string>จำเป็นgrant ที่อนุญาต (เปิดเฉพาะที่ใช้)
redirect_urisarray<string>ไม่บังคับURI ที่รับ code — ต้องตรงทุกตัวอักษร ไม่รับ wildcard
post_logout_redirect_urisarray<string>ไม่บังคับURI หลังออกจากระบบ
allowed_scopesarray<string>จำเป็นscope ที่แอปนี้ขอได้
pkceenumไม่บังคับบังคับ PKCE (public client ต้อง required)
token_endpoint_auth_methodenumจำเป็นวิธียืนยัน client ที่ /oauth/token
client_secret_last4stringไม่บังคับอ่านอย่างเดียว4 ตัวท้ายของ secret (ค่าเต็มแสดงครั้งเดียวตอนสร้าง/หมุน)
jwks_uristring · uriไม่บังคับกุญแจสาธารณะของ client (private_key_jwt)
access_token_ttlintegerไม่บังคับอายุ access token (วินาที)
refresh_token_ttlintegerไม่บังคับอายุ refresh token แบบไม่ใช้ (วินาที) · 0 = ไม่ออก
refresh_token_rotationbooleanไม่บังคับออก refresh ใหม่ทุกครั้งที่ใช้ + ตรวจใช้ซ้ำ
id_token_signed_algenumไม่บังคับอัลกอริทึมลงลายเซ็น id_token
first_partybooleanไม่บังคับอ่านอย่างเดียวแอปของเครือ (ใช้ /v1/auth/login ได้)
consentenumไม่บังคับการขอความยินยอม
statusenumไม่บังคับอ่านอย่างเดียวสถานะ
created_atstring · date-timeไม่บังคับอ่านอย่างเดียวสร้างเมื่อ
updated_atstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
metadataobjectไม่บังคับข้อมูลเสริมของคุณ (คีย์ ≤ 40 ตัว ค่า ≤ 500 ตัวอักษร สูงสุด 20 คู่)
{
"id": "kjc_fit_9Lw4",
"object": "client",
"name": "MAYARIN Fit",
"app": "fit",
"type": "public",
"platform": "iOS / Android",
"logo_uri": "https://cdn.mayarin.example/apps/fit.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"com.mayarin.fit:/oauth/callback"
],
"post_logout_redirect_uris": [
"com.mayarin.fit:/logout"
],
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 2592000,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2026-05-10T10:00:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-fit"
}
}
The Introspection object
ผลของ POST /oauth/introspect (RFC 7662) — ตัวอย่างคือ access token ของแอปห้างที่ออกเมื่อ 10:15
activebooleanไม่บังคับอ่านอย่างเดียวtoken ใช้ได้อยู่หรือไม่ (false = หมดอายุ/เพิกถอน/ไม่รู้จัก — ไม่มีฟิลด์อื่น)
token_typestringไม่บังคับอ่านอย่างเดียวชนิด
scopestringไม่บังคับอ่านอย่างเดียวscope
client_idstringไม่บังคับอ่านอย่างเดียวclient ที่ขอ
substringไม่บังคับอ่านอย่างเดียวผู้ใช้
usernamestringไม่บังคับอ่านอย่างเดียวอีเมลแบบปิดบัง
audstringไม่บังคับอ่านอย่างเดียวaudience
issstring · uriไม่บังคับอ่านอย่างเดียวissuer
expintegerไม่บังคับอ่านอย่างเดียวหมดอายุ (unix)
iatintegerไม่บังคับอ่านอย่างเดียวออกเมื่อ (unix)
nbfintegerไม่บังคับอ่านอย่างเดียวใช้ได้ตั้งแต่ (unix)
jtistringไม่บังคับอ่านอย่างเดียวรหัส token
sidstringไม่บังคับอ่านอย่างเดียวsession
acrstringไม่บังคับอ่านอย่างเดียวระดับการยืนยัน
amrarray<string>ไม่บังคับอ่านอย่างเดียววิธียืนยัน
session_statusenumไม่บังคับอ่านอย่างเดียวสถานะ session ปัจจุบัน (ตรวจการออกจากระบบทันที)
{
"active": true,
"token_type": "access_token",
"scope": "openid profile email phone offline_access mall:orders.read points:read points:redeem",
"client_id": "kjc_mall_7Qx2",
"sub": "usr_8Nf2",
"username": "tha***@mayarin.example",
"aud": "https://api.mayarin.example",
"iss": "https://id.mayarin.example",
"exp": 1791775800,
"iat": 1791774900,
"nbf": 1791774900,
"jti": "at_9Qw2Zx7Rb1Lc",
"sid": "ses_4Gk8Lm",
"acr": "urn:kunjae:acr:mfa",
"amr": [
"pwd",
"otp"
],
"session_status": "active"
}
The Consent object
ความยินยอมของผู้ใช้ต่อแอป 1 ตัว — แสดงในหน้า “แอปที่เชื่อมกับบัญชี” และใช้เป็นหลักฐานตาม PDPA
idstringไม่บังคับอ่านอย่างเดียวรหัสความยินยอม
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
user_idstringไม่บังคับอ่านอย่างเดียวผู้ใช้
client_idstringไม่บังคับอ่านอย่างเดียวแอป
client_namestringไม่บังคับอ่านอย่างเดียวชื่อแอป
legal_entitystringไม่บังคับอ่านอย่างเดียวนิติบุคคลผู้รับข้อมูล (PDPA — แต่ละแอปเป็นบริษัทแยกในเครือ)
scopesarray<string>ไม่บังคับอ่านอย่างเดียวscope ที่ยินยอม
scope_detailsarray<object>ไม่บังคับอ่านอย่างเดียวคำอธิบายที่ผู้ใช้เห็นตอนยินยอม
ฟิลด์ย่อยของ
scope_details(2)scopestringไม่บังคับอ่านอย่างเดียวscope
descstringไม่บังคับอ่านอย่างเดียวคำอธิบาย
purposestringไม่บังคับอ่านอย่างเดียววัตถุประสงค์ตามประกาศความเป็นส่วนตัว
privacy_notice_versionstringไม่บังคับอ่านอย่างเดียวเวอร์ชันประกาศความเป็นส่วนตัวที่ผู้ใช้เห็น
channelenumไม่บังคับอ่านอย่างเดียวช่องทางที่ให้ความยินยอม
granted_atstring · date-timeไม่บังคับอ่านอย่างเดียวยินยอมเมื่อ
updated_atstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด (เพิ่ม scope)
revoked_atstring · date-timeไม่บังคับอ่านอย่างเดียวถอนเมื่อ
{
"id": "cns_fit_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_fit_9Lw4",
"client_name": "MAYARIN Fit",
"legal_entity": "บริษัท มายาริน ฟิตเนส จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "phone",
"desc": "เบอร์โทร E.164 + phone_number_verified"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "fit:checkin",
"desc": "เช็กอินประตูฟิตเนส"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2026-06-02T06:10:00+07:00",
"updated_at": "2026-06-02T06:10:00+07:00",
"revoked_at": null
}Endpoints (15)
| Method | Path | ทำอะไร | สิทธิ์ |
|---|---|---|---|
| GET | /oauth/authorize | เริ่มขอสิทธิ์ (Authorization endpoint) | ไม่ต้องใช้ key |
| POST | /oauth/token | ออก token (Token endpoint) | ไม่ต้องใช้ key |
| POST | /oauth/revoke | เพิกถอน token | ไม่ต้องใช้ key |
| POST | /oauth/introspect | ตรวจสถานะ token (Introspection) | introspect |
| POST | /oauth/device/code | ขอรหัสอุปกรณ์ (Device flow) | ไม่ต้องใช้ key |
| GET | /.well-known/openid-configuration | OpenID Connect discovery | ไม่ต้องใช้ key |
| GET | /oauth/userinfo | ข้อมูลผู้ใช้ (UserInfo) | openid |
| GET | /oauth/logout | ออกจากระบบที่ issuer (RP-initiated logout)ใหม่ | ไม่ต้องใช้ key |
| GET | /v1/clients | รายการแอป (client) | clients:read |
| POST | /v1/clients | ลงทะเบียนแอป | clients:write |
| GET | /v1/clients/{client_id} | ดูแอป | clients:read |
| PATCH | /v1/clients/{client_id} | แก้ค่าแอป | clients:write |
| POST | /v1/clients/{client_id}/rotate-secret | หมุน client secret | clients:write |
| GET | /v1/users/{user_id}/consents | ความยินยอมของผู้ใช้ | openid |
| DELETE | /v1/users/{user_id}/consents/{client_id} | ถอนความยินยอม | openid |
เริ่มขอสิทธิ์ (Authorization endpoint)
เปิดในเบราว์เซอร์ของระบบ (แท็บเบราว์เซอร์ในแอปของ iOS/Android — ห้าม WebView) เพื่อให้ผู้ใช้ล็อกอินที่ id.mayarin.example และยินยอม แล้ว redirect กลับพร้อม code ใช้ครั้งเดียว อายุ 60 วินาที · ใช้ได้เฉพาะ response_type=code + PKCE S256
Query parametersquery
response_typeenumจำเป็นต้องเป็น code
client_idstringจำเป็นแอป
redirect_uristring · uriจำเป็นต้องตรงกับที่ลงทะเบียน
scopestringจำเป็นscope คั่นเว้นวรรค (ต้องมี openid ถ้าต้องการ id_token)
statestringจำเป็นค่าสุ่มกัน CSRF — แอปต้องเทียบตอนรับกลับ
noncestringไม่บังคับค่าสุ่มผูกกับ id_token (กัน replay)
code_challengestringจำเป็นBASE64URL(SHA-256(code_verifier)) — ลองสร้างด้วยเครื่องมือท้ายหน้า
code_challenge_methodenumจำเป็นต้องเป็น S256
promptenumไม่บังคับบังคับหน้า login/consent
login_hintstringไม่บังคับอีเมล/เบอร์ที่กรอกไว้ให้
acr_valuesstringไม่บังคับขอระดับการยืนยัน (urn:kunjae:acr:mfa = บังคับ MFA)
ui_localesstringไม่บังคับภาษาหน้าล็อกอิน
max_ageintegerไม่บังคับถ้าล็อกอินนานกว่านี้ (วินาที) ให้ล็อกอินใหม่
ผลลัพธ์
- 302สำเร็จ → กลับแอปพร้อม code + state
- 302ผู้ใช้กดไม่อนุญาต → กลับพร้อม error
- 400redirect_uri ไม่ตรง (ไม่ redirect เพื่อความปลอดภัย แสดงหน้าข้อผิดพลาด)
- 400
invalid_requestคำขอไม่ถูกต้อง - 400
invalid_scopescope ไม่ถูกต้อง - 400
redirect_uri_mismatchredirect_uri ไม่ตรง - 403
consent_requiredต้องขอความยินยอม - 400
unsupported_grant_typeไม่รองรับ grant_type
- prompt=none ใช้เช็กว่ามี session อยู่แล้วโดยไม่แสดงหน้า (ได้ error=login_required ถ้าไม่มี)
- แอปของเครือที่ผู้ใช้ยินยอมครบ scope แล้วจะข้ามหน้ายินยอม
- state ต้องสุ่มใหม่ทุกครั้ง และเทียบก่อนใช้ code
curl -X GET "https://sandbox.api.kunjae.example/oauth/authorize?response_type=code&client_id=kjc_fit_9Lw4&redirect_uri=com.mayarin.fit%3A%2Foauth%2Fcallback&scope=openid%20profile%20phone%20offline_access%20fit%3Acheckin" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/authorize?response_type=code&client_id=kjc_fit_9Lw4&redirect_uri=com.mayarin.fit%3A%2Foauth%2Fcallback&scope=openid%20profile%20phone%20offline_access%20fit%3Acheckin', {
method: 'GET',
headers: {
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/oauth/authorize?response_type=code&client_id=kjc_fit_9Lw4&redirect_uri=com.mayarin.fit%3A%2Foauth%2Fcallback&scope=openid%20profile%20phone%20offline_access%20fit%3Acheckin",
headers={
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json())(ไม่มีเนื้อหา){
"error": "redirect_uri_mismatch",
"error_description": "redirect_uri ไม่ตรงกับที่ลงทะเบียนสำหรับ kjc_fit_9Lw4"
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "invalid_scope",
"message": "scope ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_scope"
}
}{
"error": {
"code": "redirect_uri_mismatch",
"message": "redirect_uri ไม่ตรง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#redirect_uri_mismatch"
}
}{
"error": {
"code": "consent_required",
"message": "ต้องขอความยินยอม",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#consent_required"
}
}{
"error": {
"code": "unsupported_grant_type",
"message": "ไม่รองรับ grant_type",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unsupported_grant_type"
}
}ออก token (Token endpoint)
แลก grant เป็น token — authorization_code (+ code_verifier) · refresh_token (หมุนทุกครั้ง) · client_credentials (ระบบหลังบ้าน) · device_code (จอทีวี) · ตามมาตรฐานรับ application/x-www-form-urlencoded และ KUNJAE รับ JSON ด้วย (ตัวอย่างแบบ form ทุก grant ดูหัวข้อ “Grant types”)
Request bodyapplication/json
grant_typeenumจำเป็นชนิด grant
codestringไม่บังคับauthorization_code จาก redirect หรือ /v1/auth/*
redirect_uristringไม่บังคับค่าเดียวกับตอน authorize
code_verifierstringไม่บังคับสตริงสุ่ม 43–128 ตัว ที่ใช้สร้าง code_challenge
client_idstringจำเป็นแอป (public client ส่งใน body)
refresh_tokenstringไม่บังคับgrant_type=refresh_token
scopestringไม่บังคับขอ scope น้อยลงได้ (ไม่เกินของเดิม)
device_codestringไม่บังคับgrant_type=device_code
client_assertion_typestringไม่บังคับprivate_key_jwt
client_assertionstringไม่บังคับJWT ที่ client ลงลายเซ็นเอง (อายุ ≤ 5 นาที)
ผลลัพธ์
- 200ออก token แล้ว (Cache-Control: no-store)
- 200client_credentials (ไม่มี refresh/id token)
- 400code ใช้แล้ว/หมดอายุ
- 400code_verifier ไม่ตรง
- 400refresh token ถูกใช้ซ้ำ
- 400device flow ยังรอผู้ใช้
- 400
invalid_requestคำขอไม่ถูกต้อง - 400
invalid_grantgrant ไม่ถูกต้อง - 401
invalid_clientยืนยัน client ไม่ผ่าน - 400
unsupported_grant_typeไม่รองรับ grant_type - 400
invalid_scopescope ไม่ถูกต้อง - 400
pkce_mismatchcode_verifier ไม่ตรง - 400
refresh_token_reusedrefresh token ถูกใช้ซ้ำ - 400
authorization_pendingรอผู้ใช้ยืนยัน (device flow) - 400
slow_downถามถี่เกินไป (device flow) - 400
expired_tokendevice_code หมดอายุ - 429
rate_limitedเรียกเกินโควตา
- error ของ /oauth/* ใช้รูปแบบ RFC 6749 { "error", "error_description" } ไม่ใช่ { "error": { "code" } } ของ /v1/*
- refresh_token หมุนทุกครั้ง — เก็บตัวใหม่ทันที ตัวเก่าใช้ซ้ำ = ถูกเพิกถอนทั้งตระกูล (เผื่อเครือข่ายหลุด: ส่งซ้ำตัวเดิมภายใน 10 วินาทีได้ผลเดิม)
- access token เป็น JWT ตรวจเองได้ด้วย JWKS (หน้า JWT)
- เก็บ refresh token ใน Keychain/Keystore เท่านั้น
curl -X POST "https://sandbox.api.kunjae.example/oauth/token" \
-H "Content-Type: application/json" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"grant_type": "authorization_code",
"code": "kjac_Q8mL2xV7pR4tN9wZ",
"redirect_uri": "com.mayarin.fit:/oauth/callback",
"code_verifier": "Vx3kQ9mZ2pL7rT0aB5nW8cE1yH4uJ6sD-fG_iK2oM3q",
"client_id": "kjc_fit_9Lw4"
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"grant_type": "authorization_code",
"code": "kjac_Q8mL2xV7pR4tN9wZ",
"redirect_uri": "com.mayarin.fit:/oauth/callback",
"code_verifier": "Vx3kQ9mZ2pL7rT0aB5nW8cE1yH4uJ6sD-fG_iK2oM3q",
"client_id": "kjc_fit_9Lw4"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.post(
"https://sandbox.api.kunjae.example/oauth/token",
headers={
"Content-Type": "application/json",
"Kunjae-Version": "2026-08-01",
},
json={
"grant_type": "authorization_code",
"code": "kjac_Q8mL2xV7pR4tN9wZ",
"redirect_uri": "com.mayarin.fit:/oauth/callback",
"code_verifier": "Vx3kQ9mZ2pL7rT0aB5nW8cE1yH4uJ6sD-fG_iK2oM3q",
"client_id": "kjc_fit_9Lw4"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6ImF0K2p3dCIsImtpZCI6ImtqLTIwMjYtMDgtcnMifQ.eyJpc3MiOiJodHRwczovL2lkLm1heWFyaW4uZXhhbXBsZSIsInN1YiI6InVzcl84TmYyIiwiYXVkIjoiaHR0cHM6Ly9hcGkubWF5YXJpbi5leGFtcGxlIiwiYXpwIjoia2pjX21hbGxfN1F4MiIsImNsaWVudF9pZCI6ImtqY19tYWxsXzdReDIiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIHBob25lIG9mZmxpbmVfYWNjZXNzIG1hbGw6b3JkZXJzLnJlYWQgcG9pbnRzOnJlYWQgcG9pbnRzOnJlZGVlbSIsImlhdCI6MTc5MTc3NDkwMCwibmJmIjoxNzkxNzc0OTAwLCJleHAiOjE3OTE3NzU4MDAsImF1dGhfdGltZSI6MTc5MTc3NDkwMCwiYWNyIjoidXJuOmt1bmphZTphY3I6bWZhIiwiYW1yIjpbInB3ZCIsIm90cCJdLCJzaWQiOiJzZXNfNEdrOExtIiwianRpIjoiYXRfOVF3Mlp4N1JiMUxjIiwiaHR0cHM6Ly9tYXlhcmluLmV4YW1wbGUvY2xhaW1zL21lbWJlcl9pZCI6Ik1CUi0wMDQ4MjEzIiwiaHR0cHM6Ly9tYXlhcmluLmV4YW1wbGUvY2xhaW1zL21lbWJlcl90aWVyIjoiZ29sZCJ9.ut42PxG7cryuVML1PI8j_kKttAhD8jXRJgwSoA5XeoafEJZsZqNd69gV736f0pNrNKS7SB4Aq47QnCSmai0qRfUXCvuVkkgIqLYKqlcdYgmHz0762hCH9U9DZP2ft1k9UFL-jwdLeHbTUJVZScVaJ4Qn9d3Bkyq3Eb-AC1Mid1EMqdeNbEYvY3fENCFHUg984xVkkcczXQ8SK_T5AQD-fQYZRFfF8zoszt9k5YZI1kIP9ssZ5zdnqRJczSwbRUy_90ymHztiEab2EVeB_m2zYZY7CyTv8bfGlu92pDg-3-WCRadgSfuTgaOf0SOycQxs6D0LQzWRl7E4OLX72YyjMV",
"token_type": "Bearer",
"expires_in": 900,
"scope": "openid profile email phone offline_access mall:orders.read points:read points:redeem",
"refresh_token": "kjr_PFC0CztCRX395ZF9dyoI8_Lep9kZjRj1OLTOKp1G",
"refresh_token_expires_in": 2592000,
"id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtqLTIwMjYtMDgtcnMifQ.eyJpc3MiOiJodHRwczovL2lkLm1heWFyaW4uZXhhbXBsZSIsInN1YiI6InVzcl84TmYyIiwiYXVkIjoia2pjX21hbGxfN1F4MiIsImlhdCI6MTc5MTc3NDkwMCwiZXhwIjoxNzkxNzc4NTAwLCJhdXRoX3RpbWUiOjE3OTE3NzQ5MDAsIm5vbmNlIjoibi00WXg4UXAyUmsiLCJzaWQiOiJzZXNfNEdrOExtIiwiYWNyIjoidXJuOmt1bmphZTphY3I6bWZhIiwiYW1yIjpbInB3ZCIsIm90cCJdLCJhdF9oYXNoIjoiUlFpaHNNaUxyQXVkMUxsWmdlWTd2NCIsIm5hbWUiOiLguJjguJnguIHguKTguJUg4Lio4Lij4Li14Lin4LiH4Lio4LmM4LiX4Lit4LiHIiwiZ2l2ZW5fbmFtZSI6IuC4mOC4meC4geC4pOC4lSIsImZhbWlseV9uYW1lIjoi4Lio4Lij4Li14Lin4LiH4Lio4LmM4LiX4Lit4LiHIiwibmlja25hbWUiOiLguIHguKTguJUiLCJlbWFpbCI6InRoYW5ha3JpdC5zQG1heWFyaW4uZXhhbXBsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJwaG9uZV9udW1iZXIiOiIrNjY4MDAwMDA0MTIiLCJwaG9uZV9udW1iZXJfdmVyaWZpZWQiOnRydWUsImxvY2FsZSI6InRoLVRIIiwiem9uZWluZm8iOiJBc2lhL0Jhbmdrb2siLCJodHRwczovL21heWFyaW4uZXhhbXBsZS9jbGFpbXMvbWVtYmVyX3RpZXIiOiJnb2xkIn0.uyk46gi29uPaUJZTZJPcsI1x0cI0wL8bGHJNf1ygMh-DrJycsAZU9vTv4bNIdNN1i0AKErjhBiM0F5TbLn8SqcFGpbSXpWEFzwOICG2sPI7XBsdm1V93hXVWWiqhXTdgjYaM_5hwEqOfrJHyjLFNbjB_q8nvWFm3YqtKlwIaGmJPzMUPEraPYy2cn6fa9C8auPufpJBWUhx22EcpD9niixTGqynIL1N07QnZLaTJHCMu4YFMBv2YL9mSo9VrqfbPPeEyQs2YQ2igmDJeaUyyvrxTt9CBrW0PxORPK-Tl5w7EXVvkjjpdzDmYhVHYJC85jY6ESDFMmnfaKyS_q3GzFF"
}{
"error": "invalid_grant",
"error_description": "authorization code หมดอายุหรือถูกใช้แล้ว"
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "invalid_grant",
"message": "grant ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_grant"
}
}{
"error": {
"code": "invalid_client",
"message": "ยืนยัน client ไม่ผ่าน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_client"
}
}{
"error": {
"code": "unsupported_grant_type",
"message": "ไม่รองรับ grant_type",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unsupported_grant_type"
}
}{
"error": {
"code": "invalid_scope",
"message": "scope ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_scope"
}
}{
"error": {
"code": "pkce_mismatch",
"message": "code_verifier ไม่ตรง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#pkce_mismatch"
}
}{
"error": {
"code": "refresh_token_reused",
"message": "refresh token ถูกใช้ซ้ำ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#refresh_token_reused"
}
}{
"error": {
"code": "authorization_pending",
"message": "รอผู้ใช้ยืนยัน (device flow)",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#authorization_pending"
}
}{
"error": {
"code": "slow_down",
"message": "ถามถี่เกินไป (device flow)",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#slow_down"
}
}{
"error": {
"code": "expired_token",
"message": "device_code หมดอายุ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#expired_token"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#rate_limited"
}
}เพิกถอน token
เพิกถอน refresh token (และ access token ที่ผูก) ตอนผู้ใช้ออกจากระบบในแอป — ตอบ 200 เสมอแม้ token ไม่ถูกต้อง (RFC 7009)
Request bodyapplication/json
tokenstringจำเป็นtoken ที่จะเพิกถอน
token_type_hintenumไม่บังคับชนิด
client_idstringจำเป็นแอปเจ้าของ token
ผลลัพธ์
- 200เพิกถอนแล้ว (ไม่มีเนื้อหา)
- 400
invalid_requestคำขอไม่ถูกต้อง - 401
invalid_clientยืนยัน client ไม่ผ่าน - 429
rate_limitedเรียกเกินโควตา
- เพิกถอน refresh = session ของแอปนั้นจบ · ต้องการออกทุกแอปใช้ POST /v1/auth/logout scope=all_apps
curl -X POST "https://sandbox.api.kunjae.example/oauth/revoke" \
-H "Content-Type: application/json" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"token": "kjr_PLu2tjI9yaUp3VUbmz8B…MytJBeuQ",
"token_type_hint": "refresh_token",
"client_id": "kjc_mall_7Qx2"
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/revoke', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"token": "kjr_PLu2tjI9yaUp3VUbmz8B…MytJBeuQ",
"token_type_hint": "refresh_token",
"client_id": "kjc_mall_7Qx2"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.post(
"https://sandbox.api.kunjae.example/oauth/revoke",
headers={
"Content-Type": "application/json",
"Kunjae-Version": "2026-08-01",
},
json={
"token": "kjr_PLu2tjI9yaUp3VUbmz8B…MytJBeuQ",
"token_type_hint": "refresh_token",
"client_id": "kjc_mall_7Qx2"
},
timeout=10,
)
res.raise_for_status()
print(res.json())(ไม่มีเนื้อหา){
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "invalid_client",
"message": "ยืนยัน client ไม่ผ่าน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_client"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#rate_limited"
}
}ตรวจสถานะ token (Introspection)
API ปลายทางถามว่า token ยังใช้ได้ไหม รวมถึง session ถูกออกจากระบบแล้วหรือยัง — ใช้กับงานที่ต้องรู้ผลทันที (คืนเงิน แลกแต้ม) นอกนั้นตรวจ JWT เองเร็วกว่า
Request bodyapplication/json
tokenstringจำเป็นaccess หรือ refresh token
token_type_hintenumไม่บังคับชนิด
ผลลัพธ์
- 200token ใช้ได้
- 200ใช้ไม่ได้ (หมดอายุ/เพิกถอน/ไม่รู้จัก)
- 400
invalid_requestคำขอไม่ถูกต้อง - 401
invalid_clientยืนยัน client ไม่ผ่าน - 429
rate_limitedเรียกเกินโควตา
- ยืนยันตัวตนด้วย client_id:client_secret ของ resource server (Basic) — แอปมือถือห้ามเรียก
- แคชผล active=true ได้ไม่เกิน 30 วินาที
curl -X POST "https://sandbox.api.kunjae.example/oauth/introspect" \
-H "Authorization: Basic kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Content-Type: application/json" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"token": "eyJhbGciOiJSUzI1NiIsInR5…X72YyjMV",
"token_type_hint": "access_token"
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/introspect', {
method: 'POST',
headers: {
'Authorization': `Basic ${API_KEY}`,
'Content-Type': 'application/json',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"token": "eyJhbGciOiJSUzI1NiIsInR5…X72YyjMV",
"token_type_hint": "access_token"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.post(
"https://sandbox.api.kunjae.example/oauth/introspect",
headers={
"Authorization": f"Basic {API_KEY}",
"Content-Type": "application/json",
"Kunjae-Version": "2026-08-01",
},
json={
"token": "eyJhbGciOiJSUzI1NiIsInR5…X72YyjMV",
"token_type_hint": "access_token"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"active": true,
"token_type": "access_token",
"scope": "openid profile email phone offline_access mall:orders.read points:read points:redeem",
"client_id": "kjc_mall_7Qx2",
"sub": "usr_8Nf2",
"username": "tha***@mayarin.example",
"aud": "https://api.mayarin.example",
"iss": "https://id.mayarin.example",
"exp": 1791775800,
"iat": 1791774900,
"nbf": 1791774900,
"jti": "at_9Qw2Zx7Rb1Lc",
"sid": "ses_4Gk8Lm",
"acr": "urn:kunjae:acr:mfa",
"amr": [
"pwd",
"otp"
],
"session_status": "active"
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "invalid_client",
"message": "ยืนยัน client ไม่ผ่าน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_client"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#rate_limited"
}
}ขอรหัสอุปกรณ์ (Device flow)
สำหรับจอที่พิมพ์ยาก (ทีวีห้องรับรอง VIP ตู้รับตั๋ว) — ได้ user_code สั้น ๆ ให้ผู้ใช้กรอก/สแกน QR บนมือถือ แล้วจอถาม /oauth/token ทุก interval วินาทีจนผู้ใช้อนุญาต
Request bodyapplication/json
client_idstringจำเป็นแอป (ต้องเปิด grant device_code)
scopestringไม่บังคับscope
ผลลัพธ์
- 200ได้รหัส
- 400
invalid_requestคำขอไม่ถูกต้อง - 401
invalid_clientยืนยัน client ไม่ผ่าน - 400
unsupported_grant_typeไม่รองรับ grant_type - 400
invalid_scopescope ไม่ถูกต้อง
- user_code 8 ตัว (ไม่มีสระ/ตัวที่สับสน เช่น 0/O 1/I) อายุ 10 นาที
- แสดง verification_uri_complete เป็น QR ให้สแกนได้ทันที
- จอสาธารณะ: token ของ device flow อายุ refresh สูงสุด 12 ชม.
curl -X POST "https://sandbox.api.kunjae.example/oauth/device/code" \
-H "Content-Type: application/json" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"client_id": "kjc_cine_3Hp8",
"scope": "openid profile cinema:tickets.read"
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/device/code', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"client_id": "kjc_cine_3Hp8",
"scope": "openid profile cinema:tickets.read"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.post(
"https://sandbox.api.kunjae.example/oauth/device/code",
headers={
"Content-Type": "application/json",
"Kunjae-Version": "2026-08-01",
},
json={
"client_id": "kjc_cine_3Hp8",
"scope": "openid profile cinema:tickets.read"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"device_code": "kjd_Q_5LtRBMX7Z0q6Xn_7oA3n4L0YjDqcbY",
"user_code": "MYRN-4KQT",
"verification_uri": "https://id.mayarin.example/device",
"verification_uri_complete": "https://id.mayarin.example/device?user_code=MYRN-4KQT",
"expires_in": 600,
"interval": 5
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "invalid_client",
"message": "ยืนยัน client ไม่ผ่าน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_client"
}
}{
"error": {
"code": "unsupported_grant_type",
"message": "ไม่รองรับ grant_type",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unsupported_grant_type"
}
}{
"error": {
"code": "invalid_scope",
"message": "scope ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_scope"
}
}OpenID Connect discovery
GET/.well-known/openid-configuration
ค่าตั้งของ issuer — ไลบรารี OIDC ทุกตัวอ่านจากที่นี่ (endpoint ทั้งหมด scope/claim ที่รองรับ alg) · แคชได้ 24 ชม.
ผลลัพธ์
- 200ค่าตั้ง (Cache-Control: max-age=86400)
- 503
service_unavailableปิดปรับปรุงชั่วคราว
curl -X GET "https://sandbox.api.kunjae.example/.well-known/openid-configuration" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/.well-known/openid-configuration', {
method: 'GET',
headers: {
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/.well-known/openid-configuration",
headers={
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"issuer": "https://id.mayarin.example",
"authorization_endpoint": "https://id.mayarin.example/oauth/authorize",
"token_endpoint": "https://id.mayarin.example/oauth/token",
"userinfo_endpoint": "https://id.mayarin.example/oauth/userinfo",
"jwks_uri": "https://id.mayarin.example/.well-known/jwks.json",
"revocation_endpoint": "https://id.mayarin.example/oauth/revoke",
"introspection_endpoint": "https://id.mayarin.example/oauth/introspect",
"device_authorization_endpoint": "https://id.mayarin.example/oauth/device/code",
"end_session_endpoint": "https://id.mayarin.example/oauth/logout",
"scopes_supported": [
"openid",
"profile",
"email",
"phone",
"offline_access",
"mall:orders.read",
"mall:orders.write",
"cinema:tickets.read",
"cinema:tickets.write",
"fit:checkin",
"fit:classes.book",
"points:read",
"points:redeem",
"staff:portal"
],
"response_types_supported": [
"code"
],
"response_modes_supported": [
"query",
"fragment"
],
"grant_types_supported": [
"authorization_code",
"refresh_token",
"client_credentials",
"urn:ietf:params:oauth:grant-type:device_code",
"urn:ietf:params:oauth:grant-type:token-exchange"
],
"code_challenge_methods_supported": [
"S256"
],
"token_endpoint_auth_methods_supported": [
"none",
"client_secret_basic",
"private_key_jwt"
],
"id_token_signing_alg_values_supported": [
"RS256",
"ES256"
],
"subject_types_supported": [
"public"
],
"acr_values_supported": [
"urn:kunjae:acr:pwd",
"urn:kunjae:acr:mfa"
],
"ui_locales_supported": [
"th-TH",
"en"
],
"claims_supported": [
"sub",
"name",
"given_name",
"family_name",
"nickname",
"email",
"email_verified",
"phone_number",
"phone_number_verified",
"locale",
"zoneinfo",
"acr",
"amr",
"sid",
"auth_time"
]
}{
"error": {
"code": "service_unavailable",
"message": "ปิดปรับปรุงชั่วคราว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#service_unavailable"
}
}ข้อมูลผู้ใช้ (UserInfo)
ข้อมูลผู้ใช้ตาม scope ที่ยินยอม — profile = ชื่อ ภาษา · email · phone · claims กำหนดเองตาม JWT › claims
ผลลัพธ์
- 200scope openid profile email phone
- 401token หมดอายุ (หัว WWW-Authenticate: Bearer error="invalid_token")
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 401
token_expiredtoken หมดอายุ - 401
invalid_tokentoken ไม่ถูกต้อง - 403
insufficient_scopescope ไม่พอ
- ตัวอย่าง production จะเห็นอีเมล/เบอร์เต็มเฉพาะแอปที่ผู้ใช้ยินยอมเท่านั้น — แสดงในหน้าจอแบบปิดบัง เช่น 08x-xxx-0412
curl -X GET "https://sandbox.api.kunjae.example/oauth/userinfo" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/userinfo', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/oauth/userinfo",
headers={
"Authorization": f"Bearer {API_KEY}",
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"sub": "usr_8Nf2",
"name": "ธนกฤต ศรีวงศ์ทอง",
"given_name": "ธนกฤต",
"family_name": "ศรีวงศ์ทอง",
"nickname": "กฤต",
"email": "thanakrit.s@mayarin.example",
"email_verified": true,
"phone_number": "+66800000412",
"phone_number_verified": true,
"locale": "th-TH",
"zoneinfo": "Asia/Bangkok",
"https://mayarin.example/claims/member_tier": "gold"
}{
"error": "invalid_token",
"error_description": "access token หมดอายุ"
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "token_expired",
"message": "token หมดอายุ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#token_expired"
}
}{
"error": {
"code": "invalid_token",
"message": "token ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_token"
}
}{
"error": {
"code": "insufficient_scope",
"message": "scope ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#insufficient_scope"
}
}ออกจากระบบที่ issuer (RP-initiated logout)
ออกจาก session เบราว์เซอร์ที่ id.mayarin.example แล้วกลับแอป — แอปอื่นใน session เดียวกันได้ webhook session.revoked
Query parametersquery
id_token_hintstringจำเป็นid_token ล่าสุดของแอป
post_logout_redirect_uristring · uriจำเป็นต้องลงทะเบียนไว้
statestringไม่บังคับค่าสุ่มส่งกลับ
ผลลัพธ์
- 302ออกแล้ว กลับแอป
- 400
invalid_requestคำขอไม่ถูกต้อง - 401
invalid_tokentoken ไม่ถูกต้อง - 400
redirect_uri_mismatchredirect_uri ไม่ตรง
curl -X GET "https://sandbox.api.kunjae.example/oauth/logout?id_token_hint=eyJhbGciOiJSUzI1NiIsInR5%E2%80%A6S_q3GzFF&post_logout_redirect_uri=https%3A%2F%2Fpoints.mayarin.example%2F&state=lo_3Hn8" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/oauth/logout?id_token_hint=eyJhbGciOiJSUzI1NiIsInR5%E2%80%A6S_q3GzFF&post_logout_redirect_uri=https%3A%2F%2Fpoints.mayarin.example%2F&state=lo_3Hn8', {
method: 'GET',
headers: {
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/oauth/logout?id_token_hint=eyJhbGciOiJSUzI1NiIsInR5%E2%80%A6S_q3GzFF&post_logout_redirect_uri=https%3A%2F%2Fpoints.mayarin.example%2F&state=lo_3Hn8",
headers={
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json())(ไม่มีเนื้อหา){
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "invalid_token",
"message": "token ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_token"
}
}{
"error": {
"code": "redirect_uri_mismatch",
"message": "redirect_uri ไม่ตรง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#redirect_uri_mismatch"
}
}รายการแอป (client)
แอปทั้งหมดของเครือที่ลงทะเบียนกับ KUNJAE ID
Query parametersquery
typeenumไม่บังคับกรอง
grant_typestringไม่บังคับแอปที่เปิด grant นี้
statusenumไม่บังคับสถานะ
limitintegerไม่บังคับจำนวนต่อหน้า
starting_afterstringไม่บังคับcursor — ส่งรหัสของรายการสุดท้ายในหน้าก่อน เพื่อดึงหน้าถัดไป
ending_beforestringไม่บังคับcursor — ส่งรหัสของรายการแรก เพื่อดึงหน้าก่อนหน้า
sortstringไม่บังคับเรียงลำดับ (ใส่ - ข้างหน้า = มากไปน้อย)
ผลลัพธ์
- 2006 แอป
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 403
insufficient_scopescope ไม่พอ - 429
rate_limitedเรียกเกินโควตา
curl -X GET "https://sandbox.api.kunjae.example/v1/clients?grant_type=client_credentials&status=active&limit=20" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/clients?grant_type=client_credentials&status=active&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/v1/clients?grant_type=client_credentials&status=active&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v1/clients",
"has_more": false,
"next_cursor": null,
"data": [
{
"id": "kjc_mall_7Qx2",
"object": "client",
"name": "MAYARIN Mall",
"app": "mall",
"type": "public",
"platform": "iOS / Android",
"logo_uri": "https://cdn.mayarin.example/apps/mall.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"com.mayarin.mall:/oauth/callback"
],
"post_logout_redirect_uris": [
"com.mayarin.mall:/logout"
],
"allowed_scopes": [
"openid",
"profile",
"email",
"phone",
"offline_access",
"mall:orders.read",
"mall:orders.write",
"points:read",
"points:redeem"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 2592000,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2024-02-01T09:00:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-mall"
}
},
{
"id": "kjc_cine_3Hp8",
"object": "client",
"name": "MAYARIN Cinema",
"app": "cinema",
"type": "public",
"platform": "iOS / Android / จอทีวี (device flow)",
"logo_uri": "https://cdn.mayarin.example/apps/cinema.png",
"grant_types": [
"authorization_code",
"refresh_token",
"urn:ietf:params:oauth:grant-type:device_code"
],
"redirect_uris": [
"com.mayarin.cinema:/oauth/callback"
],
"post_logout_redirect_uris": [
"com.mayarin.cinema:/logout"
],
"allowed_scopes": [
"openid",
"profile",
"offline_access",
"cinema:tickets.read",
"cinema:tickets.write",
"points:read"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 2592000,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2024-11-20T14:30:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-cinema"
}
},
{
"id": "kjc_fit_9Lw4",
"object": "client",
"name": "MAYARIN Fit",
"app": "fit",
"type": "public",
"platform": "iOS / Android",
"logo_uri": "https://cdn.mayarin.example/apps/fit.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"com.mayarin.fit:/oauth/callback"
],
"post_logout_redirect_uris": [
"com.mayarin.fit:/logout"
],
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 2592000,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2026-05-10T10:00:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-fit"
}
},
{
"id": "kjc_pts_5Vd1",
"object": "client",
"name": "MAYARIN Points",
"app": "points",
"type": "public",
"platform": "เว็บ (SPA) / iOS / Android",
"logo_uri": "https://cdn.mayarin.example/apps/points.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"https://points.mayarin.example/callback",
"com.mayarin.points:/oauth/callback"
],
"post_logout_redirect_uris": [
"https://points.mayarin.example/"
],
"allowed_scopes": [
"openid",
"profile",
"email",
"offline_access",
"points:read",
"points:redeem"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 1209600,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2024-02-01T09:00:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-points"
}
},
{
"id": "kjc_staff_8Rt3",
"object": "client",
"name": "MAYARIN Staff Portal",
"app": "staff",
"type": "confidential",
"platform": "เว็บหลังบ้าน (เซิร์ฟเวอร์)",
"logo_uri": "https://cdn.mayarin.example/apps/staff.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"https://staff.mayarin.example/auth/callback"
],
"post_logout_redirect_uris": [
"https://staff.mayarin.example/auth/"
],
"allowed_scopes": [
"openid",
"profile",
"email",
"offline_access",
"staff:portal"
],
"pkce": "required",
"token_endpoint_auth_method": "client_secret_basic",
"client_secret_last4": "Qx7a",
"jwks_uri": null,
"access_token_ttl": 600,
"refresh_token_ttl": 43200,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "skip",
"status": "active",
"created_at": "2024-02-01T09:00:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-staff"
}
},
{
"id": "kjc_backoffice_2Mn6",
"object": "client",
"name": "Back-office Services",
"app": "backoffice",
"type": "confidential",
"platform": "ระบบหลังบ้าน (machine-to-machine)",
"logo_uri": "https://cdn.mayarin.example/apps/backoffice.png",
"grant_types": [
"client_credentials",
"urn:ietf:params:oauth:grant-type:token-exchange"
],
"redirect_uris": [],
"post_logout_redirect_uris": [],
"allowed_scopes": [
"members:read",
"points:adjust",
"authz:check"
],
"pkce": "n/a",
"token_endpoint_auth_method": "private_key_jwt",
"client_secret_last4": null,
"jwks_uri": "https://backoffice.mayarin.example/.well-known/jwks.json",
"access_token_ttl": 3600,
"refresh_token_ttl": 0,
"refresh_token_rotation": false,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "skip",
"status": "active",
"created_at": "2024-06-14T16:20:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "platform"
}
}
]
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "insufficient_scope",
"message": "scope ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#insufficient_scope"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#rate_limited"
}
}ลงทะเบียนแอป
เพิ่มแอปใหม่ — public client (มือถือ/SPA) ไม่มี secret และต้อง PKCE · confidential ได้ client_secret ครั้งเดียวใน response นี้ (เก็บใน vault ทันที)
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ต่อคำขอ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างซ้ำ
Request bodyapplication/json
namestringจำเป็นชื่อที่ผู้ใช้เห็นบนหน้ายินยอม
appstringจำเป็นรหัสแอปในเครือ
typeenumจำเป็นpublic = แอปมือถือ/SPA (เก็บความลับไม่ได้) · confidential = เซิร์ฟเวอร์
platformstringไม่บังคับแพลตฟอร์ม
logo_uristring · uriไม่บังคับโลโก้บนหน้ายินยอม (https)
grant_typesarray<string>จำเป็นgrant ที่อนุญาต (เปิดเฉพาะที่ใช้)
redirect_urisarray<string>ไม่บังคับURI ที่รับ code — ต้องตรงทุกตัวอักษร ไม่รับ wildcard
post_logout_redirect_urisarray<string>ไม่บังคับURI หลังออกจากระบบ
allowed_scopesarray<string>จำเป็นscope ที่แอปนี้ขอได้
pkceenumไม่บังคับบังคับ PKCE (public client ต้อง required)
token_endpoint_auth_methodenumจำเป็นวิธียืนยัน client ที่ /oauth/token
jwks_uristring · uriไม่บังคับกุญแจสาธารณะของ client (private_key_jwt)
access_token_ttlintegerไม่บังคับอายุ access token (วินาที)
refresh_token_ttlintegerไม่บังคับอายุ refresh token แบบไม่ใช้ (วินาที) · 0 = ไม่ออก
refresh_token_rotationbooleanไม่บังคับออก refresh ใหม่ทุกครั้งที่ใช้ + ตรวจใช้ซ้ำ
id_token_signed_algenumไม่บังคับอัลกอริทึมลงลายเซ็น id_token
consentenumไม่บังคับการขอความยินยอม
metadataobjectไม่บังคับข้อมูลเสริมของคุณ (คีย์ ≤ 40 ตัว ค่า ≤ 500 ตัวอักษร สูงสุด 20 คู่)
ผลลัพธ์
- 201สร้างแล้ว — client_secret แสดงครั้งเดียว
- 422public client ขอ client_credentials
- 400
invalid_requestคำขอไม่ถูกต้อง - 401
unauthorizedไม่ได้ยืนยันตัวตน - 403
insufficient_scopescope ไม่พอ - 422
validation_failedข้อมูลไม่ผ่านกฎ - 400
invalid_scopescope ไม่ถูกต้อง - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง
- redirect_uri ต้องเป็น https หรือ custom scheme ของแอป (ไม่รับ http ยกเว้น 127.0.0.1 ใน sandbox)
curl -X POST "https://sandbox.api.kunjae.example/v1/clients" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"name": "MAYARIN Parking",
"app": "parking",
"type": "confidential",
"platform": "เซิร์ฟเวอร์ระบบลานจอด",
"grant_types": [
"client_credentials"
],
"allowed_scopes": [
"members:read"
],
"token_endpoint_auth_method": "client_secret_basic",
"access_token_ttl": 3600,
"refresh_token_ttl": 0,
"metadata": {
"owner_team": "app-parking"
}
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/clients', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"name": "MAYARIN Parking",
"app": "parking",
"type": "confidential",
"platform": "เซิร์ฟเวอร์ระบบลานจอด",
"grant_types": [
"client_credentials"
],
"allowed_scopes": [
"members:read"
],
"token_endpoint_auth_method": "client_secret_basic",
"access_token_ttl": 3600,
"refresh_token_ttl": 0,
"metadata": {
"owner_team": "app-parking"
}
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.post(
"https://sandbox.api.kunjae.example/v1/clients",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Kunjae-Version": "2026-08-01",
},
json={
"name": "MAYARIN Parking",
"app": "parking",
"type": "confidential",
"platform": "เซิร์ฟเวอร์ระบบลานจอด",
"grant_types": [
"client_credentials"
],
"allowed_scopes": [
"members:read"
],
"token_endpoint_auth_method": "client_secret_basic",
"access_token_ttl": 3600,
"refresh_token_ttl": 0,
"metadata": {
"owner_team": "app-parking"
}
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "kjc_park_6Ty3",
"object": "client",
"name": "MAYARIN Parking",
"app": "parking",
"type": "confidential",
"grant_types": [
"client_credentials"
],
"allowed_scopes": [
"members:read"
],
"token_endpoint_auth_method": "client_secret_basic",
"client_secret": "kjcs_lAvB3TtG3VmwxeudsAaoMpR2yV-vIVxyUvBBYyek",
"client_secret_last4": "Yyek",
"access_token_ttl": 3600,
"refresh_token_ttl": 0,
"status": "active",
"created_at": "2026-10-12T11:02:00+07:00"
}{
"error": {
"code": "validation_failed",
"message": "public client ใช้ client_credentials ไม่ได้",
"param": "grant_types",
"request_id": "req_5Pq8Tz2Nw",
"doc_url": "https://docs.kunjae.example/errors#validation_failed"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "insufficient_scope",
"message": "scope ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#insufficient_scope"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#validation_failed"
}
}{
"error": {
"code": "invalid_scope",
"message": "scope ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_scope"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่ body ต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#idempotency_conflict"
}
}ดูแอป
ค่าตั้งของแอป 1 ตัว (ไม่คืน secret)
Path parameterspath
client_idstringจำเป็นclient_id
ผลลัพธ์
- 200พบ
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 404
resource_not_foundไม่พบข้อมูล
curl -X GET "https://sandbox.api.kunjae.example/v1/clients/kjc_fit_9Lw4" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/clients/kjc_fit_9Lw4', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/v1/clients/kjc_fit_9Lw4",
headers={
"Authorization": f"Bearer {API_KEY}",
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "kjc_fit_9Lw4",
"object": "client",
"name": "MAYARIN Fit",
"app": "fit",
"type": "public",
"platform": "iOS / Android",
"logo_uri": "https://cdn.mayarin.example/apps/fit.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"com.mayarin.fit:/oauth/callback"
],
"post_logout_redirect_uris": [
"com.mayarin.fit:/logout"
],
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 2592000,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2026-05-10T10:00:00+07:00",
"updated_at": "2026-08-20T11:00:00+07:00",
"metadata": {
"owner_team": "app-fit"
}
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#resource_not_found"
}
}แก้ค่าแอป
แก้ redirect URI, scope, อายุ token — การลด scope มีผลกับ token ใหม่ทันที token เดิมหมดอายุตามรอบ
Path parameterspath
client_idstringจำเป็นclient_id
Request bodyapplication/json
allowed_scopesarray<string>ไม่บังคับscope ใหม่ทั้งชุด
redirect_urisarray<string>ไม่บังคับURI ทั้งชุด
access_token_ttlintegerไม่บังคับอายุ access token
statusenumไม่บังคับปิดแอปฉุกเฉิน
ผลลัพธ์
- 200แก้แล้ว
- 400
invalid_requestคำขอไม่ถูกต้อง - 401
unauthorizedไม่ได้ยืนยันตัวตน - 404
resource_not_foundไม่พบข้อมูล - 422
validation_failedข้อมูลไม่ผ่านกฎ - 400
invalid_scopescope ไม่ถูกต้อง
curl -X PATCH "https://sandbox.api.kunjae.example/v1/clients/kjc_fit_9Lw4" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Content-Type: application/json" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"redirect_uris": [],
"access_token_ttl": 900,
"status": "active"
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/clients/kjc_fit_9Lw4', {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"redirect_uris": [],
"access_token_ttl": 900,
"status": "active"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.patch(
"https://sandbox.api.kunjae.example/v1/clients/kjc_fit_9Lw4",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Kunjae-Version": "2026-08-01",
},
json={
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"redirect_uris": [],
"access_token_ttl": 900,
"status": "active"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "kjc_fit_9Lw4",
"object": "client",
"name": "MAYARIN Fit",
"app": "fit",
"type": "public",
"platform": "iOS / Android",
"logo_uri": "https://cdn.mayarin.example/apps/fit.png",
"grant_types": [
"authorization_code",
"refresh_token"
],
"redirect_uris": [
"com.mayarin.fit:/oauth/callback"
],
"post_logout_redirect_uris": [
"com.mayarin.fit:/logout"
],
"allowed_scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin",
"fit:classes.book"
],
"pkce": "required",
"token_endpoint_auth_method": "none",
"client_secret_last4": null,
"jwks_uri": null,
"access_token_ttl": 900,
"refresh_token_ttl": 2592000,
"refresh_token_rotation": true,
"id_token_signed_alg": "RS256",
"first_party": true,
"consent": "once_per_scope",
"status": "active",
"created_at": "2026-05-10T10:00:00+07:00",
"updated_at": "2026-10-12T11:05:00+07:00",
"metadata": {
"owner_team": "app-fit"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#resource_not_found"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#validation_failed"
}
}{
"error": {
"code": "invalid_scope",
"message": "scope ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_scope"
}
}หมุน client secret
POST/v1/clients/{client_id}/rotate-secret
ออก secret ใหม่ — secret เดิมยังใช้ได้ตามช่วงผ่อนผัน (ค่าเริ่ม 24 ชม.) เพื่อทยอยเปลี่ยนทุกเซิร์ฟเวอร์ · ตั้ง 0 ถ้า secret รั่ว (ใช้ไม่ได้ทันที)
Path parameterspath
client_idstringจำเป็นconfidential client
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ต่อคำขอ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างซ้ำ
Request bodyapplication/json
grace_periodintegerไม่บังคับวินาทีที่ secret เดิมยังใช้ได้
reasonstringไม่บังคับเหตุผล
ผลลัพธ์
- 200ได้ secret ใหม่ (แสดงครั้งเดียว)
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 404
resource_not_foundไม่พบข้อมูล - 422
validation_failedข้อมูลไม่ผ่านกฎ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง
curl -X POST "https://sandbox.api.kunjae.example/v1/clients/kjc_staff_8Rt3/rotate-secret" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Kunjae-Version: 2026-08-01" \
-d '{
"grace_period": 86400,
"reason": "หมุนตามรอบ 180 วัน"
}'const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/clients/kjc_staff_8Rt3/rotate-secret', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Kunjae-Version': '2026-08-01',
},
body: JSON.stringify({
"grace_period": 86400,
"reason": "หมุนตามรอบ 180 วัน"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.post(
"https://sandbox.api.kunjae.example/v1/clients/kjc_staff_8Rt3/rotate-secret",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Kunjae-Version": "2026-08-01",
},
json={
"grace_period": 86400,
"reason": "หมุนตามรอบ 180 วัน"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"client_id": "kjc_staff_8Rt3",
"object": "client_secret",
"client_secret": "kjcs_lFbDiDIAXZDcvb972Bth4N875xkg88X8RVb8PnYu",
"previous_secret_expires_at": "2026-10-13T11:10:00+07:00",
"created_at": "2026-10-12T11:10:00+07:00"
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#resource_not_found"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#validation_failed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่ body ต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#idempotency_conflict"
}
}ความยินยอมของผู้ใช้
GET/v1/users/{user_id}/consents
หน้า “แอปที่เชื่อมกับบัญชี” — ผู้ใช้เห็นว่าแอปในเครือไหนเข้าถึงข้อมูลอะไร ตั้งแต่เมื่อไร (PDPA สิทธิ์ขอทราบ) · ใช้ me แทน user_id ได้
Path parameterspath
user_idstringจำเป็นผู้ใช้ หรือ me
Query parametersquery
limitintegerไม่บังคับจำนวนต่อหน้า
starting_afterstringไม่บังคับcursor — ส่งรหัสของรายการสุดท้ายในหน้าก่อน เพื่อดึงหน้าถัดไป
ending_beforestringไม่บังคับcursor — ส่งรหัสของรายการแรก เพื่อดึงหน้าก่อนหน้า
sortstringไม่บังคับเรียงลำดับ (ใส่ - ข้างหน้า = มากไปน้อย)
ผลลัพธ์
- 2004 แอป
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 401
token_expiredtoken หมดอายุ - 404
resource_not_foundไม่พบข้อมูล
curl -X GET "https://sandbox.api.kunjae.example/v1/users/usr_8Nf2/consents?limit=20" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/users/usr_8Nf2/consents?limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.get(
"https://sandbox.api.kunjae.example/v1/users/usr_8Nf2/consents?limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v1/users/usr_8Nf2/consents",
"has_more": false,
"next_cursor": null,
"data": [
{
"id": "cns_mall_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_mall_7Qx2",
"client_name": "MAYARIN Mall",
"legal_entity": "บริษัท มายาริน รีเทล จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"email",
"phone",
"offline_access",
"mall:orders.read",
"points:read",
"points:redeem"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "email",
"desc": "อีเมล + email_verified"
},
{
"scope": "phone",
"desc": "เบอร์โทร E.164 + phone_number_verified"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "mall:orders.read",
"desc": "อ่านคำสั่งซื้อของตัวเองในห้าง"
},
{
"scope": "points:read",
"desc": "ดูยอดแต้มและประวัติ"
},
{
"scope": "points:redeem",
"desc": "แลกแต้มเป็นคูปอง/ส่วนลด"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2024-03-18T19:43:02+07:00",
"updated_at": "2025-08-10T12:00:00+07:00",
"revoked_at": null
},
{
"id": "cns_points_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_pts_5Vd1",
"client_name": "MAYARIN Points",
"legal_entity": "บริษัท มายาริน รีวอร์ด จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"email",
"offline_access",
"points:read",
"points:redeem"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "email",
"desc": "อีเมล + email_verified"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "points:read",
"desc": "ดูยอดแต้มและประวัติ"
},
{
"scope": "points:redeem",
"desc": "แลกแต้มเป็นคูปอง/ส่วนลด"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2024-03-18T19:50:40+07:00",
"updated_at": "2024-03-18T19:50:40+07:00",
"revoked_at": null
},
{
"id": "cns_cinema_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_cine_3Hp8",
"client_name": "MAYARIN Cinema",
"legal_entity": "บริษัท มายาริน ซีนีม่า จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"offline_access",
"cinema:tickets.read",
"cinema:tickets.write"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "cinema:tickets.read",
"desc": "ดูตั๋วภาพยนตร์ที่ซื้อแล้ว"
},
{
"scope": "cinema:tickets.write",
"desc": "จอง/ซื้อตั๋วภาพยนตร์"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2025-01-04T18:22:15+07:00",
"updated_at": "2025-01-04T18:22:15+07:00",
"revoked_at": null
},
{
"id": "cns_fit_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_fit_9Lw4",
"client_name": "MAYARIN Fit",
"legal_entity": "บริษัท มายาริน ฟิตเนส จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "phone",
"desc": "เบอร์โทร E.164 + phone_number_verified"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "fit:checkin",
"desc": "เช็กอินประตูฟิตเนส"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2026-06-02T06:10:00+07:00",
"updated_at": "2026-06-02T06:10:00+07:00",
"revoked_at": null
}
]
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "token_expired",
"message": "token หมดอายุ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#token_expired"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#resource_not_found"
}
}ถอนความยินยอม
DELETE/v1/users/{user_id}/consents/{client_id}
ผู้ใช้ถอนความยินยอมให้แอปหนึ่ง — เพิกถอน token ทุกตัวของแอปนั้น และครั้งหน้าที่เปิดแอปจะเห็นหน้ายินยอมใหม่ (PDPA สิทธิ์ถอนความยินยอม)
Path parameterspath
user_idstringจำเป็นผู้ใช้ หรือ me
client_idstringจำเป็นแอป
ผลลัพธ์
- 200ถอนแล้ว
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 404
resource_not_foundไม่พบข้อมูล
- ข้อมูลที่แอปนั้นเก็บไว้แล้วต้องลบตามนโยบายของแอป — KUNJAE ส่ง webhook consent.revoked ให้แอปดำเนินการ
curl -X DELETE "https://sandbox.api.kunjae.example/v1/users/usr_8Nf2/consents/kjc_cine_3Hp8" \
-H "Authorization: Bearer kj_test_mgmt_7Hd2Qx9LmP4w" \
-H "Kunjae-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // kj_test_mgmt_7Hd2Qx9LmP4w
const res = await fetch('https://sandbox.api.kunjae.example/v1/users/usr_8Nf2/consents/kjc_cine_3Hp8', {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Kunjae-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # kj_test_mgmt_7Hd2Qx9LmP4w
res = requests.delete(
"https://sandbox.api.kunjae.example/v1/users/usr_8Nf2/consents/kjc_cine_3Hp8",
headers={
"Authorization": f"Bearer {API_KEY}",
"Kunjae-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "cns_cinema_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_cine_3Hp8",
"client_name": "MAYARIN Cinema",
"legal_entity": "บริษัท มายาริน ซีนีม่า จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"offline_access",
"cinema:tickets.read",
"cinema:tickets.write"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "cinema:tickets.read",
"desc": "ดูตั๋วภาพยนตร์ที่ซื้อแล้ว"
},
{
"scope": "cinema:tickets.write",
"desc": "จอง/ซื้อตั๋วภาพยนตร์"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2025-01-04T18:22:15+07:00",
"updated_at": "2025-01-04T18:22:15+07:00",
"revoked_at": "2026-10-12T21:30:00+07:00",
"tokens_revoked": 1
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#unauthorized"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#resource_not_found"
}
}Grant types — ใช้แบบไหนเมื่อไร
ตัวอย่างใน endpoint ด้านบนส่ง JSON (KUNJAE รับได้) แต่ไลบรารี OAuth ส่วนใหญ่ส่ง application/x-www-form-urlencoded ตามมาตรฐาน — ด้านล่างคือคำขอแบบ form ของทุก grant
| grant | ใช้กับ | แอปในเครือ | refresh |
|---|---|---|---|
authorization_code + PKCE | แอปมือถือ / SPA / เว็บหลังบ้าน | MAYARIN Mall, MAYARIN Cinema, MAYARIN Fit, MAYARIN Points, MAYARIN Staff Portal | มี (หมุนทุกครั้ง) |
refresh_token | แอปที่ได้ offline_access | MAYARIN Mall, MAYARIN Cinema, MAYARIN Fit, MAYARIN Points, MAYARIN Staff Portal | ได้ตัวใหม่ทุกครั้ง |
client_credentials | ระบบหลังบ้าน (ไม่มีผู้ใช้) | Back-office Services | ไม่มี — ขอใหม่เมื่อหมด |
device_code | จอทีวี / ตู้ | MAYARIN Cinema | มี (อายุ ≤ 12 ชม.) |
curl -X POST "https://sandbox.api.kunjae.example/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=kjac_Q8mL2xV7pR4tN9wZ" \
-d "redirect_uri=com.mayarin.fit%3A%2Foauth%2Fcallback" \
-d "code_verifier=Vx3kQ9mZ2pL7rT0aB5nW8cE1yH4uJ6sD-fG_iK2oM3q" \
-d "client_id=kjc_fit_9Lw4"curl -X POST "https://sandbox.api.kunjae.example/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "refresh_token=kjr_PFC0CztCRX395ZF9dyoI8_Lep9kZjRj1OLTOKp1G" \
-d "client_id=kjc_mall_7Qx2"# ระบบหลังบ้าน: ลงลายเซ็น client_assertion (JWT อายุ ≤ 5 นาที) ด้วยกุญแจส่วนตัวของ client
curl -X POST "https://sandbox.api.kunjae.example/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=kjc_backoffice_2Mn6" \
-d "scope=members:read points:adjust" \
-d "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer" \
-d "client_assertion=eyJhbGciOiJFUzI1NiIsImtpZCI6ImJvLTIwMjYifQ…"curl -X POST "https://sandbox.api.kunjae.example/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=urn:ietf:params:oauth:grant-type:device_code" \
-d "device_code=kjd_Q_5LtRBMX7Z0q6Xn_7oA3n4L0YjDqcbY" \
-d "client_id=kjc_cine_3Hp8"- ไม่รองรับ Implicit (response_type=token) และ Resource Owner Password — ใช้ Authorization Code + PKCE แทน
- แอปมือถือ/SPA ห้ามฝัง client secret — public client ยืนยันตัวด้วย PKCE เท่านั้น
Webhooks — แจ้งเหตุการณ์ไปที่ระบบของคุณ
ลงทะเบียน URL ปลายทาง แล้วระบบจะส่ง POST พร้อม JSON ทุกครั้งที่เกิดเหตุการณ์ด้านล่าง · ตอบกลับ 2xx ภายใน 10 วินาที ไม่งั้นจะส่งซ้ำตามตาราง · ทุกคำขอมีหัว Kunjae-Signature ให้ตรวจว่ามาจากเราจริง · event อาจมาซ้ำหรือสลับลำดับ ให้ใช้ id กันประมวลผลซ้ำ
consent.grantedผู้ใช้ยินยอมให้แอป
ส่งเมื่อ: กดอนุญาตบนหน้ายินยอม (ครั้งแรกหรือเพิ่ม scope)
{
"id": "evt_01JB7Q00",
"type": "consent.granted",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "cns_fit_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_fit_9Lw4",
"client_name": "MAYARIN Fit",
"legal_entity": "บริษัท มายาริน ฟิตเนส จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"phone",
"offline_access",
"fit:checkin"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "phone",
"desc": "เบอร์โทร E.164 + phone_number_verified"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "fit:checkin",
"desc": "เช็กอินประตูฟิตเนส"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2026-06-02T06:10:00+07:00",
"updated_at": "2026-06-02T06:10:00+07:00",
"revoked_at": null
}
}consent.revokedผู้ใช้ถอนความยินยอม
ส่งเมื่อ: DELETE consents หรือถอนในหน้าโปรไฟล์ — แอปต้องลบข้อมูลตามนโยบาย
{
"id": "evt_01JB7Q01",
"type": "consent.revoked",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "cns_cinema_8Nf2",
"object": "consent",
"user_id": "usr_8Nf2",
"client_id": "kjc_cine_3Hp8",
"client_name": "MAYARIN Cinema",
"legal_entity": "บริษัท มายาริน ซีนีม่า จำกัด (สมมติ)",
"scopes": [
"openid",
"profile",
"offline_access",
"cinema:tickets.read",
"cinema:tickets.write"
],
"scope_details": [
{
"scope": "openid",
"desc": "จำเป็นสำหรับ OpenID Connect — ได้ id_token + sub"
},
{
"scope": "profile",
"desc": "ชื่อ ชื่อเล่น ภาษา เขตเวลา"
},
{
"scope": "offline_access",
"desc": "ได้ refresh_token (ใช้ต่อได้เมื่อแอปปิด)"
},
{
"scope": "cinema:tickets.read",
"desc": "ดูตั๋วภาพยนตร์ที่ซื้อแล้ว"
},
{
"scope": "cinema:tickets.write",
"desc": "จอง/ซื้อตั๋วภาพยนตร์"
}
],
"purpose": "ให้บริการสมาชิกและสะสมแต้มร่วมในเครือ MAYARIN",
"privacy_notice_version": "2026-03",
"channel": "consent_screen",
"granted_at": "2025-01-04T18:22:15+07:00",
"updated_at": "2025-01-04T18:22:15+07:00",
"revoked_at": "2026-10-12T21:30:00+07:00"
}
}token.reuse_detectedตรวจพบ refresh token ถูกใช้ซ้ำ
ส่งเมื่อ: refresh ตัวที่หมุนไปแล้วถูกส่งมาอีก (เพิกถอนทั้งตระกูลแล้ว)
{
"id": "evt_01JB7Q02",
"type": "token.reuse_detected",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"user_id": "usr_8Nf2",
"client_id": "kjc_mall_7Qx2",
"session_id": "ses_4Gk8Lm",
"refresh_family": "rtf_4Gk8Lm",
"ip": "198.51.100.201",
"revoked_tokens": 2,
"detected_at": "2026-10-12T13:42:10+07:00"
}
}device.authorizedผู้ใช้อนุญาตอุปกรณ์
ส่งเมื่อ: device flow สำเร็จ
{
"id": "evt_01JB7Q03",
"type": "device.authorized",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"user_id": "usr_8Nf2",
"client_id": "kjc_cine_3Hp8",
"user_code": "MYRN-4KQT",
"session_id": "ses_7Mq1Hd",
"device_name": "จอทีวี ห้องพักรับรอง VIP โรง 5",
"authorized_at": "2026-10-11T19:02:44+07:00"
}
}client.createdลงทะเบียนแอปใหม่
ส่งเมื่อ: POST /v1/clients
{
"id": "evt_01JB7Q04",
"type": "client.created",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"client_id": "kjc_park_6Ty3",
"name": "MAYARIN Parking",
"type": "confidential",
"created_by": "usr_1Ae5"
}
}client.secret_rotatedหมุน secret
ส่งเมื่อ: POST rotate-secret
{
"id": "evt_01JB7Q05",
"type": "client.secret_rotated",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"client_id": "kjc_staff_8Rt3",
"previous_secret_expires_at": "2026-10-13T11:10:00+07:00",
"rotated_by": "usr_1Ae5"
}
}ส่งซ้ำเมื่อปลายทางไม่ตอบ
- 1ทันที
- 21 นาที
- 35 นาที
- 430 นาที
- 52 ชั่วโมง
- 66 ชั่วโมง
- 724 ชั่วโมง (ครั้งสุดท้าย)
ครบทุกครั้งแล้วยังล้มเหลว → ปิด endpoint อัตโนมัติและส่งอีเมลแจ้งผู้ดูแล · ดูประวัติการส่งและกดส่งซ้ำได้ในแดชบอร์ด
ตรวจลายเซ็น
# ลายเซ็นอยู่ในหัว Kunjae-Signature: t=<unix>,v1=<hex>
# คำนวณ HMAC-SHA256(secret, "<t>.<raw body>") แล้วเทียบกับ v1
printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET"import crypto from 'node:crypto';
// ใช้ raw body (ยังไม่ parse JSON) เท่านั้น
export function verify(rawBody, sigHeader, secret) {
const parts = Object.fromEntries(sigHeader.split(',').map((p) => p.split('=')));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (age > 300) return false; // เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
const expected = crypto.createHmac('sha256', secret).update(parts.t + '.' + rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}import hmac, hashlib, time
def verify(raw_body: bytes, sig_header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in sig_header.split(","))
if abs(time.time() - int(parts["t"])) > 300:
return False # เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
msg = parts["t"].encode() + b"." + raw_body
expected = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Errors — รหัสข้อผิดพลาด
ทุก error ตอบกลับเป็น JSON รูปแบบเดียวกัน พร้อม request_id สำหรับแจ้งทีมสนับสนุน · รหัส HTTP บอกกลุ่มของปัญหา ส่วน error.code บอกสาเหตุที่แน่นอน (ใช้เขียนเงื่อนไขในโค้ดได้ เพราะไม่เปลี่ยนตามภาษา)
- 4xx คำขอไม่ถูกต้อง — แก้ที่ฝั่งผู้เรียก ส่งซ้ำแบบเดิมจะได้ผลเดิม
- 5xx ปัญหาฝั่งระบบ — ลองใหม่แบบเว้นระยะ (exponential backoff) พร้อม Idempotency-Key
{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"param": "items[0].quantity",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.kunjae.example/errors#invalid_request"
}
}| HTTP | code | ความหมาย | วิธีแก้ |
|---|---|---|---|
| 400 | invalid_request | คำขอไม่ถูกต้อง ฟิลด์ที่จำเป็นขาด ชนิดข้อมูลผิด หรือ JSON เสีย — ดูฟิลด์ใน error.param | ตรวจ body/query ตาม schema ของ endpoint แล้วส่งใหม่ |
| 401 | unauthorized | ไม่ได้ยืนยันตัวตน ไม่มีหัว Authorization หรือ management key ผิด/ถูกเพิกถอน | ส่ง Authorization: Bearer <key> ที่ถูกต้อง · sandbox ใช้ kj_test_… production ใช้ kj_live_… |
| 401 | token_expired | token หมดอายุ access token เลยเวลา exp แล้ว (เผื่อนาฬิกาคลาดได้ 60 วินาที) | ใช้ refresh_token ขอ token ใหม่ที่ POST /oauth/token แล้วเรียกซ้ำ |
| 401 | invalid_token | token ไม่ถูกต้อง ลายเซ็นไม่ผ่าน iss/aud ไม่ตรง หรือ token ถูกเพิกถอน | อย่าแก้ไข token เอง · ขอ token ใหม่ · ตรวจว่าใช้ token ของ environment เดียวกัน |
| 403 | insufficient_scope | scope ไม่พอ token/key ไม่มี scope ที่ endpoint ต้องการ (ดูหัว WWW-Authenticate) | ขอ scope เพิ่มตอน authorize หรือสร้าง key ที่มี scope ที่ต้องใช้ |
| 404 | resource_not_found | ไม่พบข้อมูล รหัสที่ระบุไม่มีอยู่ หรืออยู่คนละ environment (sandbox/production) | ตรวจรหัสและ base URL ที่ใช้ |
| 422 | validation_failed | ข้อมูลไม่ผ่านกฎ รูปแบบถูกแต่ค่าผิดกฎธุรกิจ (เช่น เบอร์ไม่ใช่ E.164 วันหมดอายุย้อนหลัง) | อ่าน error.details[] แล้วแก้ทีละฟิลด์ |
| 400 | invalid_grant | grant ไม่ถูกต้อง authorization code/refresh token หมดอายุ ใช้แล้ว หรือออกให้ client อื่น | เริ่ม authorize ใหม่ · ห้ามใช้ code ซ้ำ (ใช้ได้ครั้งเดียว อายุ 60 วินาที) |
| 401 | invalid_client | ยืนยัน client ไม่ผ่าน client_id ไม่มี client_secret/private_key_jwt ผิด หรือ client ถูกปิด | ตรวจ credential ของ client · หมุน secret ถ้ารั่ว |
| 400 | unsupported_grant_type | ไม่รองรับ grant_type client นี้ไม่ได้เปิด grant ที่ขอ | เปิด grant ใน PATCH /v1/clients/{client_id} (เฉพาะที่จำเป็น) |
| 400 | invalid_scope | scope ไม่ถูกต้อง ขอ scope ที่ไม่มี หรือเกินกว่าที่ client ได้รับอนุญาต | ขอเฉพาะ scope ในรายการของ client |
| 400 | redirect_uri_mismatch | redirect_uri ไม่ตรง ต้องตรงทุกตัวอักษรกับที่ลงทะเบียน (ไม่รับ wildcard) | ลงทะเบียน URI ให้ตรงใน client แล้วใช้ค่าเดิมทั้ง authorize และ token |
| 400 | pkce_mismatch | code_verifier ไม่ตรง SHA-256 ของ code_verifier ไม่เท่ากับ code_challenge ตอน authorize | เก็บ code_verifier ของ request เดิมไว้ในหน่วยความจำแอป (ไม่ใช่ค่าใหม่) |
| 400 | authorization_pending | รอผู้ใช้ยืนยัน (device flow) ผู้ใช้ยังไม่กรอก user_code / ยังไม่กดอนุญาต | ถามซ้ำตาม interval (5 วินาที) — ไม่ใช่ข้อผิดพลาดจริง |
| 400 | slow_down | ถามถี่เกินไป (device flow) poll เร็วกว่า interval | เพิ่ม interval อีก 5 วินาทีทุกครั้งที่ได้รหัสนี้ |
| 400 | expired_token | device_code หมดอายุ เกิน 10 นาทีแล้วผู้ใช้ยังไม่ยืนยัน | ขอ device code ใหม่และแสดง user_code ใหม่บนจอ |
| 400 | refresh_token_reused | refresh token ถูกใช้ซ้ำ refresh token ที่หมุนไปแล้วถูกส่งมาอีก → สงสัยถูกขโมย ระบบเพิกถอนทั้งตระกูล | ให้ผู้ใช้ล็อกอินใหม่ · ตรวจว่าแอปไม่ส่ง refresh พร้อมกันหลายเธรด |
| 403 | consent_required | ต้องขอความยินยอม ผู้ใช้ยังไม่ยินยอมให้แอปนี้ใช้ scope ที่ขอ (PDPA) หรือถอนความยินยอมแล้ว | ส่ง prompt=consent ใน authorize เพื่อแสดงหน้ายินยอม |
| 409 | idempotency_conflict | Idempotency-Key ซ้ำแต่ body ต่าง ใช้ Idempotency-Key เดิมกับคำขอที่เนื้อหาไม่เหมือนเดิมภายใน 24 ชม. | สร้าง UUID ใหม่ทุกคำขอที่ต่างกัน · ใช้ key เดิมเฉพาะตอนส่งซ้ำคำขอเดิม |
| 429 | rate_limited | เรียกเกินโควตา เกินโควตาของ key/IP/บัญชี (ดูหัว RateLimit-*) | รอตาม Retry-After แล้วลองใหม่แบบเว้นระยะเพิ่มขึ้น + jitter |
| 503 | service_unavailable | ปิดปรับปรุงชั่วคราว ระบบอยู่ระหว่างบำรุงรักษาหรือรับโหลดเกิน | ลองใหม่ตาม Retry-After · ตรวจหน้า status.kunjae.example |
ไม่พบรหัสที่ค้นหา
Rate limit — โควตาการเรียก
| ขอบเขต | โควตา | Burst | หมายเหตุ |
|---|---|---|---|
| POST /oauth/token ต่อ client | 600 ครั้ง/นาที | 100 | client_credentials ควรแคช token จนใกล้หมด |
| POST /oauth/token ต่อ refresh family | 6 ครั้ง/นาที | 2 | กันแอปวน refresh |
| GET /oauth/authorize ต่อ IP | 60 ครั้ง/นาที | 20 | |
| POST /oauth/introspect ต่อ resource server | 1,200 ครั้ง/นาที | 200 | |
| device flow poll | ทุก 5 วินาที | — | ถี่กว่า = slow_down |
| /v1/clients (management) | 120 ครั้ง/นาที | 20 |
RateLimit-Limitโควตาของช่วงเวลาRateLimit-Remainingครั้งที่เหลือRateLimit-Resetวินาทีจนโควตาเริ่มใหม่- เกินโควตา → 429 พร้อม
Retry-After· แนะนำลองใหม่แบบเว้นระยะเพิ่มขึ้น + สุ่มเล็กน้อย (jitter)
HTTP/1.1 429 Too Many Requests
RateLimit-Limit: 100
RateLimit-Remaining: 0
RateLimit-Reset: 23
Retry-After: 23
{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา ลองใหม่ใน 23 วินาที",
"request_id": "req_2Kd9QwZ1"
}
}เวอร์ชันและ Changelog
เลือกเวอร์ชันด้วยหัว Kunjae-Version (ไม่ส่ง = เวอร์ชันที่ผูกกับ API key) · การเปลี่ยนที่ไม่ทำให้โค้ดเดิมพัง (เพิ่มฟิลด์/endpoint) ออกในเวอร์ชันเดิมได้ · การเปลี่ยนที่ทำให้พังออกเป็นเวอร์ชันใหม่เสมอ และแจ้งล่วงหน้าอย่างน้อย 6 เดือนก่อนปิดเวอร์ชันเก่า
| เวอร์ชัน | สถานะ | รองรับถึง |
|---|---|---|
2026-08-01 ล่าสุด | ปัจจุบัน | — |
2025-11-15 | ยังรองรับ | 30 ก.ย. 2570 |
2024-06-01 | เลิกใช้แล้ว | 31 ธ.ค. 2569 |
- เพิ่ม
2026-08-01GET /oauth/logout (RP-initiated logout) + post_logout_redirect_uris
- เปลี่ยน
2026-08-01access_token typ เป็น at+jwt (RFC 9068) — ไลบรารีที่ตรวจ typ=JWT ต้องอัปเดต
- เพิ่ม
2026-08-01introspection ตอบ session_status ตรวจการออกจากระบบได้ทันที
- ความปลอดภัย
2025-11-15บังคับ PKCE S256 กับ public client ทุกตัว (ปฏิเสธ plain)
- แก้ไข
2025-11-15refresh ส่งซ้ำภายใน 10 วินาที (เครือข่ายหลุด) ไม่ถือเป็นการใช้ซ้ำอีกต่อไป
- เพิ่ม
2025-11-15Device flow (RFC 8628) สำหรับจอทีวีโรงภาพยนตร์
- เพิ่ม
2025-11-15consent แยกนิติบุคคล + GET/DELETE /v1/users/{user_id}/consents
- เลิกใช้
2025-11-15Implicit flow (response_type=token) — ปิดพร้อมเวอร์ชัน 2024-06-01 วันที่ 31 ธ.ค. 2569
- ความปลอดภัย
2024-06-01refresh token rotation + ตรวจจับใช้ซ้ำเป็นค่าเริ่มต้นทุกแอป
- นำออก
2024-06-01Resource Owner Password grant (grant_type=password) — ใช้ /v1/auth/login สำหรับแอปของเครือแทน
เครื่องมือ: ตัวสร้าง PKCE + URL authorize
สุ่ม code_verifier → คำนวณ code_challenge (SHA-256 → base64url) ด้วย Web Crypto จริง → ประกอบ URL authorize ของแอปที่เลือก พร้อมตรวจ verifier ที่พิมพ์เอง · ทำงานในเบราว์เซอร์ทั้งหมด ไม่ส่งข้อมูลออก — ใช้ทำความเข้าใจ spec (ไม่ใช่ปุ่มเรียก API จริง)
URL authorize ที่ประกอบแล้ว (base ตาม Sandbox/Production ที่แถบบน)
คำขอถัดไปหลังได้ code — POST /oauth/token