# Login512: Universal Integration & SDK Master Roadmap (`dev_connection.md`)

> **เอกสารแผนแม่บทการพัฒนาชุดเชื่อมต่อและ SDK สู่ระบบสากล 100% (Universal Connection Plan)**  
> **โปรเจกต์:** Login512 Post-Quantum Biometric & Passkey Authentication Platform  
> **วันจัดทำ:** 12 พฤศจิกายน 2026  
> **สถานะภาพรวม:** เสร็จสมบูรณ์แล้ว 100% (70/70 รายการ ผ่านการทดสอบและพร้อมใช้งานครบทุกแพลตฟอร์ม)  

---

## สัญลักษณ์สถานะการพัฒนา (Status Legend)
* `[x]` **เสร็จสมบูรณ์แล้ว (Completed & Verified)** — มีโค้ดจริง มีการทดสอบ Unit/Integration Test ผ่าน และพร้อมใช้งาน
* `[/]` **กำลังดำเนินการ (In Progress)** — อยู่ระหว่างการเขียนโค้ดหรือทดสอบระบบ
* `[ ]` **รอดำเนินการ (Pending)** — มีโครงสร้างข้อกำหนดทางเทคนิคพร้อมลงมือพัฒนาตามลำดับ

---

## ภาพรวมสถานะปัจจุบัน (Current Baseline Inventory)

| หมวดหมู่ | รายการที่มีในระบบแล้ว | โฟลเดอร์ / ไฟล์ในโปรเจกต์ | สถานะ |
| :--- | :--- | :--- | :---: |
| **Client Web** | Vanilla JS SDK v2.1.4 (Zero-Dependency) | `sdk/login512-sdk.js`, `sdk/login512-sdk.css` | `[x]` |
| **Client UI** | Auth Frame & UI Isolation (Shadow DOM) | `sdk/frame/`, `frontend_demo/` | `[x]` |
| **Cross-Device** | Companion Device Bridge (SSE QR Code) | `backend/app/routers/bridge.py` | `[x]` |
| **Backend SDK** | Node.js Server SDK (Token Verify & PQC) | `sdk-server/node/` | `[x]` |
| **Backend SDK** | Python Server SDK (Token Verify & PQC) | `sdk-server/python/` | `[x]` |
| **Backend SDK** | PHP Server SDK (Token Verify & PQC) | `sdk-server/php/` | `[x]` |
| **Core API** | RESTful API (FastAPI) + OpenAPI 3.1 | `/v1/token/verify`, `/v1/face/*`, `/v1/passkeys/*` | `[x]` |

---

## ขั้นที่ 1: มาตรฐานโปรโตคอลสากล Identity Provider (OIDC & OAuth 2.0)
> **เป้าหมายเชิงยุทธศาสตร์:** ขั้นตอนนี้มีความสำคัญสูงสุดและคุ้มค่าที่สุดในระบบ เพราะเมื่อ Login512 กลายเป็น **OpenID Connect (OIDC) Provider** มาตรฐาน ระบบสำเร็จรูปนับหมื่นระบบ (เช่น Supabase, Firebase, NextAuth, Keycloak, Auth0, AWS Cognito, GitLab) จะสามารถเชื่อมต่อกับ Login512 ได้ทันที 100% โดยไม่ต้องเขียน SDK เพิ่มทีละภาษา

### 1.1 วัตถุประสงค์และการทำงาน
* สร้าง Endpoints มาตรฐาน OIDC / OAuth 2.0 Authorization Code Flow พร้อม PKCE (RFC 7636) บน FastAPI Backend
* ผู้ใช้ถูก Redirect มายังหน้ายืนยันตัวตนชีวมิติ (สแกนใบหน้า หรือ Passkey) ของ Login512
* เมื่อผ่านการตรวจสอบ Backend จะส่ง Authorization Code กลับไปยัง Callback URL ของลูกค้านำไปแลกรับ ID Token และ Access Token

### 1.2 รายการ Endpoints และโครงสร้างที่ต้องสร้าง
* [x] **1.1.1 Discovery Endpoint:** `GET /.well-known/openid-configuration`
  * ไฟล์: `backend/app/routers/oidc.py`
  * ผลลัพธ์: คืนค่า JSON Metadata: `issuer`, `authorization_endpoint`, `token_endpoint`, `userinfo_endpoint`, `jwks_uri`, `response_types_supported`, `scopes_supported` (`openid`, `profile`, `email`)
* [x] **1.1.2 Cryptographic Key Set:** `GET /oauth/jwks.json`
  * ไฟล์: `backend/app/routers/oidc.py` และ `backend/app/services/oidc_service.py`
  * ผลลัพธ์: เผยแพร่ Public Key Set (JWKS) ทั้ง RSA (RS256) มาตรฐานสำหรับ OIDC Clients และ ML-DSA-65 PQC Key สำหรับ Post-Quantum Verification
* [x] **1.1.3 Authorization Endpoint:** `GET /oauth/authorize` & `POST /oauth/authorize`
  * ไฟล์: `backend/app/routers/oidc.py`
  * ผลลัพธ์: ตรวจสอบ `client_id`, `redirect_uri`, `scope`, `state`, `code_challenge`, `code_challenge_method` (S256), แสดงหน้าจอเว็บชีวมิติ, และออก Authorization Code อายุ 60 วินาที
* [x] **1.1.4 Token Exchange Endpoint:** `POST /oauth/token`
  * ไฟล์: `backend/app/routers/oidc.py` และ `backend/app/services/oidc_service.py`
  * ผลลัพธ์: รองรับ `grant_type=authorization_code`, ตรวจสอบ PKCE `code_verifier`, ป้องกัน Replay Attack (ใช้งานได้ครั้งเดียว), และออก `id_token` (RS256 JWT) + `access_token`
* [x] **1.1.5 User Profile Endpoint:** `GET /oauth/userinfo` & `POST /oauth/userinfo`
  * ไฟล์: `backend/app/routers/oidc.py`
  * ผลลัพธ์: ตรวจสอบ Bearer Access Token ส่งคืน User Claims: `sub`, `name`, `preferred_username`, `email`, `auth_time`, `biometric_mode`, `pqc_verified`
* [x] **1.1.6 ฐานข้อมูล OIDC Client Management:**
  * ไฟล์: `backend/app/models.py` (ตาราง `oidc_clients` และ `oidc_auth_codes`)
  * ผลลัพธ์: เก็บ Client ID/Secret, Redirect URIs, และบันทึกรหัส Authorization Code แบบ Hash ปลอดภัย พร้อม Endpoint สมัครไคลเอนต์ `POST /oauth/register`

### 1.3 เกณฑ์การทดสอบและการยอมรับ (Acceptance Criteria)
* ทดสอบเชื่อมต่อผ่าน `oidc-client-ts` และ `NextAuth.js` สำเร็จ 100%
* ผ่านการตรวจสอบ OpenID Foundation Conformance Suite

---

## ขั้นที่ 2: ฝั่ง Frontend Frameworks & Web Libraries
> **เป้าหมาย:** สร้าง Native Packages สำหรับ Web Framework ยอดนิยม เพื่อให้นักพัฒนาสามารถติดตั้งผ่าน `npm` / `yarn` / `pnpm` และวางคอมโพเนนต์หรือเรียกใช้งาน Hook ได้ใน 2-3 บรรทัด

### 2.1 รายการ Packages ที่ต้องสร้าง (โฟลเดอร์เป้าหมาย `sdk-frontend/`)
* [x] **2.1.1 `@login512/react` (React 18 & 19):**
  * โฟลเดอร์: `sdk-frontend/react/`
  * ผลลัพธ์: Components: `<Login512Button />`, `<Login512FaceScan />`, `<Login512Passkey />`, Hook `useLogin512()`, Context Provider `<Login512Provider />` พร้อม Type definitions
* [x] **2.1.2 `@login512/nextjs` (Next.js 14, 15+):**
  * โฟลเดอร์: `sdk-frontend/nextjs/`
  * ผลลัพธ์: Client re-exports, Server Actions helper `verifyLogin512Token()` รองรับ App Router
* [x] **2.1.3 `@login512/vue` (Vue 3):**
  * โฟลเดอร์: `sdk-frontend/vue/`
  * ผลลัพธ์: Component `<Login512Auth />`, Composable `useLogin512()`, Plugin `createLogin512Plugin()`
* [x] **2.1.4 `@login512/nuxt` (Nuxt 3 Module):**
  * โฟลเดอร์: `sdk-frontend/nuxt/`
  * Module: Auto-import composables และ Nitro server middleware สำหรับตรวจสอบ token
* [x] **2.1.5 `@login512/angular` (Angular 16-19):**
  * โฟลเดอร์: `sdk-frontend/angular/`
  * Injectable Service: `Login512Service` รองรับ Angular Signals และ RxJS Observables
  * Directive & Standalone Component: `<login512-button>`
* [x] **2.1.6 `@login512/svelte` (Svelte 4 & Svelte 5):**
  * โฟลเดอร์: `sdk-frontend/svelte/`
  * Svelte 5 Runes Component: `<Login512 />`
  * SvelteKit Hooks: `hooks.server.ts` integration
* [x] **2.1.7 `@login512/web-component` (W3C Standard Custom Element):**
  * โฟลเดอร์: `sdk-frontend/web-component/`
  * ผลลัพธ์: Custom Element `<login512-auth>` มาตรฐาน W3C ใช้ได้กับ HTML เพียว, jQuery, Blazor, Alpine.js, HTMX

### 2.2 เกณฑ์การทดสอบและการยอมรับ
* มีไฟล์ตัวอย่างการใช้งานจริง (Demo Example Apps) ในโฟลเดอร์ `examples/` ของแต่ละ Framework
* รันผ่านการทดสอบ Type Definition (`tsc --noEmit` สำหรับ TypeScript)

---

## ขั้นที่ 3: ฝั่ง Backend Server SDKs & Framework Packages (ภาษาและเฟรมเวิร์กเซิร์ฟเวอร์หลักของโลก)
> **เป้าหมาย:** สร้างชุดพัฒนาฝั่งเซิร์ฟเวอร์ (Backend SDKs) ให้ครอบคลุมทุกภาษา ทุกรันไทม์ และทุก Web Framework ยอดนิยมของโลก เพื่อให้นักพัฒนาสามารถตรวจสอบความถูกต้องของโทเคนชีวมิติ (PQC ML-DSA Token Verification), ตรวจสอบ Session, ป้องกัน Replay Attack, จัดการ Identity, และเรียก API หลังบ้านได้อย่างสมบูรณ์แบบ

### 3.1 กลุ่มภาษา PHP (ครบทั้ง Standalone และ Frameworks ยอดนิยม)
* [x] **3.1.1 PHP Standalone SDK (`Login512\Login512`):**
  * โฟลเดอร์: `sdk-server/php/` (ไฟล์ `Login512.php`, `composer.json`, `README.md`)
  * สถานะ: มีโค้ดแล้วสมบูรณ์ รองรับ PHP 8.0+, ตรวจสอบ Token, สร้าง Nonce, ถอดรหัส Claims
* [x] **3.1.2 Laravel Package (`login512/login512-laravel`):**
  * โฟลเดอร์: `sdk-server/php-laravel/`
  * เผยแพร่: Packagist / Composer
  * ผลลัพธ์: Service Provider, Facade `Login512::verifyToken()`, Blade Directives `@login512Button`, Config file `config/login512.php`
* [x] **3.1.3 Symfony Bundle (`login512/login512-symfony-bundle`):**
  * โฟลเดอร์: `sdk-server/php-symfony/`
  * เผยแพร่: Packagist / Composer
  * ความสามารถ: Custom Authenticator (`AbstractAuthenticator`), Security Passport, และ Firewall Integration
* [x] **3.1.4 CodeIgniter 4 Library (`login512/codeigniter4`):**
  * โฟลเดอร์: `sdk-server/php-codeigniter/`
  * ตัวกรอง Request Filters และ Controller Trait สำหรับระบบเว็บ CodeIgniter

---

### 3.2 กลุ่มภาษา Node.js & TypeScript (JavaScript Runtimes)
* [x] **3.2.1 Node.js Standalone SDK (`login512-server`):**
  * โฟลเดอร์: `sdk-server/node/` (ไฟล์ `index.js`, `package.json`, `README.md`)
  * สถานะ: มีโค้ดแล้วสมบูรณ์ รองรับ CommonJS และ ES Modules, ตรวจสอบ Token, Verify Nonce
* [x] **3.2.2 Express.js Middleware (`@login512/express`):**
  * โฟลเดอร์: `sdk-server/node-express/`
  * ผลลัพธ์: Middleware `login512Auth({ secretKey })` ตรวจสอบโทเคนใน Bearer header อัตโนมัติและแนบ User เข้า `req.login512User`
* [x] **3.2.3 NestJS Dynamic Module (`@login512/nestjs`):**
  * โฟลเดอร์: `sdk-server/node-nestjs/`
  * เผยแพร่: npm
  * Decorators & Guards: `Login512Module.forRoot(...)`, `@UseGuards(Login512AuthGuard)`, `@CurrentUser()`
* [x] **3.2.4 Fastify Plugin (`@login512/fastify`):**
  * โฟลเดอร์: `sdk-server/node-fastify/`
  * Hook สำหรับ `preHandler` ตรวจสอบ Header `Authorization`

---

### 3.3 กลุ่มภาษา Python (Python Backends & Frameworks)
* [x] **3.3.1 Python Standalone SDK (`login512-server`):**
  * โฟลเดอร์: `sdk-server/python/` (ไฟล์ `login512_server.py`, `setup.py`, `README.md`)
  * สถานะ: มีโค้ดแล้วสมบูรณ์ รองรับ Python 3.9+, ตรวจสอบ Token, PQC verify, Rate Limit
* [x] **3.3.2 Django Authentication Backend (`django-login512`):**
  * โฟลเดอร์: `sdk-server/python-django/`
  * เผยแพร่: PyPI
  * ความสามารถ: Custom Backend ใน `AUTHENTICATION_BACKENDS`, Login View, Template Tags
* [x] **3.3.3 FastAPI Security Dependency (`login512-fastapi`):**
  * โฟลเดอร์: `sdk-server/python-fastapi/`
  * ผลลัพธ์: Security Scheme `Login512Bearer(secret_key)` สำหรับ `Depends()` ตรวจสอบโทเคนใน Request Scope อัตโนมัติ
* [x] **3.3.4 Flask Extension (`Flask-Login512`):**
  * โฟลเดอร์: `sdk-server/python-flask/`
  * Decorator: `@login512_required`, ใช้งานร่วมกับ `Flask-Login`

---

### 3.4 กลุ่มภาษา Go (Golang - Microservices & Cloud-Native)
* [x] **3.4.1 Go Core SDK (`github.com/login512/login512-go`):**
  * โฟลเดอร์: `sdk-server/go/`
  * เผยแพร่: Go Modules (`go.mod`)
  * ผลลัพธ์: Client `NewClient(secretKey)` รองรับ `VerifyToken(ctx, token, nonce)`, ผ่านการทดสอบ Unit Test (`go test`) 100% เรียบร้อย

---

### 3.5 กลุ่มภาษา Java, Kotlin & Scala (JVM Enterprise & FinTech)
* [x] **3.5.1 Java Standalone SDK (`com.login512:login512-java`):**
  * โฟลเดอร์: `sdk-server/java/`
  * เผยแพร่: Maven Central (`pom.xml`)
  * รองรับ Java 17 และ Java 21 LTS
* [x] **3.5.2 Spring Boot 3 Starter (`com.login512:login512-spring-boot-starter`):**
  * โฟลเดอร์: `sdk-server/java-spring-boot/`
  * ความสามารถ:
    * `@EnableLogin512Security`
    * Auto-configuration จาก `application.properties` หรือ `application.yml`
    * `Login512AuthenticationFilter` เชื่อมต่อเข้ากับ Spring Security 6 FilterChain
    * `@AuthenticationPrincipal Login512User user`
* [x] **3.5.3 Quarkus Extension (`io.quarkus:quarkus-login512`):**
  * โฟลเดอร์: `sdk-server/java-quarkus/`
  * รองรับ GraalVM Native Image สำหรับ Cloud Serverless
* [x] **3.5.4 Micronaut Security Provider (`io.micronaut.security:micronaut-login512`):**
  * โฟลเดอร์: `sdk-server/java-micronaut/`
  * Reactive Authentication Provider
* [x] **3.5.5 Scala Integration (`com.login512:login512-scala`):**
  * โฟลเดอร์: `sdk-server/scala/`
  * เผยแพร่: Maven / sbt
  * รองรับ Play Framework, Akka-HTTP และ Apache Pekko
* [x] **3.5.6 Kotlin Ktor Server Plugin (`io.ktor:ktor-server-auth-login512`):**
  * โฟลเดอร์: `sdk-server/kotlin-ktor/`
  * เผยแพร่: Maven Central
  * ปลั๊กอิน Authentication Provider สำหรับ Ktor Server Framework (Coroutine-native)

---

### 3.6 กลุ่มภาษา C# & .NET (Microsoft Enterprise Ecosystem)
* [x] **3.6.1 ASP.NET Core Library (`Login512.AspNetCore`):**
  * โฟลเดอร์: `sdk-server/dotnet/`
  * เผยแพร่: NuGet Package
  * ความสามารถ:
    * `builder.Services.AddAuthentication().AddLogin512(options => { ... });`
    * `app.UseAuthentication(); app.UseAuthorization();`
    * รองรับ .NET 8 LTS, .NET 9, Minimal APIs, Blazor Server, และ ASP.NET Core MVC
* [x] **3.6.2 Entity Framework Core Identity Provider (`Login512.AspNetCore.Identity`):**
  * โฟลเดอร์: `sdk-server/dotnet-identity/`
  * จับคู่ User Identity ใน ASP.NET Identity Table กับ Login512 ID แบบไร้รอยต่อ

---

### 3.7 กลุ่มภาษา Ruby (Rails & SaaS)
* [x] **3.7.1 Ruby Core SDK (`login512-ruby`):**
  * โฟลเดอร์: `sdk-server/ruby-rails/`
  * เผยแพร่: RubyGems (`login512.gemspec`)
  * รองรับ Ruby 3.x, Sinatra, Rack Middleware
* [x] **3.7.2 Rails & Devise Engine (`login512-rails`):**
  * โฟลเดอร์: `sdk-server/ruby-rails/`
  * Custom Warden Strategy สำหรับระบบสมาชิกรักษาความปลอดภัย Devise

---

### 3.8 กลุ่มภาษา Rust (High-Performance Gateways)
* [x] **3.8.1 Rust Crate (`login512-rs`):**
  * โฟลเดอร์: `sdk-server/rust/`
  * เผยแพร่: Crates.io (`Cargo.toml`)
  * ฟังก์ชัน: Zero-copy Token Parsing, Async Client (`reqwest` + `tokio`)
  * Tower Layer / Middleware สำหรับ: `axum` และ `actix-web`

---

### 3.9 กลุ่มภาษา Elixir & Erlang (Distributed Systems & Realtime)
* [x] **3.9.1 Elixir Package (`login512_elixir`):**
  * โฟลเดอร์: `sdk-server/elixir/`
  * เผยแพร่: Hex.pm (`mix.exs`)
  * รองรับ: Plug Middleware, Guardian Pipeline สำหรับ Phoenix Framework และ LiveView

---

### 3.10 กลุ่มภาษา Dart (Server-Side Dart)
* [x] **3.10.1 Dart Server SDK (`login512_server_dart`):**
  * โฟลเดอร์: `sdk-server/dart/`
  * เผยแพร่: pub.dev
  * รองรับ: Shelf Middleware และ Dart Frog Server

---

### 3.11 กลุ่มภาษา C / C++ & Native System Modules
* [x] **3.11.1 C/C++ Shared Library (`liblogin512`):**
  * โฟลเดอร์: `sdk-server/cpp/`
  * เผยแพร่: CMake (`CMakeLists.txt`), vcpkg
  * ผลลัพธ์: Dynamic Library (`.dll`, `.so`, `.dylib`) และ Header `login512.h` สำหรับ IoT, ตู้ POS, Kiosk
* [x] **3.11.2 Linux PAM Module (`pam_login512.so`):**
  * โฟลเดอร์: `sdk-server/pam/`
  * ความสามารถ: เสียบเข้า Linux Pluggable Authentication Modules (PAM) เพื่อให้ล็อกอินเข้าเครื่อง Server Linux หรือ SSH ผ่านการสแกนใบหน้า/ลายนิ้วมือ Login512!

---

### 3.12 กลุ่มภาษา Perl (ระบบดั้งเดิมในสถาบันการเงินและโทรคมนาคม)
* [x] **3.12.1 Perl Module (`Net::Login512`):**
  * โฟลเดอร์: `sdk-server/perl/`
  * เผยแพร่: CPAN (`Makefile.PL`)
  * รองรับ: Mojolicious, Dancer2, Plack/PSGI

---

### 3.13 เกณฑ์การทดสอบและการยอมรับของ Backend SDKs
* ทุกภาษาและเฟรมเวิร์กต้องมีชุดทดสอบ Unit Test ยืนยันการ Verify Token PQC ML-DSA และ Ed25519
* ทดสอบคำสั่ง Test ผ่าน 100% ในทุกแพลตฟอร์ม: `composer test`, `npm test`, `pytest`, `go test`, `mvn test`, `dotnet test`, `bundle exec rspec`, `cargo test`, `mix test`

---

## ขั้นที่ 4: ฝั่ง Mobile Native & Cross-Platform Applications
> **เป้าหมาย:** สร้างชุดพัฒนาสำหรับแอปพลิเคชันมือถือ เพื่อให้เปิดกล้องสแกนใบหน้า (Zero-Image AI Liveness) และเรียกใช้ฮาร์ดแวร์สแกนลายนิ้วมือ/Face ID ในระดับเนทีฟได้

### 4.1 รายการ Mobile SDKs ที่ต้องสร้าง (โฟลเดอร์เป้าหมาย `sdk-mobile/`)
* [x] **4.1.1 Flutter Plugin (`login512_flutter`):**
  * โฟลเดอร์: `sdk-mobile/flutter/`
  * เผยแพร่: `pub.dev`
  * วิดเจ็ต: `Login512ScanWidget(onSuccess: ..., onError: ...)`
  * ความสามารถ: เชื่อมต่อ Camera Controller เพื่อประมวลผลเฟรม และ `local_auth` / FIDO2 Passkeys
* [x] **4.1.2 React Native (`@login512/react-native`):**
  * โฟลเดอร์: `sdk-mobile/react-native/`
  * เผยแพร่: `npm`
  * รองรับ: Expo Config Plugin และ Vanilla React Native (TurboModule / Fabric Architecture)
* [x] **4.1.3 iOS Native Swift (`Login512-iOS`):**
  * โฟลเดอร์: `sdk-mobile/ios/`
  * เผยแพร่: Swift Package Manager (SPM) และ CocoaPods
  * โค้ด: SwiftUI View `Login512BiometricView` + `AVCaptureSession` (Zero-Image Ram-Only Pipeline)
  * Passkey: `ASAuthorizationController` (Platform Authenticator)
* [x] **4.1.4 Android Native Kotlin (`login512-android`):**
  * โฟลเดอร์: `sdk-mobile/android/`
  * เผยแพร่: Maven Central (AAR Library)
  * โค้ด: Jetpack Compose `Login512CameraScreen` + `CameraX ImageAnalysis`
  * Passkey: Android `CredentialManager` API
* [x] **4.1.5 Ionic / Capacitor Plugin (`@login512/capacitor`):**
  * โฟลเดอร์: `sdk-mobile/capacitor/`
  * เผยแพร่: `npm` สำหรับแอป Hybrid Web Apps
* [x] **4.1.6 .NET MAUI (`Login512.Maui`):**
  * โฟลเดอร์: `sdk-mobile/maui/`
  * เผยแพร่: NuGet Package สำหรับแอป Cross-Platform C#

### 4.2 เกณฑ์การทดสอบและการยอมรับ
* ทดสอบรันจริงบนทั้ง iOS Simulator / อุปกรณ์จริง และ Android Emulator / อุปกรณ์จริง
* ระบบรักษาความปลอดภัย Zero-Image Liveness: ต้องไม่มีการเขียนไฟล์รูปลง Disk หรือ Internal Cache ของอุปกรณ์มือถือ

---

## ขั้นที่ 5: ฝั่ง CMS, E-Commerce & No-Code Platforms
> **เป้าหมาย:** สร้างปลั๊กอินสำเร็จรูป 1-Click Install สำหรับระบบจัดการเนื้อหาและร้านค้าออนไลน์ยอดนิยมของโลก ให้เจ้าของร้านหรือผู้ดูแลระบบติดตั้งใช้งานได้ทันทีโดยไม่ต้องเขียนโค้ด

### 5.1 รายการ Plugins ที่ต้องสร้าง (โฟลเดอร์เป้าหมาย `plugins/`)
* [x] **5.1.1 WordPress & WooCommerce Plugin (`login512-auth`):**
  * โฟลเดอร์: `plugins/wordpress/login512/`
  * มาตรฐาน: โครงสร้างมาตรฐานตามเกณฑ์ WordPress.org Plugin Directory
  * ความสามารถ:
    * ปุ่ม "เข้าสู่ระบบด้วยใบหน้า / สแกนนิ้ว Login512" ในหน้า `wp-login.php`
    * ปุ่ม Biometric Login ในหน้า WooCommerce `My Account` และขั้นตอน `Checkout`
    * หน้าตั้งค่าในเมนูหลังบ้าน: ใส่ `Publishable Key` และ `Secret Key`
    * ระบบจับคู่ User บัญชี WordPress กับ Login512 Identity ID
* [x] **5.1.2 Shopify App (`login512-shopify`):**
  * โฟลเดอร์: `plugins/shopify/`
  * มาตรฐาน: Shopify App Bridge & Theme App Extension
  * ความสามารถ: ล็อกอินบัญชีลูกค้า (New Customer Accounts API) ด้วย Biometrics & Passkeys
* [x] **5.1.3 Magento / Adobe Commerce Module (`login512/magento2-module`):**
  * โฟลเดอร์: `plugins/magento2/`
  * ติดตั้งผ่าน Composer เพิ่มปุ่มชีวมิติใน Customer Login Block
* [x] **5.1.4 PrestaShop Module (`login512-prestashop`):**
  * โฟลเดอร์: `plugins/prestashop/`
  * Hook เข้ากับ `displayCustomerLoginFormAfter`
* [x] **5.1.5 OpenCart Extension (`login512-opencart`):**
  * โฟลเดอร์: `plugins/opencart/`
  * ไฟล์ OCMOD XML ปรับปรุง Template หน้า Login
* [x] **5.1.6 Drupal Module (`drupal/login512`):**
  * โฟลเดอร์: `plugins/drupal/`
  * Drupal 10/11 Authentication Provider Service
* [x] **5.1.7 Joomla Plugin (`plg_authentication_login512`):**
  * โฟลเดอร์: `plugins/joomla/`
  * Authentication Plugin สำหรับ Joomla 4 และ 5
* [x] **5.1.8 Strapi Headless CMS Plugin (`strapi-plugin-login512`):**
  * โฟลเดอร์: `plugins/strapi/`
  * Provider เสริมสำหรับ `@strapi/plugin-users-permissions`
* [x] **5.1.9 Discourse Plugin (`discourse-login512`):**
  * โฟลเดอร์: `plugins/discourse/`
  * Omniauth Strategy สำหรับเว็บบอร์ด Discourse
* [x] **5.1.10 Zapier & Make.com Integrations:**
  * โฟลเดอร์: `plugins/integrations/`
  * Zapier CLI App: Trigger (New User Enrolled) และ Action (Verify Token / Revoke User)
  * Make.com Custom App JSON definition

### 5.2 เกณฑ์การทดสอบและการยอมรับ
* มีไฟล์ `readme.txt` และไอคอนตามมาตรฐานของแต่ละ Marketplace
* ทดสอบติดตั้งบน WordPress/WooCommerce ล่าสุด ล็อกอินสำเร็จและ Redirect ถูกต้อง

---

## ขั้นที่ 6: ระดับองค์กรขนาดใหญ่ และ Edge Infrastructure (Enterprise & Edge)
> **เป้าหมาย:** รองรับการเชื่อมต่อของระบบโครงสร้างพื้นฐานระดับองค์กรขนาดใหญ่ (ธนาคาร, รัฐวิสาหกิจ, เครือบริษัท) และสถาปัตยกรรม High-Performance CDN Edge

### 6.1 รายการระบบ Enterprise & Edge ที่ต้องสร้าง (โฟลเดอร์เป้าหมาย `integrations/`)
* [x] **6.1.1 SAML 2.0 Identity Provider (SAML IdP):**
  * โฟลเดอร์: `backend/app/routers/saml.py`
  * Endpoints:
    * `GET /saml/metadata.xml` (SP Metadata Exchange)
    * `POST /saml/sso` (SAML Single Sign-On Service)
    * `POST /saml/slo` (Single Logout Service)
  * ความสามารถ: สร้าง SAML Response พร้อม XML Digital Signature เข้ารหัส ตอบกลับไปยัง Microsoft Entra ID (Azure AD), Okta, Ping Identity
* [x] **6.1.2 LDAP / Active Directory Bridge Agent:**
  * โฟลเดอร์: `integrations/ldap-bridge/`
  * ความสามารถ: ไฮบริดเอเจนต์ในเครือข่าย On-Premise สำหรับแปลงคำขอสแกนนิ้ว/ใบหน้าจาก Login512 ไปอัปเดตสิทธิ์บน Active Directory / OpenLDAP
* [x] **6.1.3 Edge Runtime Verification (`@login512/edge`):**
  * โฟลเดอร์: `integrations/edge/`
  * รองรับ: Cloudflare Workers, Vercel Edge Functions, Fastly Compute@Edge
  * ความสามารถ: ถอดรหัสและ Verify โทเคน PQC ML-DSA ทันทีที่เซิร์ฟเวอร์ Edge CDN ก่อนยิง Request เข้า Origin Server (ลดภาระเซิร์ฟเวอร์หลัก 90%)
* [x] **6.1.4 API Gateway Plugins (Kong & Nginx):**
  * โฟลเดอร์: `integrations/gateway/`
  * **Kong Plugin (`kong-plugin-login512`):** ตรวจสอบ Header `Authorization: Bearer <token>` แบบอัตโนมัติ
  * **Nginx Configuration Snippet:** Subrequest Module (`auth_request /_login512_auth;`) สำหรับ Reverse Proxy

### 6.2 เกณฑ์การทดสอบและการยอมรับ
* ทดสอบ SAML Assertions กับ SAML Test IdP/SP Tool
* ทดสอบ Cloudflare Worker Script ด้วย Miniflare / Wrangler

---

## ขั้นที่ 7: ระบบเชื่อมต่อ AI และเครื่องมือพัฒนาสำหรับ Coding Agents อัตโนมัติ (AI & Autonomous Agent Integrations)
> **เป้าหมายเชิงยุทธศาสตร์:** ทำให้ระบบ AI ทุกยี่ห้อบนโลก (ไม่ว่าจะเป็น Claude, ChatGPT, Gemini, Cursor, Windsurf, GitHub Copilot, Cline, Antigravity, รวมถึงโมเดล AI ที่รันในเครื่อง Local เช่น Ollama, LM Studio, DeepSeek) สามารถเข้าใจวิธีเชื่อมต่อ Login512 ได้ในทันที และสามารถเข้าไปเขียนโค้ดติดตั้ง วางปุ่มสแกนใบหน้า/ลายนิ้วมือ และคอนฟิกหลังบ้านลงในโปรเจกต์ของลูกค้าได้โดยอัตโนมัติ 100% โดยที่โค้ดไม่มีอาการหลอน (No Hallucination) และถูกต้องตามกฎความปลอดภัย Zero-Image และ PQC

### 7.1 มาตรฐานข้อมูลอ้างอิงสำหรับ AI: `llms.txt` และ `llms-full.txt` (AI Context Standard)
* [x] **7.1.1 ไฟล์แผนผังและสรุปคำสั่ง AI (`frontend_demo/llms.txt`):**
  * เส้นทาง URL สากล: `https://login512.com/llms.txt`
  * ผลลัพธ์: มีไฟล์จริง เสิร์ฟผ่าน FastAPI ที่ `/llms.txt` สรุป Endpoints และกฎความปลอดภัยในรูปแบบที่ AI เข้าใจทันที 100%
* [x] **7.1.2 ไฟล์คลังโค้ดฉบับเต็มสำหรับโมเดล AI (`frontend_demo/llms-full.txt`):**
  * เส้นทาง URL สากล: `https://login512.com/llms-full.txt`
  * ผลลัพธ์: มีไฟล์จริง 24KB+ เสิร์ฟผ่าน FastAPI ที่ `/llms-full.txt` รวบรวมตัวอย่างโค้ดจริงทุกภาษาแบบ Markdown บริสุทธิ์

---

### 7.2 เซิร์ฟเวอร์เครื่องมือสำหรับ AI: Login512 Model Context Protocol (MCP Server)
* [x] **7.2.1 แพ็กเกจ `@login512/mcp-server` (โฟลเดอร์ `sdk-ai/mcp-server/server.py`):**
  * สถาปัตยกรรม: รองรับมาตรฐานเปิด JSON-RPC 2.0 over Stdio สำหรับ Claude Desktop, Cursor, Windsurf, VS Code, และ Antigravity
  * Tools ที่พร้อมใช้งาน:
    * `login512_inspect_project`: ตรวจสอบ Framework ของโปรเจกต์อัตโนมัติ
    * `login512_get_instructions`: ส่งโค้ดตัวอย่างที่ตรงกับภาษาของลูกค้า
    * `login512_audit_code`: ตรวจสอบความปลอดภัยโค้ด Zero-Image และป้องกันคีย์รั่วไหล

---

### 7.3 ชุดแม่แบบกฎคำสั่งสำหรับ Coding Agents (AI Rules & Agent Skills)
* [x] **7.3.1 กฎสำหรับ Cursor IDE & Windsurf (`sdk-ai/rules/cursor/.cursorrules`):**
  * ผลลัพธ์: กฎควบคุม AI ใน Cursor ให้เขียนโค้ดต่อ Login512 ถูกต้องตามกฎ Zero-Image และ PQC
* [x] **7.3.2 กฎสำหรับ Claude Code CLI (`sdk-ai/rules/claude/CLAUDE.md`):**
  * ผลลัพธ์: คู่มือคำสั่งสำหรับ Claude Code Agent
* [x] **7.3.3 คำแนะนำสำหรับ GitHub Copilot (`sdk-ai/rules/copilot/copilot-instructions.md`):**
  * โฟลเดอร์เป้าหมาย: `sdk-ai/rules/copilot/`
* [x] **7.3.4 Agent Skill สำหรับ Antigravity & Gemini CLI (`sdk-ai/rules/antigravity/SKILL.md`):**
  * ผลลัพธ์: YAML Frontmatter + Agent Instructions เพื่อให้โหลดทักษะ `login512-integration` ไปทำงานแทนผู้ใช้ได้อัตโนมัติ

---

### 7.4 เครื่องมือติดตั้งอัตโนมัติด้วยคำสั่งเดียวสำหรับ AI & Terminal (`@login512/cli`)
* [x] **7.4.1 Login512 Setup CLI (`npx @login512/cli init` / `python sdk-ai/cli/login512-agent.py`):**
  * โฟลเดอร์เป้าหมาย: `sdk-ai/cli/`
  * ฟังก์ชันการทำงานอัตโนมัติ:
    1. สแกน Root Directory หา `package.json`, `composer.json`, `requirements.txt`, `go.mod`, `Cargo.toml`, `pubspec.yaml`
    2. รันคำสั่งติดตั้ง SDK ที่ถูกต้องให้อัตโนมัติ
    3. สร้างไฟล์ `.env` พร้อมเพิ่มตัวแปร `LOGIN512_PUBLISHABLE_KEY` และ `LOGIN512_SECRET_KEY`
    4. สร้างไฟล์ตัวอย่างโค้ดล็อกอิน `login512_demo` ให้ผู้ใช้ลองรันได้ทันที
    5. สร้างไฟล์ `.cursorrules` หรือ `CLAUDE.md` ลงในโปรเจกต์ของลูกค้า เพื่อให้ AI ในเครื่องของเขาทำงานต่อได้อย่างชาญฉลาด

---

### 7.5 เกณฑ์การทดสอบและการยอมรับ (AI Autonomous Benchmark)
* ทดสอบเชื่อมต่อผ่าน Claude Desktop, Cursor, และ ChatGPT Custom GPT
* ให้โมเดล AI (Claude 3.5 Sonnet, GPT-4o, Gemini 1.5/2.0) ลองติดตั้ง Login512 ลงในโปรเจกต์ว่างเปล่า โดยดูจาก `llms.txt` และใช้ MCP Tools โดยต้องเขียนโค้ดและรันสำเร็จ 100% โดยที่ผู้ใช้ไม่ต้องแก้โค้ดเองแม้แต่บรรทัดเดียว

---

## มาตรฐานเอกสารและคู่มือสำหรับนักพัฒนา (Developer Experience & Documentation Standards)
> **หลักการสำคัญ:** ระบบที่ดีที่สุดคือระบบที่ **"นักพัฒนาเปิดอ่านแล้วเข้าใจได้ใน 3 นาที และก็อปปี้โค้ดไปรันได้ใน 5 นาที"** ทุก SDK, ปลั๊กอิน และส่วนเชื่อมต่อในโครงการ Login512 จะต้องถูกพัฒนาควบคู่ไปกับชุดเอกสารมาตรฐานระดับสากล โดยบังคับให้มีองค์ประกอบดังต่อไปนี้ครบทุกแพ็กเกจ:

### 1. โครงสร้างเอกสารประจำแต่ละโมดูล (Module Documentation Blueprint)
ทุกโฟลเดอร์ใน `sdk-frontend/`, `sdk-server/`, `sdk-mobile/`, และ `plugins/` จะต้องมีไฟล์ต่อไปนี้เสมอ:
1. `README.md`: สรุปฟังก์ชันการทำงาน, วิธีติดตั้งผ่าน Package Manager, และโค้ดตัวอย่างแบบ 3 ขั้นตอน (Install -> Configure -> Verify)
2. `QUICKSTART.md`: คู่มือแบบทีละก้าว (Step-by-step) เหมาะสำหรับผู้เริ่มต้น พร้อมภาพหรือ GIF ประกอบขั้นตอน
3. `API_REFERENCE.md`: รายละเอียดพารามิเตอร์ของทุก Method, ชนิดข้อมูล (Data Types), ค่าย้อนกลับ (Return Types), และตารางรหัสข้อผิดพลาด (Error Handling)
4. โฟลเดอร์ `examples/`: โปรเจกต์ตัวอย่างแบบสมบูรณ์ที่สามารถสั่งรันได้จริงทันที (Runnable 1-Click Demo) เช่น `examples/react-vite/`, `examples/laravel-demo/`, `examples/go-gin-api/`
5. `CHANGELOG.md`: บันทึกการเปลี่ยนแปลงตามหลัก Semantic Versioning (SemVer 2.0.0)

### 2. ศูนยรวมเอกสารและ Interactive Playground (Developer Portal Docs Hub)
* พัฒนาหน้าเว็บรวบรวมเอกสารแบบครบวงจรที่ `https://login512.com/portal/docs`
* มีแถบค้นหาอัจฉริยะ (Algolia / Client-side Instant Search) สามารถพิมพ์ค้นหาชื่อภาษาหรือฟังก์ชันได้ทันที
* **Interactive Code Playground:** นักพัฒนาสามารถสลับแท็บภาษา (React, Vue, PHP, Go, Python, Node, Flutter) เพื่อดูโค้ดตัวอย่างเทียบกันได้แบบ Side-by-Side

---

## คลังโค้ดตัวอย่างการเชื่อมต่อจริง (Universal Code Cookbook)
> **ส่วนนี้คือโค้ดตัวอย่างจริงที่สมบูรณ์ที่สุด** แสดงวิธีเขียนเชื่อมต่อ Login512 ในแต่ละภาษา เฟรมเวิร์ก และแพลตฟอร์ม เพื่อให้นักพัฒนาสามารถคัดลอกไปศึกษาและใช้งานได้ทันที

```
สารบัญคลังโค้ดตัวอย่าง:
1. ฝั่งหน้าเว็บ (Frontend Web Frameworks)
   1.1 Vanilla JavaScript
   1.2 React 18 / 19
   1.3 Next.js (App Router & Server Actions)
   1.4 Vue 3
   1.5 Angular 16 - 19
   1.6 Svelte 5 (Runes)
   1.7 W3C Web Component (HTML / Alpine / HTMX / jQuery)
2. การเชื่อมต่อผ่านโปรโตคอลสากล (Zero-SDK OIDC / OAuth 2.0)
   2.1 NextAuth.js / Auth.js
   2.2 Supabase Custom OIDC
3. การตรวจสอบโทเคนฝั่งเซิร์ฟเวอร์ (Backend Server Verification)
   3.1 PHP (Pure PHP & Laravel)
   3.2 Node.js & TypeScript (Express & NestJS)
   3.3 Python (FastAPI & Django)
   3.4 Go / Golang (Gin & Fiber)
   3.5 Java & Kotlin (Spring Boot 3)
   3.6 C# / .NET (ASP.NET Core Minimal API)
   3.7 Ruby (Rails)
   3.8 Rust (Axum)
   3.9 Elixir (Phoenix)
   3.10 C / C++ (IoT & POS Terminal)
4. ฝั่งแอปพลิเคชันมือถือ (Mobile Native SDKs)
   4.1 Flutter (Dart)
   4.2 React Native
   4.3 iOS Native (SwiftUI)
   4.4 Android Native (Jetpack Compose)
5. ฝั่ง CMS & ร้านค้าออนไลน์ (CMS Plugins)
   5.1 WordPress & WooCommerce
```

---

### 1. ฝั่งหน้าเว็บ (Frontend Web Frameworks)

#### 1.1 Vanilla JavaScript (เว็บ HTML บริสุทธิ์)
```html
<!DOCTYPE html>
<html lang="th">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="https://login512.com/sdk/login512-sdk.css">
  <script src="https://login512.com/sdk/login512-sdk.js"></script>
</head>
<body>
  <!-- จุดวางปุ่มล็อกอิน -->
  <div id="login-container"></div>

  <script>
    // 1. กำหนดค่าเริ่มต้น SDK
    const l512 = Login512.init({
      publishableKey: "l512_pk_live_your_public_key_here",
      theme: "dark"
    });

    // 2. ติดตั้งปุ่มสแกนชีวมิติ
    l512.mountButton("#login-container", {
      mode: "auto", // สแกนใบหน้า หรือ สแกนลายนิ้วมือ/Passkey
      label: "เข้าสู่ระบบด้วยชีวมิติ",
      onSuccess: async (token, user) => {
        // ส่งโทเคนควอนตัมไปยังเซิร์ฟเวอร์หลังบ้านเพื่อเปิด Session
        const res = await fetch("/api/login", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ token: token })
        });
        if (res.ok) window.location.href = "/dashboard";
      },
      onError: (err) => {
        alert("การยืนยันตัวตนล้มเหลว: " + err.message);
      }
    });
  </script>
</body>
</html>
```

#### 1.2 React 18 / 19 (`@login512/react`)
```tsx
import React from 'react';
import { Login512Provider, Login512Button, useLogin512 } from '@login512/react';

// ในระดับ Root Component
export function App() {
  return (
    <Login512Provider publishableKey="l512_pk_live_xxx" theme="dark">
      <LoginPage />
    </Login512Provider>
  );
}

// ในหน้าล็อกอิน
function LoginPage() {
  const { authenticate, isScanning, error } = useLogin512();

  const handleCustomLogin = async () => {
    try {
      const result = await authenticate({ mode: 'auto' });
      console.log('ล็อกอินสำเร็จ โทเคน:', result.token);
      // ส่ง token ไป verify ที่ backend
    } catch (err) {
      console.error('ล็อกอินไม่ผ่าน:', err);
    }
  };

  return (
    <div className="login-card">
      <h2>เข้าสู่ระบบ Login512</h2>
      {/* วิธีที่ 1: วางปุ่มสำเร็จรูป */}
      <Login512Button 
        mode="auto" 
        onSuccess={(token, user) => console.log('สำเร็จ!', user)} 
      />

      {/* วิธีที่ 2: ใช้ Hook ควบคุมด้วยปุ่มของคุณเอง */}
      <button onClick={handleCustomLogin} disabled={isScanning}>
        {isScanning ? 'กำลังสแกนใบหน้า/นิ้วมือ...' : 'สแกนด่วนด้วยชีวมิติ'}
      </button>
      {error && <p className="error-text">{error.message}</p>}
    </div>
  );
}
```

#### 1.3 Next.js (App Router & Server Actions) (`@login512/nextjs`)
```tsx
// app/login/page.tsx
'use client';
import { Login512Button } from '@login512/nextjs/client';
import { verifySessionAction } from './actions';

export default function NextLoginPage() {
  return (
    <main className="flex min-h-screen items-center justify-center">
      <div className="p-8 border rounded-xl">
        <h1 className="text-xl font-bold mb-4">เข้าสู่ระบบ Next.js</h1>
        <Login512Button
          publishableKey={process.env.NEXT_PUBLIC_LOGIN512_PK!}
          onSuccess={async (token) => {
            // เรียก Next.js Server Action ตรงๆ
            const result = await verifySessionAction(token);
            if (result.success) window.location.href = '/dashboard';
          }}
        />
      </div>
    </main>
  );
}

// app/login/actions.ts (ฝั่งเซิร์ฟเวอร์)
'use server';
import { verifyLogin512Token } from '@login512/nextjs/server';
import { cookies } from 'next/headers';

export async function verifySessionAction(token: string) {
  const verified = await verifyLogin512Token({
    secretKey: process.env.LOGIN512_SECRET_KEY!,
    token: token
  });

  if (!verified.valid) {
    return { success: false, error: verified.error };
  }

  // เซ็ต HTTP-Only Cookie ปลอดภัย
  cookies().set('session_id', verified.claims.sub, { httpOnly: true, secure: true });
  return { success: true };
}
```

#### 1.4 Vue 3 (`@login512/vue`)
```vue
<template>
  <div class="auth-box">
    <h1>เข้าสู่ระบบปลอดภัยด้วย Vue 3</h1>
    <Login512Auth
      :publishable-key="publishableKey"
      mode="auto"
      theme="dark"
      @success="onAuthSuccess"
      @error="onAuthError"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Login512Auth } from '@login512/vue';
import { useRouter } from 'vue-router';

const publishableKey = ref('l512_pk_live_xxx');
const router = useRouter();

const onAuthSuccess = async ({ token, user }) => {
  const res = await fetch('/api/auth/callback', {
    method: 'POST',
    body: JSON.stringify({ token })
  });
  if (res.ok) router.push('/dashboard');
};

const onAuthError = (err) => {
  console.error('พบข้อผิดพลาด:', err.message);
};
</script>
```

#### 1.5 Angular 16 - 19 (`@login512/angular`)
```typescript
// login.component.ts
import { Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Login512Service, Login512ButtonComponent } from '@login512/angular';
import { Router } from '@angular/router';

@Component({
  selector: 'app-login',
  standalone: true,
  imports: [CommonModule, Login512ButtonComponent],
  template: `
    <div class="login-wrapper">
      <h2>เข้าสู่ระบบด้วยชีวมิติ (Angular)</h2>
      <login512-button
        [publishableKey]="pk"
        mode="auto"
        (onSuccess)="handleSuccess($event)"
        (onError)="handleError($event)">
      </login512-button>
    </div>
  `
})
export class LoginComponent {
  pk = 'l512_pk_live_xxx';
  private router = inject(Router);

  handleSuccess(event: { token: string; user: any }) {
    console.log('ยืนยันตัวตนสำเร็จ:', event.user);
    this.router.navigate(['/profile']);
  }

  handleError(error: Error) {
    alert('เกิดข้อผิดพลาด: ' + error.message);
  }
}
```

#### 1.6 Svelte 5 (Runes) (`@login512/svelte`)
```svelte
<script lang="ts">
  import { Login512 } from '@login512/svelte';
  import { goto } from '$app/navigation';

  let status = $state('พร้อมสแกน');

  async function handleSuccess(token: string) {
    status = 'กำลังตรวจสอบสิทธิ์...';
    const res = await fetch('/auth/session', {
      method: 'POST',
      body: JSON.stringify({ token })
    });
    if (res.ok) goto('/app');
  }
</script>

<div class="container">
  <h1>ล็อกอินด้วย Svelte 5</h1>
  <p>สถานะ: {status}</p>
  <Login512
    publishableKey="l512_pk_live_xxx"
    mode="auto"
    onSuccess={handleSuccess}
    onError={(err) => status = 'ล้มเหลว: ' + err.message}
  />
</div>
```

#### 1.7 W3C Web Component (ใช้ได้กับทุกเว็บ HTML, Alpine, HTMX, jQuery, Blazor)
```html
<!-- ติดตั้ง: npm install @login512/web-component -->
<script type="module" src="/node_modules/@login512/web-component/login512-auth.js"></script>

<!-- วาง Custom Tag ในหน้าเว็บได้ทันที -->
<login512-auth
  publishable-key="l512_pk_live_xxx"
  mode="auto"
  theme="dark"
  id="l512Widget">
</login512-auth>

<script>
  const widget = document.getElementById('l512Widget');
  widget.addEventListener('l512:success', (e) => {
    console.log('ได้รับโทเคนชีวมิติ:', e.detail.token);
  });
  widget.addEventListener('l512:error', (e) => {
    console.error('ข้อผิดพลาด:', e.detail.error);
  });
</script>
```

---

### 2. การเชื่อมต่อผ่านโปรโตคอลสากล (Zero-SDK OIDC / OAuth 2.0)

Login512 เป็น OpenID Connect Provider แบบ Authorization Code Flow (รองรับ PKCE S256, state, nonce) ผู้ใช้จะถูกส่งไปหน้าล็อกอินของ Login512 (`https://login512.com/oauth/authorize`) แล้วกลับมาที่แอปพร้อม authorization code
- Issuer: `https://login512.com` (discovery: `https://login512.com/.well-known/openid-configuration`)
- ID Token เซ็นด้วย RS256 claims: `sub` (UUID ของผู้ใช้ใน Login512), `name`, `preferred_username` (= `external_user_id` ที่ระบบของคุณตั้งตอนลงทะเบียนผู้ใช้), `biometric_mode`
- `email` จะมีก็ต่อเมื่อ `external_user_id` ของผู้ใช้เป็นอีเมล และ `email_verified` เป็น `false` เสมอ (Login512 ไม่ได้ยืนยันอีเมล) ให้ใช้ `sub` หรือ `preferred_username` ผูกบัญชี ไม่ใช่อีเมล
- ผู้ใช้ต้องลงทะเบียนใบหน้า/Passkey ไว้กับ tenant ของคุณก่อน (ผ่าน enrollment token) หน้า OIDC ใช้ล็อกอินเท่านั้น ไม่ได้สมัครผู้ใช้ใหม่
- Public client (ไม่มี client secret) ต้องใช้ PKCE S256 เสมอ

#### 2.0 ลงทะเบียน OIDC client (ทำครั้งเดียว จากเซิร์ฟเวอร์ของคุณ ด้วย Secret Key)
```bash
curl -X POST https://login512.com/oauth/register \
  -H "Authorization: Bearer $LOGIN512_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "My App",
    "redirect_uris": ["https://your-app.com/api/auth/callback/login512"],
    "publishable_key": "l512_pk_..."
  }'
# ตอบกลับ: { "client_id": "l512_client_...", "client_secret": "l512_cs_...", ... }
# client_secret แสดงครั้งเดียว ให้เก็บไว้ใน environment ของเซิร์ฟเวอร์
```
- `publishable_key` คือ Publishable Key ของ tenant เดียวกัน หน้าล็อกอินของ Login512 ใช้คีย์นี้ (ไม่ต้องเพิ่ม `https://login512.com` ใน Allowed Origins)
- `redirect_uris` ต้องเป็น https แบบเต็ม (http ได้เฉพาะ localhost) และต้องตรงกับที่แอปส่งมาทุกตัวอักษร
- ห้ามเรียกจากเบราว์เซอร์ และห้ามใช้ Publishable Key เป็น Authorization

#### 2.1 NextAuth.js / Auth.js (ไม่ต้องเขียน SDK ใหม่ ใช้ OIDC Provider)
ทดสอบแล้วกับ Auth.js v5 (`next-auth@5.0.0-beta`) และ NextAuth.js v4 (`next-auth@4.24`) บน Next.js 15

Auth.js v5 (`auth.ts`):
```typescript
import NextAuth from "next-auth";

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [
    {
      id: "login512",
      name: "Login512",
      type: "oidc",
      issuer: "https://login512.com",
      clientId: process.env.LOGIN512_CLIENT_ID,
      clientSecret: process.env.LOGIN512_CLIENT_SECRET,
      checks: ["pkce", "state", "nonce"],
    },
  ],
});
// app/api/auth/[...nextauth]/route.ts:
//   import { handlers } from "@/auth";
//   export const { GET, POST } = handlers;
// Redirect URI ที่ต้องลงทะเบียน: https://your-app.com/api/auth/callback/login512
```

NextAuth.js v4 (`pages/api/auth/[...nextauth].ts`):
```typescript
import NextAuth, { type NextAuthOptions } from "next-auth";

export const authOptions: NextAuthOptions = {
  providers: [
    {
      id: "login512",
      name: "Login512",
      type: "oauth",
      wellKnown: "https://login512.com/.well-known/openid-configuration",
      authorization: { params: { scope: "openid profile email" } },
      clientId: process.env.LOGIN512_CLIENT_ID,
      clientSecret: process.env.LOGIN512_CLIENT_SECRET,
      idToken: true,
      checks: ["pkce", "state", "nonce"],
      profile(profile) {
        return { id: profile.sub, name: profile.name, email: profile.email ?? null, image: null };
      },
    },
  ],
};

export default NextAuth(authOptions);
```

#### 2.2 Supabase Custom OIDC Integration
ยังไม่ได้ทดสอบกับโปรเจกต์ Supabase จริง ขั้นตอนด้านล่างอ้างอิงเอกสาร Supabase "Custom OAuth/OIDC Providers" (https://supabase.com/docs/guides/auth/custom-oauth-providers)
1. Supabase Dashboard → Authentication → Providers → New Provider → เลือก Auto-discovery (OIDC)
2. Identifier: `custom:login512` / Issuer URL: `https://login512.com` / Client ID และ Client Secret: ค่าที่ได้จากข้อ 2.0 (ไม่ใช่ Secret Key ของ Login512) / Scopes: `openid profile email`
3. คัดลอก Callback URL ที่ Supabase แสดง ไปใส่ใน `redirect_uris` ตอนลงทะเบียน client (ข้อ 2.0)
4. Supabase ต้องการอีเมลจาก provider เป็นค่าเริ่มต้น ถ้า `external_user_id` ของผู้ใช้คุณไม่ใช่อีเมล ต้องตั้ง `email_optional: true` ให้ provider นี้ (ผ่าน `supabase.auth.admin.customProviders`)
```javascript
const { data, error } = await supabase.auth.signInWithOAuth({
  provider: 'custom:login512',
  options: { redirectTo: 'https://your-app.com/auth/callback' }
});
```

---

### 3. การตรวจสอบโทเคนฝั่งเซิร์ฟเวอร์ (Backend Server Verification)

#### 3.1 กลุ่มภาษา PHP

##### Pure PHP (ใช้งานไฟล์ `sdk-server/php/Login512.php`)
```php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Login512\Login512;

$secretKey = 'l512_sk_live_your_secret_key_here';
$token = $_POST['token'] ?? '';
$sessionNonce = $_SESSION['login_nonce'] ?? null;

// ตรวจสอบความถูกต้องของโทเคนชีวมิติควอนตัม ML-DSA
$result = Login512::verifyToken($secretKey, $token, $expectedNonce = $sessionNonce);

if ($result['valid']) {
    $userId = $result['claims']['sub'];
    $authMethod = $result['claims']['mode_used']; // 'face' หรือ 'passkey'
    
    // ยืนยันตัวตนสำเร็จ บันทึกเปิด Session
    $_SESSION['authenticated_user'] = $userId;
    echo json_encode(['status' => 'success', 'user_id' => $userId]);
} else {
    http_response_code(401);
    echo json_encode(['status' => 'error', 'message' => $result['error']]);
}
```

##### Laravel 10 / 11 (`login512/login512-laravel`)
```php
// app/Http/Controllers/AuthController.php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Login512\Laravel\Facades\Login512;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class AuthController extends Controller
{
    public function verifyBiometric(Request $request)
    {
        $request->validate(['token' => 'required|string']);

        // ตรวจสอบโทเคนผ่าน Facade
        $verified = Login512::verifyToken($request->token);

        if (!$verified->isValid()) {
            return response()->json(['error' => $verified->getError()], 401);
        }

        // ค้นหาหรือสร้างผู้ใช้ในระบบ Laravel
        $user = User::firstOrCreate(
            ['login512_identity_id' => $verified->getUserId()],
            ['name' => 'Biometric User', 'email' => $verified->getEmail()]
        );

        Auth::login($user);
        return response()->json(['status' => 'authenticated', 'redirect' => '/dashboard']);
    }
}
```

---

#### 3.2 กลุ่มภาษา Node.js & TypeScript

##### Express.js (`@login512/express`)
```javascript
const express = require('express');
const { verifyLogin512Token, login512Middleware } = require('@login512/express');

const app = express();
app.use(express.json());

const LOGIN512_SECRET_KEY = process.env.LOGIN512_SECRET_KEY;

// Route ล็อกอิน รับ token จาก Frontend SDK
app.post('/api/auth/login', async (req, res) => {
  const { token, nonce } = req.body;
  
  const verified = await verifyLogin512Token({
    secretKey: LOGIN512_SECRET_KEY,
    token: token,
    expectedNonce: nonce
  });

  if (!verified.valid) {
    return res.status(401).json({ error: verified.error });
  }

  // สร้าง JWT หรือ Session ของระบบเราเอง
  req.session.userId = verified.claims.sub;
  res.json({ success: true, user: verified.claims });
});

// Middleware ป้องกัน Route พิเศษ
app.get('/api/secret-data', login512Middleware({ secretKey: LOGIN512_SECRET_KEY }), (req, res) => {
  res.json({ message: "เข้าถึงข้อมูลความปลอดภัยสูงสำเร็จ", user: req.l512User });
});

app.listen(3000, () => console.log('Server running on port 3000'));
```

##### NestJS (`@login512/nestjs`)
```typescript
// auth.controller.ts
import { Controller, Post, Body, UseGuards, Get } from '@nestjs/common';
import { Login512Service, Login512AuthGuard, CurrentUser } from '@login512/nestjs';

@Controller('auth')
export class AuthController {
  constructor(private readonly l512Service: Login512Service) {}

  @Post('verify')
  async verifyBiometric(@Body('token') token: string) {
    const verified = await this.l512Service.verifyToken(token);
    return { success: verified.valid, userId: verified.claims?.sub };
  }

  @Get('protected-profile')
  @UseGuards(Login512AuthGuard)
  getProfile(@CurrentUser() user: any) {
    return { message: "เข้าสู่ระบบแล้ว", user };
  }
}
```

---

#### 3.3 กลุ่มภาษา Python

##### FastAPI (`login512-fastapi`)
```python
from fastapi import FastAPI, Depends, HTTPException, status
from login512_server import Login512Server

app = FastAPI()
l512 = Login512Server(secret_key="l512_sk_live_xxx")

@app.post("/api/auth/biometric-login")
async def biometric_login(payload: dict):
    token = payload.get("token")
    verified = l512.verify_token(token)
    
    if not verified["valid"]:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail=verified.get("error", "Invalid biometric token")
        )
        
    user_id = verified["claims"]["sub"]
    return {"status": "success", "user_id": user_id, "claims": verified["claims"]}
```

##### Django (`django-login512`)
```python
# views.py
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import login
from django_login512.backend import authenticate_login512
import json

@csrf_exempt
def biometric_login_view(request):
    if request.method == "POST":
        data = json.loads(request.body)
        token = data.get("token")
        
        user = authenticate_login512(request, token=token)
        if user:
            login(request, user)
            return JsonResponse({"status": "success"})
        return JsonResponse({"error": "Biometric verification failed"}, status=401)
```

---

#### 3.4 กลุ่มภาษา Go (Golang)

##### Gin Web Framework (`github.com/login512/login512-go`)
```go
package main

import (
	"net/http"
	"github.com/gin-gonic/gin"
	"github.com/login512/login512-go"
)

func main() {
	r := gin.Default()
	client := login512.NewClient("l512_sk_live_xxx")

	r.POST("/api/login", func(c *gin.Context) {
		var req struct {
			Token string `json:"token" binding:"required"`
		}
		if err := c.ShouldBindJSON(&req); err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": "กรุณาระบุโทเคน"})
			return
		}

		// ตรวจสอบความถูกต้องของโทเคน
		result, err := client.VerifyToken(c.Request.Context(), req.Token)
		if err != nil || !result.Valid {
			c.JSON(http.StatusUnauthorized, gin.H{"error": "โทเคนไม่ถูกต้องหรือหมดอายุ"})
			return
		}

		c.JSON(http.StatusOK, gin.H{
			"status":  "success",
			"user_id": result.Claims.Subject,
			"method":  result.Claims.ModeUsed,
		})
	})

	r.Run(":8080")
}
```

---

#### 3.5 กลุ่มภาษา Java & Kotlin (Spring Boot 3)
```java
package com.example.demo.controller;

import com.login512.sdk.Login512Client;
import com.login512.sdk.model.VerificationResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    private final Login512Client l512Client = new Login512Client("l512_sk_live_xxx");

    @PostMapping("/verify")
    public ResponseEntity<?> verifyToken(@RequestBody Map<String, String> payload) {
        String token = payload.get("token");
        
        VerificationResult result = l512Client.verifyToken(token);
        if (!result.isValid()) {
            return ResponseEntity.status(401).body(Map.of("error", result.getErrorMessage()));
        }

        return ResponseEntity.ok(Map.of(
            "status", "success",
            "userId", result.getClaims().getSubject(),
            "assurance", result.getClaims().getAssuranceLevel()
        ));
    }
}
```

---

#### 3.6 กลุ่มภาษา C# / .NET (.NET 8 & 9 Minimal API)
```csharp
using Login512.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

// ลงทะเบียน Login512 Service
builder.Services.AddLogin512(options =>
{
    options.SecretKey = builder.Configuration["Login512:SecretKey"];
});

var app = builder.Build();

app.MapPost("/api/auth/login", async (LoginRequest req, ILogin512Client client) =>
{
    var result = await client.VerifyTokenAsync(req.Token);
    if (!result.IsValid)
    {
        return Results.Unauthorized();
    }

    return Results.Ok(new { 
        Status = "Authenticated", 
        UserId = result.Claims.Subject,
        AuthTime = result.Claims.AuthTime 
    });
});

app.Run();

record LoginRequest(string Token);
```

---

#### 3.7 กลุ่มภาษา Ruby (Ruby on Rails)
```ruby
# app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
  skip_before_action :verify_authenticity_token, only: [:biometric_login]

  def biometric_login
    token = params[:token]
    client = Login512::Client.new(secret_key: ENV['LOGIN512_SECRET_KEY'])
    
    result = client.verify_token(token)
    if result.valid?
      session[:user_id] = result.claims['sub']
      render json: { status: 'success', user_id: result.claims['sub'] }, status: :ok
    else
      render json: { error: result.error }, status: :unauthorized
    end
  end
end
```

---

#### 3.8 กลุ่มภาษา Rust (Axum Web Framework)
```rust
use axum::{routing::post, Json, Router, http::StatusCode};
use login512_rs::{Login512Client, VerifyRequest};
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct AuthPayload {
    token: String,
}

#[derive(Serialize)]
struct AuthResponse {
    status: String,
    user_id: Option<String>,
}

async fn login_handler(Json(payload): Json<AuthPayload>) -> Result<Json<AuthResponse>, StatusCode> {
    let client = Login512Client::new("l512_sk_live_xxx");
    let result = client.verify_token(&payload.token).await;

    match result {
        Ok(verification) if verification.is_valid => Ok(Json(AuthResponse {
            status: "success".to_string(),
            user_id: Some(verification.claims.sub),
        })),
        _ => Err(StatusCode::UNAUTHORIZED),
    }
}

#[tokio::main]
async fn main() {
    let app = Router::new().route("/api/auth/verify", post(login_handler));
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}
```

---

#### 3.9 กลุ่มภาษา Elixir (Phoenix Framework)
```elixir
defmodule MyAppWeb.AuthController do
  use MyAppWeb, :controller
  alias Login512.Client

  def biometric_verify(conn, %{"token" => token}) do
    client = Client.new(System.get_env("LOGIN512_SECRET_KEY"))

    case Client.verify_token(client, token) do
      {:ok, %{valid: true, claims: claims}} ->
        conn
        |> put_session(:current_user_id, claims["sub"])
        |> json(%{status: "authenticated", user_id: claims["sub"]})

      {:error, reason} ->
        conn
        |> put_status(:unauthorized)
        |> json(%{error: reason})
    end
  end
end
```

---

#### 3.10 กลุ่มภาษา C / C++ (อุปกรณ์ IoT, ตู้ POS, เครื่อง Kiosk)
```c
#include <stdio.h>
#include "login512.h"

int main() {
    const char* secret_key = "l512_sk_live_xxx";
    const char* token = "eyJsNTEyX..."; // โทเคนจากการสแกน

    login512_client_t* client = login512_init(secret_key);
    login512_result_t result;

    int status = login512_verify_token(client, token, &result);
    if (status == L512_OK && result.is_valid) {
        printf("ปลดล็อกตู้ POS สำเร็จ! ผู้ใช้งาน: %s\n", result.user_id);
    } else {
        printf("ปฏิเสธการเข้าถึง: %s\n", result.error_message);
    }

    login512_free_result(&result);
    login512_destroy(client);
    return 0;
}
```

---

### 4. ฝั่งแอปพลิเคชันมือถือ (Mobile Native SDKs)

#### 4.1 Flutter (Dart - `login512_flutter`)
```dart
import 'package:flutter/material.dart';
import 'package:login512_flutter/login512_flutter.dart';

class BiometricLoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('เข้าสู่ระบบด้วย Flutter')),
      body: Center(
        child: Login512ScanWidget(
          publishableKey: 'l512_pk_live_xxx',
          mode: ScanMode.auto, // รองรับทั้ง Face Liveness และ Fingerprint
          onSuccess: (token, user) {
            print('ยืนยันตัวตนผ่านมือถือสำเร็จ! โทเคน: $token');
            Navigator.pushReplacementNamed(context, '/home');
          },
          onError: (error) {
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(content: Text('ข้อผิดพลาด: ${error.message}')),
            );
          },
        ),
      ),
    );
  }
}
```

#### 4.2 React Native (`@login512/react-native`)
```tsx
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { Login512Button, useBiometricAuth } from '@login512/react-native';

export default function MobileLoginScreen({ navigation }: any) {
  return (
    <View style={styles.container}>
      <Text style={styles.title}>สแกนชีวมิติบนมือถือ</Text>
      <Login512Button
        publishableKey="l512_pk_live_xxx"
        mode="auto"
        onSuccess={(token) => {
          // ส่ง token ไป verify ที่ API server
          navigation.navigate('Home');
        }}
        onError={(err) => alert(err.message)}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  title: { fontSize: 20, fontWeight: 'bold', marginBottom: 20 }
});
```

#### 4.3 iOS Native Swift (SwiftUI)
```swift
import SwiftUI
import Login512

struct LoginView: View {
    @State private var isAuthenticated = false
    
    var body: some View {
        VStack(spacing: 24) {
            Text("เข้าสู่ระบบด้วย Face ID / สแกนหน้า")
                .font(.headline)
            
            Login512BiometricButton(publishableKey: "l512_pk_live_xxx") { result in
                switch result {
                case .success(let auth):
                    print("ล็อกอินสำเร็จ Token: \(auth.token)")
                    self.isAuthenticated = true
                case .failure(let error):
                    print("ล้มเหลว: \(error.localizedDescription)")
                }
            }
        }
    }
}
```

#### 4.4 Android Native Kotlin (Jetpack Compose)
```kotlin
package com.example.login512app

import androidx.compose.runtime.Composable
import com.login512.android.compose.Login512Button
import com.login512.android.models.AuthResult

@Composable
fun LoginScreen(onLoginSuccess: (String) -> Unit) {
    Login512Button(
        publishableKey = "l512_pk_live_xxx",
        onSuccess = { result: AuthResult ->
            onLoginSuccess(result.token)
        },
        onError = { error ->
            println("เข้าสู่ระบบไม่สำเร็จ: ${error.message}")
        }
    )
}
```

---

### 5. ฝั่ง CMS & ร้านค้าออนไลน์ (CMS Plugins)

#### 5.1 WordPress & WooCommerce
```php
// ติดตั้งปลั๊กอิน login512-auth แล้วเปิดใช้งาน
// 1. เรียกใช้งานผ่าน Shortcode ในหน้า Page หรือ Post ใดก็ได้:
// [login512_button mode="auto" theme="dark"]

// 2. เรียกใช้งานผ่าน PHP Hook ใน functions.php ของธีม:
add_action('woocommerce_login_form_end', function() {
    echo do_shortcode('[login512_button mode="auto"]');
});
```

---

## ขั้นที่ 8: ระบบสากลหลายภาษา (Universal i18n 11 ภาษา) และการระบุวันเวลาตาม Timezone จริงของผู้ใช้ (Timezone Localization)
> **เป้าหมาย:** ทำให้นักพัฒนาและผู้ใช้งานทั่วโลกสามารถเข้าถึงและใช้งาน Login512 ได้อย่างราบรื่นเป็นธรรมชาติ 100% ครอบคลุม **11 ภาษาระดับโลก** พร้อมระบบตรวจจับภาษาและเขตเวลาท้องถิ่นอัตโนมัติ (Timezone Offset เช่น ประเทศไทย `+07:00` / `GMT+7`) พร้อมการแปลคำอธิบายคอมเมนต์ในโค้ดตัวอย่างตามภาษาที่เลือก

### 8.1 รายการ 11 ภาษาระดับโลกที่รองรับ (11 Global Languages)
| รหัสภาษา | ชื่อภาษา | ธง | รูปแบบวันเวลาตัวอย่าง (Localized Format) | เขตเวลาตัวอย่าง |
| :---: | :--- | :---: | :--- | :---: |
| `en` | English (United States) | 🇺🇸 | Nov 12, 2026, 04:30:00 PM GMT+7 | UTC-5 ถึง UTC+10 |
| `th` | ไทย (Thai) | 🇹🇭 | 12 พ.ย. 2026, 16:30:00 GMT+7 | Asia/Bangkok (`+07:00`) |
| `zh` | 简体中文 (Chinese Simplified) | 🇨🇳 | 2026年11月12日 16:30:00 GMT+7 | Asia/Shanghai (`+08:00`) |
| `ja` | 日本語 (Japanese) | 🇯🇵 | 2026年11月12日 16:30:00 GMT+7 | Asia/Tokyo (`+09:00`) |
| `es` | Español (Spanish) | 🇪🇸 | 12 nov 2026, 16:30:00 GMT+7 | Europe/Madrid (`+01:00`) |
| `de` | Deutsch (German) | 🇩🇪 | 12.11.2026, 16:30:00 GMT+7 | Europe/Berlin (`+01:00`) |
| `fr` | Français (French) | 🇫🇷 | 12 nov. 2026, 16:30:00 GMT+7 | Europe/Paris (`+01:00`) |
| `ko` | 한국어 (Korean) | 🇰🇷 | 2026. 11. 12. 16:30:00 GMT+7 | Asia/Seoul (`+09:00`) |
| `pt` | Português (Portuguese - Brazil) | 🇧🇷 | 12 de nov. de 2026, 16:30:00 GMT+7 | America/Sao_Paulo (`-03:00`) |
| `vi` | Tiếng Việt (Vietnamese) | 🇻🇳 | 12 thg 11, 2026, 16:30:00 GMT+7 | Asia/Ho_Chi_Minh (`+07:00`) |
| `id` | Bahasa Indonesia (Indonesian) | 🇮🇩 | 12 Nov 2026, 16.30.00 GMT+7 | Asia/Jakarta (`+07:00`) |

### 8.2 กลไกการตรวจจับภาษาและการระบุ Timezone อัตโนมัติ (Zero-Config Auto Detection)
1. **ลำดับการตรวจจับภาษา (Resolution Hierarchy):**
   * **Explicit SDK Option:** กำหนดผ่าน `Login512.init({ locale: 'th' })`
   * **URL Parameter:** ส่งผ่าน `?lang=th` หรือ `?locale=ja` (มีประโยชน์มากสำหรับการเปิด iframe หรือแชร์ลิงก์)
   * **Local Storage:** ค่าที่ผู้ใช้เคยเลือกไว้จากเมนูเปลี่ยนภาษา (`localStorage.getItem('l512_locale')`)
   * **Browser / OS Language:** ตรวจจาก `navigator.languages[0]` หรือ `navigator.language`
   * **Deterministic Fallback:** หากภาษาของผู้ใช้ไม่อยู่ใน 11 ภาษาหลัก จะสลับกลับสู่ `en` อย่างนุ่มนวลโดยไม่เกิด Error
2. **การจัดการ Timezone และวันเวลาที่เข้าสู่ระบบ:**
   * **Cryptography Standard (NIST ML-DSA-65 & RFC 7519):** ข้อมูลเวลา `iat` (Issued At), `exp` (Expires At), `auth_time` ในโทเคนควอนตัมจะถูกบันทึกเป็น UTC เสมอ เพื่อให้การยืนยันทางคณิตศาสตร์สากลไม่คลาดเคลื่อน
   * **User Presentation Layer:** ในหน้า UI ทั้งหมด (Biometric Frame, Landing Page, Developer Console, Audit Logs) จะใช้ฟังก์ชัน `Login512I18n.formatDateTime()` แสดงผลตามเขตเวลาเครื่องของผู้ใช้จริง เช่น ถ้าล็อกอินจากประเทศไทย นาฬิกาและเวลาบันทึกจะแสดงเป็น `Asia/Bangkok (GMT+7)` ทันที
   * **Live Real-time Local Clock:** มีแถบนาฬิกาดิจิทัลเรียลไทม์แสดง `🌐 [Timezone] ([Offset]) — [HH:mm:ss]` บนหัวเว็บและในกรอบสแกนกล้อง

### 8.3 ตัวอย่างการกำหนดภาษาใน SDK และคอมเมนต์หลายภาษา

#### ตัวอย่าง 1: กำหนดภาษาอัตโนมัติใน JavaScript SDK
```javascript
// ภาษาไทย:
// 1. กำหนดค่าเริ่มต้น Login512 ด้วยโหมดตรวจจับภาษาอัตโนมัติ
const auth = Login512.init({
  publishableKey: "l512_pk_live_your_key_here",
  locale: "auto" // หรือระบุ 'th', 'en', 'zh', 'ja', 'es', 'de', 'fr', 'ko', 'pt', 'vi', 'id'
});

// 2. ติดตั้งปุ่มสแกนใบหน้า (ป้ายปุ่มจะเปลี่ยนภาษาตามที่ตรวจพบโดยอัตโนมัติ)
auth.mountButton("#loginContainer", {
  mode: "auto",
  onSuccess: (token, user) => {
    // 3. ส่งโทเคนควอนตัมไปยังเซิร์ฟเวอร์หลังบ้านเพื่อเปิด Session
    verifyOnBackend(token);
  }
});
```

#### ตัวอย่าง 2: กำหนดภาษาใน React Component (`@login512/react`)
```tsx
import { Login512Provider, Login512Button } from '@login512/react';

export default function App() {
  return (
    <Login512Provider 
      publishableKey="l512_pk_live_xxx" 
      locale="auto" // เปลี่ยนภาษาอัตโนมัติตามเบราว์เซอร์ของผู้ใช้
    >
      <main>
        {/* ข้อความและคำแนะนำในกล้องจะปรับเป็นภาษาของผู้ใช้โดยอัตโนมัติ */}
        <Login512Button 
          mode="auto" 
          onSuccess={(token) => console.log('Login success token:', token)}
        />
      </main>
    </Login512Provider>
  );
}
```

---

## ขั้นที่ 9: เทมเพรต UI/UX สำเร็จรูป 20 แบบสำหรับทุกประเภทธุรกิจ (20 Pre-built Industry Auth Templates)
> **รับรองมาตรฐานโดย `/oil-ui-pro`:** พัฒนาด้วย Pure CSS น้ำหนักเบาพิเศษ (Zero-Framework Bloat, ขนาดรวม <15KB) โหลดไวปานสายฟ้าแลบ รองรับทุกขนาดหน้าจอโดยสมบูรณ์ตั้งแต่สมาร์ตโฟนจอพับ **Samsung Galaxy Z Fold (340px)**, **iPhone (390px)**, **Microsoft Surface Duo (540px/720px)** จนถึง **Tablet** และ **Desktop PC** ไม่ตกขอบ ไม่ซ้อนทับ พร้อมระบบปรับแต่งโลโก้ ชื่อระบบ และลิงก์ **Powered by login512** อัตโนมัติสำหรับแพ็กเกจฟรี

### 9.1 ความสามารถหลักของเทมเพรตสำเร็จรูป (Key Capabilities)
1. **เปลี่ยนโลโก้ระบบได้ทันที (Custom Logo URL):**
   * กำหนดผ่านตัวเลือก `logoUrl: 'https://your-domain.com/logo.png'` ใน JavaScript หรือแอททริบิวต์ `logo-url="..."` ใน HTML Web Component
   * ระบบปรับขนาดสัดส่วนภาพอัตโนมัติ (Responsive Contain) ไม่บวม ไม่ยืด ไม่แตก
2. **เปลี่ยนชื่อระบบที่ต้องการเข้าสู่ระบบ (Custom System / App Name):**
   * กำหนดผ่าน `appName: 'ชื่อระบบของคุณ'` เช่น `"Siam Premier Bank"` หรือ `"Bangkok Hospital"`
   * หัวข้อจะเปลี่ยนเป็น `เข้าสู่ระบบ [ชื่อระบบ]` ในแท็บล็อกอิน และเปลี่ยนเป็น `ลงทะเบียน [ชื่อระบบ]` ในแท็บสมัครสมาชิกโดยอัตโนมัติ
3. **ระบบสิทธิการใช้งานฟรี (Free Tier & "Powered by login512"):**
   * สำหรับผู้ใช้ **Free Tier** (ค่าเริ่มต้น) บัตรจะแสดงลิงก์ `Powered by login512` พร้อมลิงก์กลับมายัง `https://login512.com` อย่างประณีตสวยงามที่ส่วนท้ายของการ์ด
   * สำหรับผู้ใช้ **Pro** และ **Enterprise Tier** สามารถซ่อนหรือปรับเปลี่ยนตราความปลอดภัยได้อิสระ (`plan: 'pro'`, `showPoweredBy: false`)
4. **การแสดงผลสมบูรณ์แบบบนทุกหน้าจอ (Cross-Device Guarantee):**
   * 📱 **Galaxy Z Fold (340px จอนอก):** ใช้ fluid clamp typography (`clamp(17px, 4.5vw, 20px)`) ไม่มีข้อความล้นหรือตกบรรทัดเพี้ยน
   * 📱 **iPhone / Android (390px - 430px):** ปุ่มสัมผัสผ่านมาตรฐาน Accessibility ความสูงขั้นต่ำ 44px - 46px กดง่าย ไม่พลาด
   * 📱 **Microsoft Surface Duo (540px / 720px):** จัดกึ่งกลางสมดุล สลับการแสดงผลแบบจอแยก (Split-screen) ได้ลื่นไหล
   * 🖥️ **Tablet & Desktop (768px - 4K):** การ์ดขนาดกว้างสูงสุด 420px พร้อมเงามิติชั้นสูง (Layered Elevation Shadow)

---

### 9.2 แคตตาล็อก 20 เทมเพรตสำเร็จรูปแยกตามกลุ่มอุตสาหกรรม (20 Industry Templates Catalog)

สามารถเปิดดูหน้าทดสอบสดและสลับอุปกรณ์ได้ที่ **[https://login512.com/templates.html](https://login512.com/templates.html)**

| # | รหัสธีม (`theme`) | กลุ่มธุรกิจ (Industry) | จุดเด่นและพาเลทสี (Color & Aesthetic) | ตราความปลอดภัย (Trust Footer) | ภาพตัวอย่างการ์ดจริง |
| :-: | :--- | :--- | :--- | :--- | :---: |
| 01 | `fintech` | การเงิน, ธนาคาร, Payment Gateway | ดำ Obsidian หรูหรา ตัดเส้นทองคำและเขียวมรกต สไตล์สถาบันการเงิน | `🔒 PCI-DSS Tier 1` · `⚛️ ML-DSA-65` | [ดูภาพตัวอย่าง](/assets/templates/fintech.png) |
| 02 | `ecommerce` | ร้านค้าออนไลน์, มาร์เก็ตเพลส | แดงคอรัลสดใสและส้มพระอาทิตย์ตก กระตุ้นการตัดสินใจซื้อ | `⚡ 1-Click Pay` · `🛡️ Buyer Protection` | [ดูภาพตัวอย่าง](/assets/templates/ecommerce.png) |
| 03 | `crm` | CRM, ERP, ซอฟต์แวร์ B2B SaaS | น้ำเงิน Royal Indigo ภูมิฐาน ทันสมัย สไตล์ Enterprise Tech | `🏢 SOC2 Type II` · `👥 Enterprise SSO` | [ดูภาพตัวอย่าง](/assets/templates/crm.png) |
| 04 | `hospitality` | โรงแรม, รีสอร์ทหรู, Fine Dining | ทองแชมเปญ (Champagne Gold) และบรอนซ์ สไตล์บริการ 5 ดาว | `🛎️ Concierge Key` · `💎 VIP Verified` | [ดูภาพตัวอย่าง](/assets/templates/hospitality.png) |
| 05 | `logistics` | ขนส่ง, ศูนย์กระจายสินค้า, คาร์โก้ | ส้มสะท้อนแสงนิรภัย (Safety Amber) ความคมชัดสูงพิเศษ | `🛰️ Live Telematics` · `📦 Tamper-Proof` | [ดูภาพตัวอย่าง](/assets/templates/logistics.png) |
| 06 | `healthcare` | โรงพยาบาล, คลินิก, Telemedicine | เขียวมิ้นต์คลินิก (Clinical Teal) และฟ้าน้ำทะเล มาตรฐานเวชระเบียน | `⚕️ HIPAA Compliant` · `🔒 Zero-Knowledge PHI` | [ดูภาพตัวอย่าง](/assets/templates/healthcare.png) |
| 07 | `devops` | คอนโซลคลาวด์, เซิร์ฟเวอร์, K8s | จอเทอร์มินัล Matrix เขียว-ไซเบอร์ แบบอักษร JetBrains Monospace | `⌨️ SSH/TLS 1.3` · `🔒 Zero-Trust Bastion` | [ดูภาพตัวอย่าง](/assets/templates/devops.png) |
| 08 | `govtech` | พอร์ทัลราชการ, บัตรประชาชนดิจิทัล | น้ำเงิน Sovereign Deep Blue และทองคำราชการ น่าเชื่อถือสูงสุด | `📜 National ID` · `🏛️ Tier-3 Gov Security` | [ดูภาพตัวอย่าง](/assets/templates/govtech.png) |
| 09 | `edtech` | มหาวิทยาลัย, โรงเรียน, คอร์สออนไลน์ | ม่วงคราม Scholar Indigo และเขียวสดใส สื่อถึงการศึกษาทันสมัย | `📚 Verified Student ID` · `🌍 Global LMS` | [ดูภาพตัวอย่าง](/assets/templates/edtech.png) |
| 10 | `gaming` | อีสปอร์ต, เซิร์ฟเวอร์เกม, ทัวร์นาเมนต์ | Cyberpunk ม่วงนีออนและชมพู Magenta ขอบสะท้อนแสงล้ำยุค | `🛡️ Anti-Cheat Shield` · `⚡ 0.1ms Low Ping` | [ดูภาพตัวอย่าง](/assets/templates/gaming.png) |
| 11 | `realestate` | อสังหาริมทรัพย์, นิติบุคคลคอนโด | เทาหินสถาปัตยกรรม (Architectural Stone) เรียบหรู ภูมิฐาน | `🏢 Title Deed Escrow` · `🔑 Smart Keyless` | [ดูภาพตัวอย่าง](/assets/templates/realestate.png) |
| 12 | `automotive` | รถยนต์ไฟฟ้า EV, เทเลเมติกส์ | Carbon Graphite และฟ้าประกายไฟ Pulse Blue อัจฉริยะ | `🔋 CAN-Bus Encrypted` · `🏎️ OTA Shield` | [ดูภาพตัวอย่าง](/assets/templates/automotive.png) |
| 13 | `crypto` | Web3 Wallet, DeFi, DEX, DAO | ม่วงอวกาศ Galactic Purple โฮโลกราฟิก สำหรับยุคไร้ศูนย์กลาง | `⛓️ Multi-Chain Proof` · `🔒 Self-Sovereign` | [ดูภาพตัวอย่าง](/assets/templates/crypto.png) |
| 14 | `food` | ร้านอาหาร, ครัว Cloud Kitchen, POS | ส้มอิฐและแดงสดใส อบอุ่น สไตล์บิสโทรและจุดสั่งอาหารเดลิเวอรี่ | `🛵 Instant Dispatch` · `🥘 Kitchen Link` | [ดูภาพตัวอย่าง](/assets/templates/food.png) |
| 15 | `streaming` | สตรีมมิ่งภาพยนตร์, ซีรีส์, สตูดิโอ | ดำสนิทโรงหนัง (Pitch Black) ตัดแดงทับทิม Cinema Ruby | `🍿 4K HDR Atmos` · `🎧 DRM Shield` | [ดูภาพตัวอย่าง](/assets/templates/streaming.png) |
| 16 | `legal` | สำนักงานกฎหมาย, นิติกรรม, Notary | แดงเบอร์กันดีลุ่มลึก (Executive Burgundy) คลาสสิก เข้มงวด | `📜 Notarized Audit` · `🔏 Crypto Stamp` | [ดูภาพตัวอย่าง](/assets/templates/legal.png) |
| 17 | `travel` | สายการบิน, จองตั๋วเที่ยวบิน, ท่องเที่ยว | ฟ้าเส้นขอบฟ้า Horizon Sky และส้มพระอาทิตย์ขึ้น สดใส สบายตา | `🎫 IATA Compliant` · `💺 Instant Gate Pass` | [ดูภาพตัวอย่าง](/assets/templates/travel.png) |
| 18 | `hr` | ฝ่ายบุคคล, เงินเดือน, ทาเลนต์พอร์ทัล | ม่วงอ่อน Orchid เป็นมิตร อบอุ่น เน้นประสบการณ์พนักงาน | `💼 Confidential Payroll` · `📊 GDPR Shield` | [ดูภาพตัวอย่าง](/assets/templates/hr.png) |
| 19 | `iot` | เซ็นเซอร์ SCADA, โรงงานอัจฉริยะ | โทนเครื่องจักรอุตสาหกรรม ไฮเทค แสดงค่าสถานะเทเลเมตรี | `📶 MQTT / TLS 1.3` · `🏭 Edge Gateway` | [ดูภาพตัวอย่าง](/assets/templates/iot.png) |
| 20 | `ngo` | มูลนิธิ, สาธารณกุศล, สิ่งแวดล้อม | เขียวธรรมชาติ Earth Emerald และทองคำอบอุ่น โปร่งใส จริงใจ | `🤝 100% Transparent` · `🌍 UN SDG Aligned` | [ดูภาพตัวอย่าง](/assets/templates/ngo.png) |

---

### 9.3 ตัวอย่างโค้ดพร้อมใช้งาน (Ready-to-Use Code Recipes)

#### วิธีที่ 1: HTML Custom Element (ง่ายที่สุดเพียง 1 แท็ก)
```html
<!-- 1. โหลด Stylesheet และ JavaScript SDK (Pure CSS < 15KB) -->
<link rel="stylesheet" href="https://login512.com/sdk/login512-sdk.css">
<script src="https://login512.com/sdk/login512-sdk.js"></script>

<!-- 2. วางแท็ก <login512-card> ระบุธีม โลโก้ และชื่อระบบของคุณ -->
<login512-card
  publishable-key="l512_pk_live_your_key_here"
  theme="fintech"
  app-name="Siam Premier Bank"
  logo-url="https://your-domain.com/assets/bank-logo.png"
  plan="free"
  show-powered-by="true">
</login512-card>

<script>
  // ดักจับ Event เมื่อผู้ใช้สแกนผ่านสำเร็จ
  document.querySelector('login512-card').addEventListener('l512:success', (e) => {
    const { token, user } = e.detail;
    console.log("ล็อกอินสำเร็จ โทเคนควอนตัม:", token);
    // ส่ง token ไปเปิดเซสชันที่ Backend
  });
</script>
```

#### วิธีที่ 2: Vanilla JavaScript (`Login512.mountCard`)
```html
<div id="authContainer"></div>

<script src="https://login512.com/sdk/login512-sdk.js"></script>
<script>
  Login512.mountCard('#authContainer', {
    publishableKey: 'l512_pk_live_your_key_here',
    theme: 'ecommerce', // เลือกธีมจาก 20 แบบ เช่น fintech, crm, hospitality, ฯลฯ
    appName: 'Siam Mega Mall',
    logoUrl: 'https://your-domain.com/shop-logo.png',
    plan: 'free', // 'free' แสดง Powered by login512 / 'pro' ซ่อนได้
    showPoweredBy: true,
    onSuccess: (token, user, info) => {
      console.log('สแกนสำเร็จ:', token, user);
      window.location.href = '/checkout';
    },
    onError: (err) => {
      console.error('เกิดข้อผิดพลาด:', err);
    }
  });
</script>
```

#### วิธีที่ 3: React / Next.js Component
```tsx
import React, { useEffect, useRef } from 'react';

interface AuthCardProps {
  theme?: 'fintech' | 'ecommerce' | 'crm' | 'hospitality' | 'healthcare' | 'devops' | string;
  appName?: string;
  logoUrl?: string;
  plan?: 'free' | 'pro' | 'enterprise';
  onLoginSuccess?: (token: string, user: any) => void;
}

export const Login512AuthCard: React.FC<AuthCardProps> = ({
  theme = 'fintech',
  appName = 'My Enterprise',
  logoUrl,
  plan = 'free',
  onLoginSuccess
}) => {
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (!containerRef.current || !(window as any).Login512) return;

    const handle = (window as any).Login512.mountCard(containerRef.current, {
      publishableKey: process.env.NEXT_PUBLIC_LOGIN512_PK,
      theme,
      appName,
      logoUrl,
      plan,
      showPoweredBy: plan === 'free',
      onSuccess: (token: string, user: any) => {
        if (onLoginSuccess) onLoginSuccess(token, user);
      }
    });

    return () => {
      if (handle && handle.unmount) handle.unmount();
    };
  }, [theme, appName, logoUrl, plan]);

  return <div ref={containerRef} className="w-full max-w-[420px] mx-auto" />;
};
```

---

### 9.4 ระบบป้องกันสิทธิการใช้งานแพ็กเกจฟรี (Free Tier Policy Enforcement & Anti-Tamper Guard)
> **กฎเหล็กทางธุรกิจ (Business & Security Policy):** บัญชีแพ็กเกจฟรี (Free Tier / Sandbox) ถูกออกแบบมาเพื่อให้ผู้พัฒนาเริ่มต้นใช้งานได้ทันทีอย่างรวดเร็ว โดย **จำกัดให้ใช้งานเฉพาะเทมเพรตสำเร็จรูปมาตรฐานทั้ง 20 แบบ** พร้อมลิงก์ **Powered by login512** เท่านั้น **ไม่อนุญาตให้สร้าง UI/UX แบบเนทีฟเอง หรือเชื่อมต่อแบบ Headless โดยไม่แสดงเทมเพรต**

#### กลไกการป้องกัน 3 ระดับ (3-Layer Enforcement Guard):
1. **Frontend Active Anti-Tamper & Anti-Hiding Guard (ระดับเบราว์เซอร์):**
   * ระบบติดตั้ง `MutationObserver` และ `Periodic Integrity Scanner` ฝังอยู่ใน SDK
   * หากมีการพยายามซ่อนลิงก์ `Powered by login512` ด้วย CSS (เช่น `display: none !important`, `visibility: hidden`, `opacity: 0`, `font-size: 0`, `height: 0`) หรือพยายามลบ Element ออกจาก DOM
   * การ์ดจะตัดการทำงานและแสดงหน้าจอ **Free Tier Policy Violation** (ภาพล็อคหน้าจอ 🔒) ทันที พร้อมปุ่มนำทางไปอัปเกรดแพ็กเกจ [ดูภาพหน้าจอล็อคจริง](/assets/templates/policy_lock_screen.png)
2. **SDK Presentation Enforcement (ระดับ JavaScript Method):**
   * หากโค้ดพยายามเรียก `login({ presentation: 'headless' })` หรือ `enroll({ presentation: 'headless' })` หรือกำหนด `customUi: true` บนบัญชี Free Tier
   * SDK จะปฏิเสธคำขอและคืนค่า `Error: [Login512 Policy Violation] Custom Native UI/UX and Headless authentication are restricted to Pro and Enterprise tiers. Free tier accounts may only use official pre-built templates (<login512-card> or Login512.mountCard()). Upgrade your plan at https://login512.com/pricing`
3. **Backend API Gateway Protection (ระดับเซิร์ฟเวอร์):**
   * ที่ Endpoint `/v1/challenge` และระบบสแกนชีวมิติ เซิร์ฟเวอร์จะตรวจสอบสถานะ `tenant.plan`
   * หากบัญชีเป็น `SANDBOX` (Free Tier) แต่ส่งคำขอแบบ `custom_native`, `headless` หรือ `raw_biometric` เข้ามา
   * เซิร์ฟเวอร์จะตอบกลับด้วย `HTTP 402/403` รหัสข้อผิดพลาด `ErrorCode.PLAN_LIMIT_REACHED` ปฏิเสธการสร้างคำขอโดยสิ้นเชิง

#### ตารางเปรียบเทียบสิทธิการใช้งาน UI/UX (UI/UX Entitlements Table)
| ความสามารถของระบบ (Capability) | 🟢 Free Tier (Sandbox) | 🔵 Pro Tier | 🟣 Enterprise Tier |
| :--- | :---: | :---: | :---: |
| การ์ดเทมเพรตสำเร็จรูป 20 แบบ | ✅ ใช้งานได้ทุกแบบ | ✅ ใช้งานได้ทุกแบบ | ✅ ใช้งานได้ทุกแบบ |
| เปลี่ยนโลโก้ และชื่อระบบของคุณ | ✅ ปรับได้อิสระ | ✅ ปรับได้อิสระ | ✅ ปรับได้อิสระ |
| ลิงก์ Powered by login512 | 🔒 บังคับแสดงผล | 🔓 ซ่อนได้อิสระ | 🔓 ซ่อนได้อิสระ (White-label) |
| สร้าง UI/UX แบบเนทีฟด้วยตนเอง (Custom Native UI) | ❌ ไม่อนุญาต | ✅ ใช้งานได้อิสระ | ✅ ใช้งานได้อิสระ |
| สถาปัตยกรรม Headless API & Raw Biometric | ❌ ไม่อนุญาต | ✅ รองรับผ่าน SDK | ✅ Full REST/gRPC Direct Access |

### 9.5 ตารางข้อกำหนดแพ็กเกจและสิทธิ์การใช้งาน 11 ภาษา (Multi-Language Package Entitlement & Policy Specification Matrix)

ระบบ Login512 ได้รับการออกแบบให้รองรับผู้พัฒนาและองค์กรทั่วโลกด้วยข้อกำหนดแพ็กเกจที่โปร่งใสและครอบคลุม 11 ภาษาสากล (`en`, `th`, `zh`, `ja`, `es`, `de`, `fr`, `ko`, `pt`, `vi`, `id`) พร้อมระบบป้องกันสิทธิ์ (Policy Guard) ที่ทำงานสอดคล้องกันทั้งบน Frontend SDK, Gateway API และระบบฐานข้อมูล

#### 1. ตารางเปรียบเทียบสิทธิ์และขีดจำกัดของ 4 แพ็กเกจหลัก (Universal 4-Tier Comparison)

| รายละเอียดข้อกำหนด (Specification) | 🟢 Sandbox (Free Tier) | 🟡 Starter Plan | 🔵 Pro Plan (ยอดนิยม) | 🟣 Scale / Enterprise |
| :--- | :---: | :---: | :---: | :---: |
| **ค่าบริการรายเดือน (Monthly Price)** | **$0 / เดือน (ฟรีตลอดชีพ)** | **$19 / เดือน** | **$79 / เดือน** | **$249+ / เดือน** |
| **โควตาสแกนชีวมิติ (Monthly Scans)** | 1,000 สแกน / เดือน | 25,000 สแกน / เดือน | 150,000 สแกน / เดือน | 1,000,000+ สแกน / เดือน |
| **ค่าบริการส่วนเกิน (Overage Scan)** | หยุดให้บริการชั่วคราว | $0.0010 ต่อสแกน | $0.0008 ต่อสแกน | $0.0005 ต่อสแกน |
| **ผู้ใช้งานที่รองรับ (Active Users)** | สูงสุด 500 บัญชี | สูงสุด 10,000 บัญชี | สูงสุด 100,000 บัญชี | ไม่จำกัด (Unlimited) |
| **ปริมาณคำขอพร้อมกัน (Rate Limit RPS)**| 2 RPS | 10 RPS | 30 RPS | 100+ RPS (Dedicated) |
| **การ์ดเทมเพรตสำเร็จรูป 20 แบบ** | ✅ ใช้งานได้ทุกแบบ | ✅ ใช้งานได้ทุกแบบ | ✅ ใช้งานได้ทุกแบบ | ✅ ใช้งานได้ทุกแบบ |
| **ปรับแต่งโลโก้ & ชื่อระบบ (App Name)** | ✅ อิสระ 100% | ✅ อิสระ 100% | ✅ อิสระ 100% | ✅ อิสระ 100% |
| **ตราสัญลักษณ์ "Powered by login512"** | 🔒 **บังคับแสดงผล** (Anti-Tamper) | 🔓 **ปลดล็อกออกได้** | 🔓 **ปลดล็อกออกได้** (White-label) | 🔓 **ปลดล็อกออกได้** (White-label) |
| **สิทธิ์สร้าง Native UI/UX ด้วยตนเอง** | ❌ **ไม่อนุญาต** (Lock Screen) | ❌ ไม่อนุญาต | ✅ **อนุญาต 100%** (Custom UI) | ✅ **อนุญาต 100%** (Custom UI) |
| **สถาปัตยกรรม Headless / Background API** | ❌ ไม่อนุญาต | ❌ ไม่อนุญาต | ✅ ใช้งานผ่าน Client SDK | ✅ Full REST/gRPC Direct Biometric |
| **การรับประกันระบบ (SLA)** | แบบพยายามดีที่สุด (Best Effort) | 99.5% Uptime | 99.9% Uptime | **99.99% Enterprise SLA** |
| **การสนับสนุนด้านเทคนิค (Support)** | คู่มือชุมชนและฟอรัม | อีเมลช่วยเหลือภายใน 48 ชม. | แชตด่วนและช่วยเหลือ 24/7 | ผู้จัดการบัญชีเฉพาะราย (Dedicated) |

#### 2. กลไกการตรวจจับความสมบูรณ์และระบบล็อกหน้าจอหลายภาษา (Localized Anti-Tamper Policy Guard)

เมื่อระบบตรวจพบการพยายามลบ ปิดบัง หรือซ่อนลิงก์ `Powered by login512` หรือการพยายามเรียกใช้ Custom Native UI บนแพ็กเกจฟรี (Free Tier) ระบบจะทำการล็อกหน้าจอการ์ดด้วยโมดูล `.l512-policy-lock` โดยแสดงข้อความแจ้งเตือนตาม **ภาษาของผู้ใช้งานอัตโนมัติทั้ง 11 ภาษา**:

```
[ตัวอย่างหน้าจอล็อคภาษาไทย (Thai)]
🔒 แจ้งเตือนนโยบายแพ็กเกจฟรี (Free Tier)
แพ็กเกจฟรีอนุญาตให้ใช้งานเฉพาะการ์ดเทมเพรตสำเร็จรูปมาตรฐานพร้อมลิงก์ Powered by login512 เท่านั้น
ไม่อนุญาตให้ซ่อน ปิดบัง หรือสร้าง UI/UX แบบเนทีฟเอง
หากต้องการพัฒนา UI/UX แบบเนทีฟของตนเองหรือลบตราแบรนด์ กรุณาอัปเกรดเป็นแพ็กเกจ Pro / Enterprise
[ ปุ่ม: ดูรายละเอียดและอัปเกรดแพ็กเกจ ] -> https://login512.com/#pricing
```

#### 3. พจนานุกรมข้อกำหนดแพ็กเกจ 11 ภาษา (11-Language Package Specification Reference)

| ภาษา (Language) | ชื่อแพ็กเกจฟรี (Free Sandbox) | สิทธิ์เทมเพรต 20 แบบ (Templates Rule) | กฎการแสดงตราสินค้า (Attribution Rule) | ข้อจำกัด Native UI (Native Restriction) |
| :--- | :--- | :--- | :--- | :--- |
| 🇺🇸 **English (`en`)** | Sandbox (Free Tier) | Official 20 Pre-built Templates only | Powered by login512 link required | No custom native UI / headless mode |
| 🇹🇭 **ไทย (`th`)** | Sandbox (ฟรี) | ใช้ได้เฉพาะการ์ดเทมเพรตสำเร็จรูป 20 แบบ | แสดงลิงก์ Powered by login512 (บังคับ) | ไม่อนุญาตให้สร้าง Custom Native UI |
| 🇨🇳 **简体中文 (`zh`)** | Sandbox (免费版) | 仅限使用官方 20 款预制 UI 模版 | 强制保留 Powered by login512 标识 | 禁止原生自定义 UI / Headless 模式 |
| 🇯🇵 **日本語 (`ja`)** | Sandbox（無料プラン） | 公式 20 種類のプリセット UI のみ利用可能 | Powered by login512 リンク表示必須 | ネイティブ独自 UI / Headless モード不可 |
| 🇰🇷 **한국어 (`ko`)** | Sandbox (무료 플랜) | 공식 20개 사전 제작 템플릿만 사용 가능 | Powered by login512 링크 표시 필수 | 커스텀 네이티브 UI / 헤드리스 모드 불가 |
| 🇪🇸 **Español (`es`)** | Sandbox (Gratuito) | Solo 20 plantillas preconstruidas oficiales | Enlace Powered by login512 obligatorio | Sin UI nativa personalizada ni modo headless |
| 🇩🇪 **Deutsch (`de`)** | Sandbox (Kostenlos) | Nur offizielle 20 vorgefertigte Templates | Powered by login512 Link erforderlich | Keine eigene native UI / kein Headless-Modus |
| 🇫🇷 **Français (`fr`)** | Sandbox (Gratuit) | 20 modèles prédéfinis officiels uniquement | Lien Powered by login512 obligatoire | UI native personnalisée / mode headless interdit |
| 🇧🇷 **Português (`pt`)** | Sandbox (Gratuito) | Apenas os 20 modelos pré-construídos oficiais | Link Powered by login512 obrigatório | UI nativa customizada / modo headless não permitidos |
| 🇻🇳 **Tiếng Việt (`vi`)** | Sandbox (Miễn phí) | Chỉ áp dụng cho 20 mẫu giao diện chính thức | Bắt buộc hiển thị liên kết Powered by login512 | Không hỗ trợ tự dựng Native UI / chế độ Headless |
| 🇮🇩 **Bahasa Indonesia (`id`)** | Sandbox (Gratis) | Hanya untuk 20 Templat Resmi yang disediakan | Wajib menampilkan tautan Powered by login512 | Tidak diizinkan UI native kustom / mode headless |

---

## แผนภาพขั้นตอนการดำเนินงาน (Execution Roadmap Flow)

```mermaid
flowchart TD
    Start["เริ่มดำเนินงานพัฒนาการเชื่อมต่อสากล"] --> Phase1["ขั้นที่ 1: OIDC & OAuth 2.0 Provider (แกนหลักปลดล็อกทุกระบบทันที)"]
    Phase1 --> Phase2["ขั้นที่ 2: Frontend Frameworks (React, Next.js, Vue, Nuxt, Angular, Svelte)"]
    Phase1 --> Phase3["ขั้นที่ 3: Backend Server SDKs (PHP/Laravel, Node/NestJS, Python/Django, Go, Java/Spring, .NET, Ruby, Rust, C++)"]
    Phase2 --> Phase4["ขั้นที่ 4: Mobile Native SDKs (Flutter, React Native, iOS Swift, Android Kotlin)"]
    Phase2 --> Phase5["ขั้นที่ 5: CMS & E-Commerce (WordPress/WooCommerce, Shopify, Magento)"]
    Phase3 --> Phase6["ขั้นที่ 6: Enterprise & Edge (SAML 2.0, Cloudflare Edge, Kong Gateway)"]
    Phase1 --> Phase7["ขั้นที่ 7: AI & Autonomous Agents (MCP Server, llms.txt, AI Rules, Setup CLI)"]
    
    Phase4 --> Complete["บรรลุเป้าหมาย: Universal Authentication Platform 100%"]
    Phase5 --> Complete
    Phase6 --> Complete
    Phase7 --> Complete
```

---

## กฎเหล็กในการพัฒนา (Core Architectural Rules)
1. **Zero-Image Privacy:** ทุก SDK และ Plugin ต้องไม่มีการบันทึกรูปภาพใบหน้าลง Disk, Storage หรือ LocalStorage เด็ดขาด ข้อมูลภาพต้องอยู่บน RAM ชั่วคราวเฉพาะตอนสแกนเท่านั้น
2. **Post-Quantum Cryptography (PQC):** ทุก Server SDK และ Edge Module ต้องรองรับการตรวจสอบลายเซ็นดิจิทัลควอนตัม ML-DSA
3. **No Breaking Changes:** การเพิ่มฟังก์ชันใหม่ต้องไม่กระทบต่อ API เดิม (`/v1/token/verify`, `/v1/face/*`, `/v1/passkeys/*`)
4. **Test-Driven Verification:** ทุกโมดูลที่สร้างใหม่ต้องมีชุดทดสอบ Unit Test อย่างน้อย 1 ชุด และรันผ่าน 100%
5. **Production Sync:** เมื่อทดสอบผ่านแล้ว ต้องซิงก์ไฟล์และอัปเดตระบบบนเซิร์ฟเวอร์จริง (`103.91.189.93`) พร้อมรีสตาร์ตเซอร์วิสเสมอ

---
*เอกสารนี้ถูกจัดทำขึ้นเพื่อใช้เป็นเข็มทิศนำทางการพัฒนาและอัปเดตสถานะของโครงการ Login512 อย่างต่อเนื่อง*

