Multi-Factor Authentication (TOTP)
ระบบ MFA ของ BossHub ใช้มาตรฐาน TOTP (Time-based One-Time Password) ซึ่งทำงานร่วมกับแอปพลิเคชันอย่าง Google Authenticator หรือ Microsoft Authenticator
เหมาะสำหรับระบบที่ต้องการความปลอดภัยสูงกว่ารหัสผ่านปกติ เช่น เครื่อง POS หรือระบบควบคุม IOT
🛡️
Security
รหัสเปลี่ยนทุก 30 วินาที ป้องกันการดักจับข้อมูล
📱
Offline
ใช้งานได้แม้โทรศัพท์ไม่มีอินเทอร์เน็ต
⚙️
Integration
เชื่อมต่อง่ายผ่าน API มาตรฐาน JSON
1 การเปิดใช้งาน (Setup)
เรียก API นี้เพื่อสร้าง Secret Key และรับ QR Code สำหรับให้ผู้ใช้สแกนครั้งแรก
POST
/api/2fa/setup
Request Body (JSON):
{
"user_id": "boss@bosshub.io",
"app_id": "my_app",
"reset": false // ส่ง true หากต้องการล้างค่าเก่า
}
2 ตรวจสอบรหัส (Verify)
ใช้ตรวจสอบรหัส 6 หลักที่ผู้ใช้กรอกมาจาก Authenticator App
POST
/api/2fa/verify
Parameters:
- user_id: ID ผู้ใช้
- token: รหัส 6 หลักที่ผู้ใช้กรอก
- app_id: ID แอปพลิเคชัน
Tips: ระบบรองรับ Valid Window +- 30 วินาที เพื่อป้องกันปัญหาเวลาของอุปกรณ์ไม่ตรงกัน
JS JavaScript / IoT Integration
สำหรับการพัฒนาฝั่ง Client (เช่น หน้าจอเครื่อง POS หรือ Dashboard) คุณสามารถใช้ `fetch` API ในการเชื่อมต่อได้โดยตรง
การดึงรหัส QR Code มาแสดง (MFA Setup)
async function setupMFA(userId, appId) {
const res = await fetch('https://authentication.bosshub.io/api/2fa/setup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: userId, app_id: appId })
});
const result = await res.json();
if (result.status === 'success') {
// นำ base64 ไปใส่ในแท็ก img
document.getElementById('qr_img').src = "data:image/png;base64," + result.data.qr_code_base64;
document.getElementById('secret_text').innerText = result.data.secret_key;
}
}
การส่งรหัสตรวจสอบ (MFA Verify)
async function verifyOTP() {
const otp = document.getElementById('otp_input').value;
try {
const res = await fetch('https://authentication.bosshub.io/api/2fa/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
user_id: currentUserId,
token: otp,
app_id: 'my_app'
})
});
const data = await res.json();
if (data.status === 'success') {
localStorage.setItem('boss_token', data.token);
window.location.href = '/dashboard';
} else {
alert('รหัสผิดพลาด: ' + data.message);
}
} catch (err) {
console.error('Verify Error:', err);
}
}
Pro Tips for Khun Boss Team:
- ใช้
input type="tel" และ pattern="[0-9]*" เพื่อให้มือถือเปิดปุ่มตัวเลขขึ้นมาทันที
- เขียน Script ให้ Auto-submit ทันทีที่กรอกครบ 6 หลัก เพื่อประสบการณ์ใช้งานที่เร็วที่สุด
- หากเป็นอุปกรณ์ IoT (เช่น ESP32) ให้ส่งรหัสผ่านทาง MQTT มาที่ Backend แล้วให้ Backend เรียก Verify API อีกที